-
Notifications
You must be signed in to change notification settings - Fork 1
/
test1.py
47 lines (39 loc) · 1.39 KB
/
test1.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
from ib_insync import *
ib = IB()
ib.connect('127.0.0.1', 7496, clientId=15)
contracts = [Forex(symbol) for symbol in 'EURUSD USDJPY'.split()]
ib.qualifyContracts(*contracts)
#get yesterday's closing price
highs = []
for contract in contracts:
bars = ib.reqHistoricalData(
contract,
endDateTime='',
durationStr='10 D',
barSizeSetting='1 week',
whatToShow='MIDPOINT',
useRTH=True,
formatDate=1)
highs.append(bars[-1].high)
#print(bars)
##Not sure how to store yesterday's close price from barDatalist to a regular variable
# #get the tickers and subscribe to market
tickers = ib.reqTickers(*contracts)
for contract in contracts:
ib.reqMktData(contract, '', False, False)
while ib.waitOnUpdate():
for ticker,high in zip(tickers,highs):
if ticker.marketPrice()> high:
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.marketPrice()) + " which is lower than prior candle high " + str(high))
# if ticker[0].open > ticker[0].lastclose
#order = MarketOrder('BUY',100)
#elif ticker[1].open > ticker[1].lastclose etc..