Beispiel #1
0
 async def query(self):
     async with websockets.connect(
             StockUrl(account=Player.get().account, stock=Player.get().stock, is_execution=True).str()) as websocket:
         while True:
             # print(json.loads(await websocket.recv()))
             execution = json.loads(await websocket.recv())
             await self.callback(execution)
Beispiel #2
0
 async def query(self):
     async with websockets.connect(StockUrl(account=Player.get().account, stock=Player.get().stock,
                                            is_ticker_tape=True).str()) as websocket:
         while True:
             # print(json.loads(await websocket.recv()))
             quote = json.loads(await websocket.recv())['quote']
             await self.callback(quote)
Beispiel #3
0
    async def recover_order(self):
        started = datetime.datetime.now()
        while True:
            if datetime.datetime.now() - started >= datetime.timedelta(seconds=30):
                print('Did not recover any order')
                break
            await asyncio.sleep(1)

            if self.remote_order:
                # We have already recovered it through other means
                break

            existing_ids = self.order_set.get_all_order_ids()
            server_orders = await Primitive.all_orders_stock()
            matching_orders = [order for order in server_orders if
                               order['id'] not in existing_ids and order['originalQty'] == self.amount and order[
                                   'symbol'] == Player.get().stock and order[
                                   'price'] == self.price and order['direction'] == self.direction and order[
                                   'orderType'] == self.orderType]
            if len(matching_orders) > 0:
                # If there are multiple matching orders then pick any one
                self.remote_order = matching_orders[0]
                print('Recovered order {}'.format(self.remote_order))
                break
Beispiel #4
0
 def bootstrap():
     Player.get('sell_side')
     asyncio.get_event_loop().run_until_complete(MarketMaker().run())