### Our Strategy Follows Here ### #Rather than Focussing on Arbitrage we try to make the most of a market that hopefully fluctuates around a reasonnably fixed average. Given no real product we thought this would be accurate. #We create an array that is a weighted version of our current portfolio of shares. We then view the market relative to the average of our current position in order to make decisions #We think this should work and it does for good periods of time. It is susceptible to large and consistent changes to the market which unfortunately happened this morning! bought_prices = [average_b(200) + 0.5] weighted_prices_a = [average_a(3)] weighted_prices_b = [average_b(3)] start_pnl = e.get_pnl() new_pnl = e.get_pnl() timer = 0 #new_start_b = [average_b(20)]*10 #weighted_prices_b = new_start_b while timer < 2000: stats_a = get_range_a(10000) stats_b = get_range_b(10000) max_range_a = stats_a[0] - stats_a[1] low_range_b = stats_b[1] - stats_b[2] book_a = e.get_last_price_book(philips_a) book_b = e.get_last_price_book(philips_b)
import time import logging from optibook.synchronous_client import Exchange from strategy import should_kill_attempt, arbitrage, stoikov_mm from utils import balance_positions from moving_average import MovingAverage logging.getLogger('client').setLevel('ERROR') exchange = Exchange() exchange.connect() START_PNL = exchange.get_pnl() ma_A = MovingAverage(exchange, "PHILIPS_A") tick = 1 while not should_kill_attempt(exchange, START_PNL): time.sleep(0.11) print(f"tick {tick}") tick += 1 ma_A.update() # Don't want to balance our trades from our MM positions exchange.delete_orders("PHILIPS_A")
print( f"[TRADED {t.instrument_id}] price({t.price}), volume({t.volume}), side({t.side})" ) # Returns all current positions positions = e.get_positions() for p in positions: print(p, positions[p]) # Returns all current positions with cash investedx positions = e.get_positions_and_cash() for p in positions: print(p, positions[p]) # Returns Current PnL based on last Traded Price pnl = e.get_pnl() print(pnl) book_A = e.get_last_price_book("PHILIPS_A") book_B = e.get_last_price_book("PHILIPS_B") print('bids_PHILIPS_A:') print("bid\tprice\task") for i in reversed(book_A.asks): print('\t' + str(round(i.price, 1)) + '\t' + str(i.volume)) for i in book_A.bids: print(str(i.volume) + '\t' + str(round(i.price, 1)) + '\t') # Returns all public tradeticks since the last time this function was called tradeticks = e.poll_new_trade_ticks(instrument_id) for t in tradeticks: print(