|
7 | 7 | from pytest_mock import MockerFixture |
8 | 8 |
|
9 | 9 | from x10.perpetual.configuration import TESTNET_CONFIG |
10 | | -from x10.perpetual.orders import OrderSide, SelfTradeProtectionLevel |
| 10 | +from x10.perpetual.order_object import OrderTpslTriggerParam |
| 11 | +from x10.perpetual.orders import ( |
| 12 | + OrderPriceType, |
| 13 | + OrderSide, |
| 14 | + OrderTriggerPriceType, |
| 15 | + SelfTradeProtectionLevel, |
| 16 | +) |
11 | 17 | from x10.utils.date import utc_now |
12 | 18 |
|
13 | 19 | FROZEN_NONCE = 1473459052 |
@@ -188,6 +194,76 @@ async def test_create_buy_order(mocker: MockerFixture, create_trading_account, c |
188 | 194 | ) |
189 | 195 |
|
190 | 196 |
|
| 197 | +@freeze_time("2024-01-05 01:08:56.860694") |
| 198 | +@pytest.mark.asyncio |
| 199 | +async def test_create_buy_order_with_tpsl(mocker: MockerFixture, create_trading_account, create_btc_usd_market): |
| 200 | + mocker.patch("x10.utils.generate_nonce", return_value=FROZEN_NONCE) |
| 201 | + |
| 202 | + from x10.perpetual.order_object import create_order_object |
| 203 | + |
| 204 | + trading_account = create_trading_account() |
| 205 | + btc_usd_market = create_btc_usd_market() |
| 206 | + order_obj = create_order_object( |
| 207 | + account=trading_account, |
| 208 | + market=btc_usd_market, |
| 209 | + amount_of_synthetic=Decimal("0.00100000"), |
| 210 | + price=Decimal("43445.11680000"), |
| 211 | + side=OrderSide.BUY, |
| 212 | + expire_time=utc_now() + timedelta(days=14), |
| 213 | + self_trade_protection_level=SelfTradeProtectionLevel.CLIENT, |
| 214 | + starknet_domain=TESTNET_CONFIG.starknet_domain, |
| 215 | + take_profit=OrderTpslTriggerParam( |
| 216 | + trigger_price=Decimal("49000"), |
| 217 | + trigger_price_type=OrderTriggerPriceType.MARK, |
| 218 | + price=Decimal("50000"), |
| 219 | + price_type=OrderPriceType.LIMIT, |
| 220 | + ), |
| 221 | + stop_loss=OrderTpslTriggerParam( |
| 222 | + trigger_price=Decimal("40000"), |
| 223 | + trigger_price_type=OrderTriggerPriceType.MARK, |
| 224 | + price=Decimal("39000"), |
| 225 | + price_type=OrderPriceType.LIMIT, |
| 226 | + ), |
| 227 | + ) |
| 228 | + |
| 229 | + assert_that( |
| 230 | + order_obj.to_api_request_json(), |
| 231 | + equal_to( |
| 232 | + { |
| 233 | + "id": "2495374044666992118771096772295242242651427695217815113349321039194683172848", |
| 234 | + "market": "BTC-USD", |
| 235 | + "type": "LIMIT", |
| 236 | + "side": "BUY", |
| 237 | + "qty": "0.00100000", |
| 238 | + "price": "43445.11680000", |
| 239 | + "reduceOnly": False, |
| 240 | + "postOnly": False, |
| 241 | + "timeInForce": "GTT", |
| 242 | + "expiryEpochMillis": 1705626536861, |
| 243 | + "fee": "0.0005", |
| 244 | + "nonce": "1473459052", |
| 245 | + "selfTradeProtectionLevel": "CLIENT", |
| 246 | + "cancelId": None, |
| 247 | + "settlement": { |
| 248 | + "signature": { |
| 249 | + "r": "0xa55625c7d5f1b85bed22556fc805224b8363074979cf918091d9ddb1403e13", |
| 250 | + "s": "0x504caf634d859e643569743642ccf244434322859b2421d76f853af43ae7a46", |
| 251 | + }, |
| 252 | + "starkKey": "0x61c5e7e8339b7d56f197f54ea91b776776690e3232313de0f2ecbd0ef76f466", |
| 253 | + "collateralPosition": "10002", |
| 254 | + }, |
| 255 | + "trigger": None, |
| 256 | + "tpSlType": None, |
| 257 | + "takeProfit": None, |
| 258 | + "stopLoss": None, |
| 259 | + "debuggingAmounts": {"collateralAmount": "-43445117", "feeAmount": "21723", "syntheticAmount": "1000"}, |
| 260 | + "builderFee": None, |
| 261 | + "builderId": None, |
| 262 | + } |
| 263 | + ), |
| 264 | + ) |
| 265 | + |
| 266 | + |
191 | 267 | @freeze_time("2024-01-05 01:08:56.860694") |
192 | 268 | @pytest.mark.asyncio |
193 | 269 | async def test_cancel_previous_order(mocker: MockerFixture, create_trading_account, create_btc_usd_market): |
|
0 commit comments