-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6. Position Summary.py
More file actions
40 lines (25 loc) · 1.04 KB
/
6. Position Summary.py
File metadata and controls
40 lines (25 loc) · 1.04 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
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from threading import Thread
import time
##-------------------------------------------------------------------------
class Strategy(EClient, EWrapper):
def __init__(self):
EWrapper.__init__(self)
EClient.__init__(self, self)
#Handle position response from TWS vis Eclient
def position(self, account, contract, position, avgCost):
print(f'\nAccount: {account} \nContract: {contract.localSymbol}')
print(f'Position: {position} \nAvg Cost: {avgCost}')
def positionEnd(self):
print('\nPositions Retrieved.')
##-------------------------------------------------------------------------
application = Strategy()
application.connect(host='localhost', port=7497, clientId=1)
time.sleep(1)
Thread(target=application.run, daemon=True).start()
print('Connected?', application.isConnected())
# Request positions from the TWS
application.reqPositions()
time.sleep(5)
application.disconnect()