Ejemplo n.º 1
0
    def test_time_in_force_parser_given_invalid_value_raises_value_error(self):
        # Arrange, Act, Assert
        with pytest.raises(ValueError):
            TimeInForceParser.to_str_py(0)

        with pytest.raises(ValueError):
            TimeInForceParser.from_str_py("")
Ejemplo n.º 2
0
    async def _submit_trailing_stop_market_order(
            self, order: TrailingStopMarketOrder) -> None:
        if order.trigger_type in (TriggerType.DEFAULT, TriggerType.LAST):
            working_type = "CONTRACT_PRICE"
        elif order.trigger_type == TriggerType.MARK:
            working_type = "MARK_PRICE"
        else:
            self._log.error(
                f"Cannot submit order: invalid `order.trigger_type`, was "
                f"{TriggerTypeParser.to_str_py(order.trigger_price)}. {order}",
            )
            return

        if order.offset_type not in (TrailingOffsetType.DEFAULT,
                                     TrailingOffsetType.BASIS_POINTS):
            self._log.error(
                f"Cannot submit order: invalid `order.offset_type`, was "
                f"{TrailingOffsetTypeParser.to_str_py(order.offset_type)} (use `BASIS_POINTS`). "
                f"{order}", )
            return

        await self._http_account.new_order(
            symbol=format_symbol(order.instrument_id.symbol.value),
            side=OrderSideParser.to_str_py(order.side),
            type=binance_order_type(order),
            time_in_force=TimeInForceParser.to_str_py(order.time_in_force),
            quantity=str(order.quantity),
            activation_price=str(order.trigger_price),
            callback_rate=str(order.trailing_offset / 100),
            working_type=working_type,
            reduce_only=order.
            is_reduce_only,  # Cannot be sent with Hedge-Mode or closePosition
            new_client_order_id=order.client_order_id.value,
            recv_window=5000,
        )
Ejemplo n.º 3
0
    def test_time_in_force_from_str(self, string, expected):
        # Arrange
        # Act
        result = TimeInForceParser.from_str_py(string)

        # Assert
        assert expected == result
Ejemplo n.º 4
0
    def test_time_in_force_to_str(self, enum, expected):
        # Arrange
        # Act
        result = TimeInForceParser.to_str_py(enum)

        # Assert
        assert expected == result
Ejemplo n.º 5
0
 async def _submit_stop_limit_order(self, order: StopLimitOrder) -> None:
     await self._http_account.new_order(
         symbol=format_symbol(order.instrument_id.symbol.value),
         side=OrderSideParser.to_str_py(order.side),
         type=binance_order_type(order),
         time_in_force=TimeInForceParser.to_str_py(order.time_in_force),
         quantity=str(order.quantity),
         price=str(order.price),
         stop_price=str(order.trigger_price),
         iceberg_qty=str(order.display_qty) if order.display_qty is not None else None,
         new_client_order_id=order.client_order_id.value,
         recv_window=5000,
     )
Ejemplo n.º 6
0
    async def _submit_limit_order(self, order: LimitOrder) -> None:
        time_in_force = TimeInForceParser.to_str_py(order.time_in_force)
        if order.is_post_only:
            time_in_force = "GTX"

        await self._http_account.new_order(
            symbol=format_symbol(order.instrument_id.symbol.value),
            side=OrderSideParser.to_str_py(order.side),
            type=binance_order_type(order),
            time_in_force=time_in_force,
            quantity=str(order.quantity),
            price=str(order.price),
            reduce_only=order.
            is_reduce_only,  # Cannot be sent with Hedge-Mode or closePosition
            new_client_order_id=order.client_order_id.value,
            recv_window=5000,
        )