-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount_portfolio_update.py
More file actions
57 lines (36 loc) · 1.79 KB
/
Copy pathaccount_portfolio_update.py
File metadata and controls
57 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from threading import Timer
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
# def error(self, reqId, errorCode, errorString):
# print("Error: ", reqId, " ", errorCode, " ", errorString)
def nextValidId(self, orderId):
self.start()
def updatePortfolio(self, contract: Contract, position: float, marketPrice: float, marketValue: float,
averageCost: float, unrealizedPNL: float, realizedPNL: float, accountName: str):
print("UpdatePortfolio.", "Symbol:", contract.symbol, "SecType:", contract.secType, "Exchange:", contract.exchange,
"Position:", position, "MarketPrice:", marketPrice, "MarketValue:", marketValue, "AverageCost:", averageCost,
"UnrealizedPNL:", unrealizedPNL, "RealizedPNL:", realizedPNL, "AccountName:", accountName)
def updateAccountValue(self, key: str, val: str, currency: str, accountName: str):
print("UpdateAccountValue. Key:", key, "Value:", val, "Currency:", currency, "AccountName:", accountName)
def updateAccountTime(self, timeStamp: str):
print("UpdateAccountTime. Time:", timeStamp)
def accountDownloadEnd(self, accountName: str):
print("AccountDownloadEnd. Account:", accountName)
def start(self):
# Account number can be omitted when using reqAccountUpdates with single account structure
self.reqAccountUpdates(True, "")
def stop(self):
self.reqAccountUpdates(False, "")
self.done = True
self.disconnect()
def main():
app = TestApp()
app.connect("127.0.0.1", 7496, 997)
Timer(5, app.stop).start()
app.run()
if __name__ == "__main__":
main()