Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Migration Guide

## 2.6.0 -> 2.7.0

- The `rfq_start_price` argument of `RestApiClient.place_order`, `BlockingTradingClient.create_and_place_order`
and `create_order_object` has been replaced with `rfq: CreateOrderRfqModel` (`x10.models.order`), which carries
`start_price` and the new `max_reprice_steps`. `NewOrderModel.rfq_start_price` has been replaced with `NewOrderModel.rfq`.

## 2.0.0 -> 2.3.0

- `Config` dataclass has been renamed to `ClientConfig` and moved to `x10.core.client_config`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"side": "BUY",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand Down Expand Up @@ -84,6 +83,7 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"debuggingAmounts": {"collateralAmount": "-43445117", "feeAmount": "21723", "syntheticAmount": "1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
10 changes: 5 additions & 5 deletions tests/signing/order_object/test_limit_order_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async def test_create_sell_order_with_default_expiration(
"side": "SELL",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand All @@ -75,6 +74,7 @@ async def test_create_sell_order_with_default_expiration(
"debuggingAmounts": {"collateralAmount": "43445116", "feeAmount": "21723", "syntheticAmount": "-1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -110,7 +110,6 @@ async def test_create_sell_order(mocker: MockerFixture, create_trading_account,
"side": "SELL",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand All @@ -134,6 +133,7 @@ async def test_create_sell_order(mocker: MockerFixture, create_trading_account,
"debuggingAmounts": {"collateralAmount": "43445116", "feeAmount": "21723", "syntheticAmount": "-1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -169,7 +169,6 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"side": "BUY",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand All @@ -193,6 +192,7 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"debuggingAmounts": {"collateralAmount": "-43445117", "feeAmount": "21723", "syntheticAmount": "1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -241,7 +241,6 @@ async def test_create_buy_order_with_order_tpsl(mocker: MockerFixture, create_tr
"side": "BUY",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand Down Expand Up @@ -301,6 +300,7 @@ async def test_create_buy_order_with_order_tpsl(mocker: MockerFixture, create_tr
"debuggingAmounts": {"collateralAmount": "-43445117", "feeAmount": "21723", "syntheticAmount": "1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -351,7 +351,6 @@ async def test_create_buy_order_with_position_tpsl(
"side": "BUY",
"qty": "0.00100000",
"price": "43445.11680000",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "GTT",
Expand Down Expand Up @@ -411,6 +410,7 @@ async def test_create_buy_order_with_position_tpsl(
"debuggingAmounts": {"collateralAmount": "-43445117", "feeAmount": "21723", "syntheticAmount": "1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
4 changes: 2 additions & 2 deletions tests/signing/order_object/test_market_order_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async def test_create_sell_order(mocker: MockerFixture, create_trading_account,
"side": "SELL",
"qty": "0.00100000",
"price": "49625.0",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "IOC",
Expand All @@ -78,6 +77,7 @@ async def test_create_sell_order(mocker: MockerFixture, create_trading_account,
"debuggingAmounts": {"collateralAmount": "49625000", "feeAmount": "24813", "syntheticAmount": "-1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -122,7 +122,6 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"side": "BUY",
"qty": "0.00100000",
"price": "50375.0",
"rfqStartPrice": None,
"reduceOnly": False,
"postOnly": False,
"timeInForce": "IOC",
Expand All @@ -146,6 +145,7 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c
"debuggingAmounts": {"collateralAmount": "-50375000", "feeAmount": "25188", "syntheticAmount": "1000"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
21 changes: 20 additions & 1 deletion tests/signing/order_object/test_order_object_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from pytest_mock import MockerFixture

from x10.config import TESTNET_CONFIG
from x10.models.order import OrderSide
from x10.errors import ValidationError
from x10.models.order import CreateOrderRfqModel, OrderSide, OrderType, TimeInForce
from x10.utils.date import utc_now

FROZEN_NONCE = 1473459052
Expand Down Expand Up @@ -71,3 +72,21 @@ async def test_external_order_id(mocker: MockerFixture, create_trading_account,
}
),
)


@pytest.mark.asyncio
async def test_rfq_not_allowed_for_non_rfq_market(create_trading_account, create_btc_usd_market):
from x10.signing.order_object import create_order_object

with pytest.raises(ValidationError, match="only supported for RFQ markets"):
create_order_object(
account=create_trading_account(),
market=create_btc_usd_market(),
order_type=OrderType.MARKET,
time_in_force=TimeInForce.IOC,
amount_of_synthetic=Decimal("0.00100000"),
price=Decimal("43445.11680000"),
side=OrderSide.BUY,
starknet_domain=TESTNET_CONFIG.signing.starknet_domain,
rfq=CreateOrderRfqModel(start_price=Decimal("43000"), max_reprice_steps=3),
)
4 changes: 2 additions & 2 deletions tests/signing/order_object/test_tpsl_order_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async def test_create_buy_partial_tpsl_order(mocker: MockerFixture, create_tradi
"side": "SELL",
"qty": "0.0001",
"price": "0",
"rfqStartPrice": None,
"reduceOnly": True,
"postOnly": False,
"timeInForce": "GTT",
Expand Down Expand Up @@ -110,6 +109,7 @@ async def test_create_buy_partial_tpsl_order(mocker: MockerFixture, create_tradi
"debuggingAmounts": {"collateralAmount": "0", "feeAmount": "0", "syntheticAmount": "-100"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
Expand Down Expand Up @@ -160,7 +160,6 @@ async def test_create_buy_position_tpsl_order(mocker: MockerFixture, create_trad
"side": "SELL",
"qty": "0",
"price": "0",
"rfqStartPrice": None,
"reduceOnly": True,
"postOnly": False,
"timeInForce": "GTT",
Expand Down Expand Up @@ -213,6 +212,7 @@ async def test_create_buy_position_tpsl_order(mocker: MockerFixture, create_trad
"debuggingAmounts": {"collateralAmount": "0", "feeAmount": "0", "syntheticAmount": "0"},
"builderFee": None,
"builderId": None,
"rfq": None,
}
),
)
5 changes: 3 additions & 2 deletions x10/clients/blocking/blocking_trading_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from x10.models.http import WrappedStreamResponseModel
from x10.models.market import MarketModel
from x10.models.order import (
CreateOrderRfqModel,
NewOrderModel,
OpenOrderModel,
OrderSide,
Expand Down Expand Up @@ -207,7 +208,7 @@ async def create_and_place_order(
time_in_force: TimeInForce = TimeInForce.GTT,
reduce_only: bool = False,
order_type: OrderType = OrderType.LIMIT,
rfq_start_price: Optional[Decimal] = None,
rfq: Optional[CreateOrderRfqModel] = None,
) -> TimedOpenOrderModel:
market = (await self.get_markets()).get(market_name)

Expand All @@ -220,7 +221,6 @@ async def create_and_place_order(
order_type=order_type,
amount_of_synthetic=amount_of_synthetic,
price=price,
rfq_start_price=rfq_start_price,
side=side,
post_only=post_only,
reduce_only=reduce_only,
Expand All @@ -231,6 +231,7 @@ async def create_and_place_order(
builder_id=builder_id,
time_in_force=time_in_force,
taker_fee=taker_fee,
rfq=rfq,
)

if order.id in self.__order_waiters:
Expand Down
8 changes: 6 additions & 2 deletions x10/clients/rest/rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from x10.errors import ValidationError
from x10.models.market import MarketModel
from x10.models.order import (
CreateOrderRfqModel,
OrderSide,
OrderTpslType,
OrderType,
PlacedOrderModel,
SelfTradeProtectionLevel,
TimeInForce,
Expand Down Expand Up @@ -51,6 +53,7 @@ async def place_order(
price: Decimal,
side: OrderSide,
taker_fee: Decimal,
order_type: OrderType = OrderType.LIMIT,
post_only: bool = False,
previous_order_id=None,
expire_time: Optional[datetime] = None,
Expand All @@ -63,7 +66,7 @@ async def place_order(
tp_sl_type: Optional[OrderTpslType] = None,
take_profit: Optional[OrderTpslTriggerParam] = None,
stop_loss: Optional[OrderTpslTriggerParam] = None,
rfq_start_price: Optional[Decimal] = None,
rfq: Optional[CreateOrderRfqModel] = None,
) -> WrappedApiResponseModel[PlacedOrderModel]:
# FIXME: Remove all the checks, should proxy the request?
if not self.__stark_account:
Expand All @@ -85,8 +88,8 @@ async def place_order(
market=market,
amount_of_synthetic=amount_of_synthetic,
price=price,
rfq_start_price=rfq_start_price,
side=side,
order_type=order_type,
post_only=post_only,
previous_order_external_id=previous_order_id,
expire_time=expire_time,
Expand All @@ -101,6 +104,7 @@ async def place_order(
tp_sl_type=tp_sl_type,
take_profit=take_profit,
stop_loss=stop_loss,
rfq=rfq,
)

if market.is_rfq:
Expand Down
14 changes: 11 additions & 3 deletions x10/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,26 @@ class CreateOrderTpslTriggerModel(X10BaseModel):
debugging_amounts: Optional[StarkDebuggingOrderAmountsModel] = None


class NewOrderModel(X10BaseModel):
class CreateOrderRfqModel(X10BaseModel):
"""
RFQ quote walk parameters. Supported for RFQ markets only.

Attributes:
rfq_start_price: The start price of the quote walk. Supported for RFQ markets MARKET orders only.
start_price: The start price of the quote walk.
max_reprice_steps: The maximum number of repricing steps of the quote walk.
"""

start_price: Optional[Decimal] = None
max_reprice_steps: Optional[int] = None


class NewOrderModel(X10BaseModel):
id: str
market: str
type: OrderType
side: OrderSide
qty: Decimal
price: Decimal
rfq_start_price: Optional[Decimal] = None
reduce_only: bool = False
post_only: bool = False
time_in_force: TimeInForce
Expand All @@ -181,6 +188,7 @@ class NewOrderModel(X10BaseModel):
debugging_amounts: Optional[StarkDebuggingOrderAmountsModel] = None
builder_fee: Optional[Decimal] = None
builder_id: Optional[int] = None
rfq: Optional[CreateOrderRfqModel] = None


class PlacedOrderModel(X10BaseModel):
Expand Down
Loading
Loading