async def fetch_status(self, order: Order) -> typing.FetchedOrderStatus: def get_order_status_by_data(order_data: dict): if order_data.get('QuantityRemaining', -1.0) == 0.0: return const.FULFILLED if order_data.get('Closed', None): return const.CANCELLED return const.CREATED success, response = await self.get( '/market/getopenorders', market=self.pair_local2bittrex(order.pair), tbs=['apikey', 'nonce', 'market'] ) if success and response.get('success', False): for order_data in response.get('result', []): if order_data['OrderUuid'] == order.id_on_exchange: return typing.FetchedOrderStatus( success=True, status=get_order_status_by_data(order_data), response=str(response), ) # orders list fetched with success, # but our `order` is not opened already. # So, it was fulfilled. self.logger.debug( f'Order not found in exchange\'s opened orders list.' f' So, it\'s successful by default. Response {response}.' ) return typing.FetchedOrderStatus( success=True, status=const.FULFILLED, response=str(response), ) self.logger.warning( f'Unknown order status.' f' Response data from exchange: {response}' ) return typing.FetchedOrderStatus( success=False, status=order.status, response=str(response), )
async def fetch_status(self, order: Order) -> typing.FetchedOrderStatus: success, response = await self.get(f'/order/{order.id_on_exchange}') status = '' if success: status = self.exchange_order_status_map[response['status']] return typing.FetchedOrderStatus( success=success, status=status, response=str(response), )
async def fetch_status(self, order: Order) -> typing.FetchedOrderStatus: success, response = await self.post( '/order/status', order_id=order.id_on_exchange, ) status = '' if success: status = self._get_order_status_from_response(response) success = bool(status) return typing.FetchedOrderStatus(success=success, status=status, response=str(response))
async def fetch_status(self, order: Order) -> typing.FetchedOrderStatus: """ Fetch status and set it to received order. :param order: :return: response data from exchange """ if not order.id_on_exchange: raise ValueError(f'Order doesn\'t have exchange ID. {order}') result = await self.session.fetch_status(order) self.logger.debug('Fetch order status from exchange.' f' order.id_on_exchange={order.id_on_exchange}.' f' Response={result}.') if result.success: if not result.status: self.logger.error( 'Exchange session returned empty order status.') return typing.FetchedOrderStatus(response=result.response) else: self.logger.warning( f'Unknown order status. Response data: {result.response}\n') return result
async def fetch_status(self, order: Order) -> typing.FetchedOrderStatus: return typing.FetchedOrderStatus( success=self.is_success, status=self.status, response='ok', )