Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathibpytutorial.py
More file actions
Latest commit
47 lines (34 loc) · 1.08 KB
/
Copy pathibpytutorial.py
File metadata and controls
47 lines (34 loc) · 1.08 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
fromib.optimportConnection, message
fromib.ext.ContractimportContract
fromib.ext.OrderimportOrder
defmake_contract(symbol, sec_type, exch, prim_exch, curr):
Contract.m_symbol=symbol
Contract.m_secType=sec_type
Contract.m_exchange=exch
Contract.m_primaryExch=prim_exch
Contract.m_currency=curr
returnContract
defmake_order(action,quantity, price=None):
ifpriceisnotNone:
order=Order()
order.m_orderType='LMT'
order.m_totalQuantity=quantity
order.m_action=action
order.m_lmtPrice=price
else:
order=Order()
order.m_orderType='MKT'
order.m_totalQuantity=quantity
order.m_action=action
returnorder
cid=303
while__name__=="__main__":
conn=Connection.create(port=7496, clientId=999)
conn.connect()
oid=cid
cont=make_contract('TSLA', 'STK', 'SMART', 'SMART', 'USD')
offer=make_order('BUY', 1, 200)
conn.placeOrder(oid, cont, offer)
conn.disconnect()
x=raw_input('enter to resend')
cid+=1