42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import sys
|
|
|
|
from ledger import Ledger, Trade
|
|
from logger import BufferedLogger
|
|
|
|
BLOTTER = [
|
|
Trade("T1", "AAPL", "BUY", 100, 190.00),
|
|
Trade("T2", "AAPL", "BUY", 50, 196.00),
|
|
Trade("T3", "MSFT", "BUY", 200, 410.00),
|
|
Trade("T4", "AAPL", "SELL", 120, 199.50),
|
|
Trade("T5", "MSFT", "SELL", 0, 412.00),
|
|
Trade("T6", "AAPL", "SELL", 80, 201.00),
|
|
Trade("T7", "IBM", "SELL", 30, 225.00),
|
|
]
|
|
|
|
|
|
def main():
|
|
live_log = BufferedLogger("live", level="INFO", stream=sys.stdout)
|
|
live = Ledger(live_log)
|
|
for trade in BLOTTER:
|
|
try:
|
|
live.apply(trade)
|
|
except ValueError:
|
|
pass
|
|
live_log.flush()
|
|
|
|
eod_log = BufferedLogger("eod", level="INFO", stream=sys.stdout)
|
|
eod = Ledger.rebuild(live.history, eod_log)
|
|
eod_log.flush()
|
|
|
|
print()
|
|
for symbol in sorted(live.positions):
|
|
p = live.positions[symbol]
|
|
print(f"{symbol:<5} qty={p.qty:>5} avg={p.avg_price:>9.4f} realized={p.realized:>10.2f}")
|
|
|
|
breaks = live.reconcile(eod)
|
|
print("reconcile:", "OK" if not breaks else breaks)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|