-
Notifications
You must be signed in to change notification settings - Fork 1
/
new.py
41 lines (36 loc) · 1.12 KB
/
new.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
from ib_insync import *
ib = IB()
ib.connect('127.0.0.1', 7496, clientId=15)
contract = []
contract = Forex('EURUSD')
ib.qualifyContracts(contract)
#get yesterday's closing price
high = []
low = []
bars = ib.reqHistoricalData(
contract,
endDateTime='',
durationStr='300 S',
barSizeSetting='5 mins',
whatToShow='MIDPOINT',
useRTH=True,
formatDate=1)
high.append(bars[-1].high)
low.append(bars[-1].low)
#print(bars)
#print(high)
# #get the tickers and subscribe to market
ticker = ib.reqTickers(contract)# I get ticker as NoneType if I use ib.ticker
ib.reqMktData(contract, '', False, False)
while ib.waitOnUpdate():
if ticker[-1].marketPrice()> high[0]:
print('Price is higher than prior candle high')
order = Order()
order.action = 'BUY'
order.orderType = "LMT"
order.totalQuantity = 10
order.lmtPrice = .95
ib.placeOrder(contract, order)
break
else:
print("Price is " + str(ticker[-1].marketPrice()) + " which is lower than prior candle high " + str(high))