def test_order_type_parser_given_invalid_value_raises_value_error(self): # Arrange, Act, Assert with pytest.raises(ValueError): OrderTypeParser.to_str_py(0) with pytest.raises(ValueError): OrderTypeParser.from_str_py("")
def test_order_type_from_str(self, string, expected): # Arrange # Act result = OrderTypeParser.from_str_py(string) # Assert assert expected == result
def test_order_type_to_str(self, enum, expected): # Arrange # Act result = OrderTypeParser.to_str_py(enum) # Assert assert expected == result
def parse_order_type(order_type: str) -> OrderType: if order_type in ("STOP", "STOP_LOSS"): return OrderType.STOP_MARKET elif order_type == "STOP_LOSS_LIMIT": return OrderType.STOP_LIMIT elif order_type == "TAKE_PROFIT": return OrderType.LIMIT elif order_type == "TAKE_PROFIT_LIMIT": return OrderType.STOP_LIMIT elif order_type == "TAKE_PROFIT_MARKET": return OrderType.MARKET_IF_TOUCHED elif order_type == "LIMIT_MAKER": return OrderType.LIMIT else: return OrderTypeParser.from_str_py(order_type)