-
Notifications
You must be signed in to change notification settings - Fork 0
/
place_order_tutorial.py
60 lines (42 loc) · 1.12 KB
/
place_order_tutorial.py
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
58
59
import ibapi
from ibapi.client import *
from ibapi.wrapper import *
import threading
class IBApi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
self.nextValidOrderId = None
def nextValidId(self, orderId):
self.nextValidOrderId = orderId
app = IBApi()
app.connect(#Your IP
)
t1 = threading.Thread(target = app.run)
t1.start()
#Waiting for TWS connection acknoledgement
while (app.nextValidOrderId == None):
print("Waiting for TWS connection acknoledgement ...")
print("Connection established.")
filename = "counter.txt"
with open(filename, 'w') as file:
file.write(str(app.nextValidOrderId))
c1 = Contract()
c1.symbol = "PLUG"
c1.secType = "STK"
c1.currency = "USD"
c1.exchange = "SMART"
c1.primaryExchange = "NASDAQ"
c2 = Contract()
c2.symbol = "RKLB"
c2.secType = "STK"
c2.currency = "USD"
c2.exchange = "SMART"
c2.primaryExchange = "NASDAQ"
myorder = Order()
myorder.orderId = app.nextValidOrderId
myorder.action = "BUY"
myorder.orderType = "LMT"
myorder.totalQuantity = 1
myorder.lmtPrice = 3.00
myorder.eTradeOnly = ""
myorder.firmQuoteOnly = ""