def make_orders(exchange: Exchange, orders: List[Order]): # Orders in form of [Order] order_results = list( map( lambda order: exchange.insert_order(order.instrument_id, price=order.price, volume=order.volume, side=order.side, order_type=order.order_type), orders)) for (order, order_id) in zip(orders, order_results): trade_history = exchange.get_trade_history(order.instrument_id) if len(trade_history) > 0 and trade_history[-1].order_id == order_id: success_msg = "SUCCESS " elif order.order_type == "ioc": success_msg = "FAILED " else: success_msg = "OUTSTANDING" order_log = f"Order: {order_id} {success_msg} | Instrument: {order.instrument_id} | Price: {order.price:.1f} | Volume: {order.volume} | Side: {order.side} | Order Type: {order.order_type}" g_recent_orders.pop(0) g_recent_orders.append(order_log) print(order_log)
#a = e.connect(username='******', password='******') # Returns all currently outstanding orders orders = e.get_outstanding_orders(instrument_id) for o in orders.values(): print('outstanding orders: ' + o) # Returns all trades you have done since the last time this function was called trades = e.poll_new_trades(instrument_id) for t in trades: print( f"[TRADED {t.instrument_id}] price({t.price}), volume({t.volume}), side({t.side})" ) # Returns all trades you have done since since the instantiation of the Exchange trades = e.get_trade_history(instrument_id) for t in trades: 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])
side='ask', order_type='ioc') i = i + 1 printOutstanding() return i count = 0 i = 0 while (count < 10): time.sleep(0.1) count = execute_trade(count) i += 1 if (i == 100): trades = e.get_trade_history('PHILIPS_A') for t in trades: print( f"[TRADED {t.instrument_id}] price({t.price}), volume({t.volume}), side({t.side})" ) trades = e.get_trade_history('PHILIPS_B') for t in trades: print( f"[TRADED {t.instrument_id}] price({t.price}), volume({t.volume}), side({t.side})" ) printOutstanding() i = 0 outstanding = e.get_outstanding_orders("PHILIPS_A") for o in outstanding.values(): print(