def getDifferenceInCurrentAskBidPrices(book_1, book_2): # Buy from 1 and sell to 2 bestAsk = getBestAsk(book_1) # How much we would buy for bestBid = getBestBid(book_2) # How much we would sell for #print(bestAsk) #print(bestBid) if (bestBid is not None and bestAsk is not None): return bestBid - bestAsk else: return -1
time.sleep(0.5) AB = getDifferenceInCurrentAskBidPrices('PHILIPS_A', 'PHILIPS_B') BA = getDifferenceInCurrentAskBidPrices('PHILIPS_B', 'PHILIPS_A') print("A => B:" + str(round(AB, 2))) print("B => A:" + str(round(BA, 2))) #printOrderBook('PHILIPS_A') #printOrderBook('PHILIPS_B') #result = e.insert_order('PHILIPS_A', price=[*bids.keys()][0], volume=1, side='ask', order_type='limit') #print(f"Order Id: {result}") #result = e.insert_order('PHILIPS_A', price=70, volume=1, side='bid', order_type='limit') #print(f"Order Id: {result}") #outstanding = e.get_outstanding_orders('PHILIPS_A') #for o in outstanding.values(): # print(f"Outstanding order: order_id({o.order_id}), instrument_id({o.instrument_id}), price({o.price}), volume({o.volume}), side({o.side})") #time.sleep(60) e.insert_order("PHILIPS_A", price=getBestAsk(e.get_last_price_book('PHILIPS_A')), volume=1, side='bid', order_type='ioc') print("trade made") time.sleep(20) #print(e.get_trade_history('PHILIPS_A')) #print(e.get_trade_history('PHILIPS_B')) #print(e.get_trade_tick_history('PHILIPS_A'))
from optibook.synchronous_client import Exchange from MainFunctions import getBestAsk import time e = Exchange() a = e.connect() instr_ids = ['PHILIPS_A', 'PHILIPS_B'] index = int(input()) # 0 or 1 instr = instr_ids[index] book = e.get_last_price_book(instr) positions = e.get_positions().values() totalPosition = sum(positions) if (book.asks[0].volume >= abs(totalPosition)): print("Estimated cash by end") cash = e.get_cash() bestAsk = getBestAsk(book) loss = bestAsk * abs(totalPosition) print(cash - loss) print("Proceed?") if (input() == "y"): e.insert_order(instr, price=bestAsk, volume=abs(totalPosition), side='bid', order_type='ioc') time.sleep(5)
from optibook.synchronous_client import Exchange from MainFunctions import getBestBid, getBestAsk e = Exchange() a = e.connect() ABids = [] AAsks = [] BBids = [] BAsks = [] for i in range(300): ABook = e.get_last_price_book('PHILIPS_A') BBook = e.get_last_price_book('PHILIPS_B') ABids.append(getBestBid(ABook)) AAsks.append(getBestAsk(ABook)) BBids.append(getBestBid(BBook)) BAsks.append(getBestAsk(BBook)) time.sleep(1) f = open("ABids.txt", "a") for line in ABids: f.write(str(line) + "\n") f.close() f = open("BBids.txt", "a") for line in BBids: f.write(str(line) + "\n") f.close() f = open("AAsks.txt", "a")
# Work out the time lag between Philips A and Philips B def get_lag(): return 5 #execute lowLiq = "PHILIPS_B" highLiq = "PHILIPS_A" count_trades = 0 while (count_trades < 10): hLBook = e.get_last_price_book(highLiq) bestAsk = getBestAsk(hLBook) if (bestAsk is not None): e.insert_order(highLiq, price=bestAsk + 0.1, volume=5, side='ask', order_type='limit') time.sleep(get_lag() - 2) currentTradeId = e.insert_order(lowLiq, price=bestAsk, volume=5, side='bid', order_type='limit') print("Sell to A") count_trades = count_trades + 1 #trades = e.poll_new_trades("PHILIPS_B")