async def get_open_orders(self) -> List[OpenOrder]: tracked_orders = list(self._in_flight_orders.values()) api_params = { 'symbol': None, 'orderSide': None, 'orderStatuses': ["NEW", "PARTIALLY_FILLED"], 'size': 500, 'bookmarkOrderId': None } result = await self._api_request("POST", Constants.ENDPOINT["USER_ORDERS"], api_params, is_auth_required=True) ret_val = [] for order in result: exchange_order_id = str(order["id"]) # CoinZoom doesn't support client order ids yet so we must find it from the tracked orders. track_order = [ o for o in tracked_orders if exchange_order_id == o.exchange_order_id ] if not track_order or len(track_order) < 1: # Skip untracked orders continue client_order_id = track_order[0].client_order_id # if Constants.HBOT_BROKER_ID not in order["clientOrderId"]: # continue if order["orderType"] != OrderType.LIMIT.name.upper(): self.logger().info( f"Unsupported order type found: {order['type']}") # Skip and report non-limit orders continue ret_val.append( OpenOrder(client_order_id=client_order_id, trading_pair=convert_from_exchange_trading_pair( order["symbol"]), price=Decimal(str(order["price"])), amount=Decimal(str(order["quantity"])), executed_amount=Decimal(str(order["cumQuantity"])), status=order["orderStatus"], order_type=OrderType.LIMIT, is_buy=True if order["orderSide"].lower() == TradeType.BUY.name.lower() else False, time=str_date_to_ts(order["timestamp"]), exchange_order_id=order["id"])) return ret_val
def _format_trading_rules( self, symbols_info: Dict[str, Any]) -> Dict[str, TradingRule]: """ Converts json API response into a dictionary of trading rules. :param symbols_info: The json API response :return A dictionary of trading rules. Response Example: [ { "symbol" : "BTC/USD", "baseCurrencyCode" : "BTC", "termCurrencyCode" : "USD", "minTradeAmt" : 0.0001, "maxTradeAmt" : 10, "maxPricePrecision" : 2, "maxQuantityPrecision" : 6, "issueOnly" : false } ] """ result = {} for rule in symbols_info: try: trading_pair = convert_from_exchange_trading_pair( rule["symbol"]) min_amount = Decimal(str(rule["minTradeAmt"])) min_price = Decimal(f"1e-{rule['maxPricePrecision']}") result[trading_pair] = TradingRule( trading_pair, min_order_size=min_amount, max_order_size=Decimal(str(rule["maxTradeAmt"])), min_price_increment=min_price, min_base_amount_increment=min_amount, min_notional_size=min(min_price * min_amount, Decimal("0.00000001")), max_price_significant_digits=Decimal( str(rule["maxPricePrecision"])), ) except Exception: self.logger().error( f"Error parsing the trading pair rule {rule}. Skipping.", exc_info=True) return result