def parse_order_type(raw_order): try: side: TradeOrderSide = TradeOrderSide(raw_order[ExchangeConstantsOrderColumns.SIDE.value]) order_type: TradeOrderType = TradeOrderType.UNKNOWN parsed_order_type: TraderOrderType = TraderOrderType.UNKNOWN try: order_type = TradeOrderType(raw_order[ExchangeConstantsOrderColumns.TYPE.value]) except ValueError as e: if raw_order[ExchangeConstantsOrderColumns.TYPE.value] is None: # No order type info: use unknown order type return side, TraderOrderType.UNKNOWN else: # Incompatible order type info: raise error raise e if order_type == TradeOrderType.UNKNOWN: parsed_order_type = TraderOrderType.UNKNOWN elif side == TradeOrderSide.BUY: if order_type == TradeOrderType.LIMIT or order_type == TradeOrderType.LIMIT_MAKER: parsed_order_type = TraderOrderType.BUY_LIMIT elif order_type == TradeOrderType.MARKET: parsed_order_type = TraderOrderType.BUY_MARKET else: parsed_order_type = _get_sell_and_buy_types(order_type) elif side == TradeOrderSide.SELL: if order_type == TradeOrderType.LIMIT or order_type == TradeOrderType.LIMIT_MAKER: parsed_order_type = TraderOrderType.SELL_LIMIT elif order_type == TradeOrderType.MARKET: parsed_order_type = TraderOrderType.SELL_MARKET else: parsed_order_type = _get_sell_and_buy_types(order_type) return side, parsed_order_type except (KeyError, ValueError): return None, None
def parse_order_type(raw_order): try: side: TradeOrderSide = TradeOrderSide( raw_order[ExchangeConstantsOrderColumns.SIDE.value]) order_type: TradeOrderType = TradeOrderType( raw_order[ExchangeConstantsOrderColumns.TYPE.value]) if side == TradeOrderSide.BUY: if order_type == TradeOrderType.LIMIT or order_type == TradeOrderType.LIMIT_MAKER: order_type = TraderOrderType.BUY_LIMIT elif order_type == TradeOrderType.MARKET: order_type = TraderOrderType.BUY_MARKET else: order_type = _get_sell_and_buy_types(order_type) elif side == TradeOrderSide.SELL: if order_type == TradeOrderType.LIMIT or order_type == TradeOrderType.LIMIT_MAKER: order_type = TraderOrderType.SELL_LIMIT elif order_type == TradeOrderType.MARKET: order_type = TraderOrderType.SELL_MARKET else: order_type = _get_sell_and_buy_types(order_type) return side, order_type except KeyError: get_logger( Order.__class__.__name__).error("Failed to parse order type") return None, None
def __update_type_from_raw(self, raw_order): self.side: TradeOrderSide = TradeOrderSide( raw_order[ExchangeConstantsOrderColumns.SIDE.value]) order_type: TradeOrderType = TradeOrderType( raw_order[ExchangeConstantsOrderColumns.TYPE.value]) if self.side == TradeOrderSide.BUY: if order_type == TradeOrderType.LIMIT: self.order_type = TraderOrderType.BUY_LIMIT elif order_type == TradeOrderType.MARKET: self.order_type = TraderOrderType.BUY_MARKET elif self.side == TradeOrderSide.SELL: if order_type == TradeOrderType.LIMIT: self.order_type = TraderOrderType.SELL_LIMIT elif order_type == TradeOrderType.MARKET: self.order_type = TraderOrderType.SELL_MARKET
def open_order_pretty_printer(exchange_name, dict_order, markdown=False) -> str: """ Open Order pretty printer :param exchange_name: the exchange name :param dict_order: the order dict :param markdown: if printer use markdown :return: the order pretty printed """ try: from octobot_trading.enums import ( ExchangeConstantsOrderColumns, TraderOrderType, TradeOrderSide, ) from octobot_trading.api.orders import parse_order_type _, _, code = get_markers(markdown) currency, market = symbol_util.split_symbol( str(dict_order.get(ExchangeConstantsOrderColumns.SYMBOL.value, ""))) order_type = parse_order_type(dict_order) if order_type == TraderOrderType.UNKNOWN: order_type = TradeOrderSide( dict_order.get(ExchangeConstantsOrderColumns.SIDE.value)) quantity = dict_order.get(ExchangeConstantsOrderColumns.AMOUNT.value, 0.0) price = dict_order.get(ExchangeConstantsOrderColumns.PRICE.value, 0.0) return ( f"{code}{order_type.name.replace('_', ' ')}{code}: {code}" f"{get_min_string_from_number(quantity)} {currency}{code} at {code}" f"{get_min_string_from_number(price)} {market}{code} on {exchange_name.capitalize()}" ) except ImportError: LOGGER.error( "open_order_pretty_printer requires OctoBot-Trading package installed" ) return ""