|
| 1 | +import asyncio |
| 2 | +from utils import default_example_setup |
| 3 | + |
| 4 | + |
| 5 | +async def main(): |
| 6 | + client, api_client, _ = default_example_setup() |
| 7 | + client.check_client() |
| 8 | + |
| 9 | + # Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot. |
| 10 | + market_index = 0 |
| 11 | + integrator_account_index = 6 |
| 12 | + integrator_taker_fee = 1000 |
| 13 | + integrator_maker_fee = 500 |
| 14 | + |
| 15 | + # create order |
| 16 | + api_key_index, nonce = client.nonce_manager.next_nonce() |
| 17 | + tx, tx_hash, err = await client.create_order( |
| 18 | + market_index=market_index, |
| 19 | + client_order_index=123, |
| 20 | + base_amount=1000, # 0.1 ETH |
| 21 | + price=4050_00, # $4050 |
| 22 | + is_ask=True, |
| 23 | + order_type=client.ORDER_TYPE_LIMIT, |
| 24 | + time_in_force=client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME, |
| 25 | + reduce_only=False, |
| 26 | + trigger_price=0, |
| 27 | + integrator_account_index=integrator_account_index, |
| 28 | + integrator_taker_fee=integrator_taker_fee, |
| 29 | + integrator_maker_fee=integrator_maker_fee, |
| 30 | + nonce=nonce, |
| 31 | + api_key_index=api_key_index, |
| 32 | + ) |
| 33 | + print(f"Create Order {tx=} {tx_hash=} {err=}") |
| 34 | + if err is not None: |
| 35 | + raise Exception(err) |
| 36 | + |
| 37 | + ## modify order |
| 38 | + # use the same API key so the TX goes after the create order TX |
| 39 | + api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index) |
| 40 | + tx, tx_hash, err = await client.modify_order( |
| 41 | + market_index=market_index, |
| 42 | + order_index=123, |
| 43 | + base_amount=1100, # 0.11 ETH |
| 44 | + price=4100_00, # $4100 |
| 45 | + trigger_price=0, |
| 46 | + integrator_account_index=integrator_account_index, |
| 47 | + integrator_taker_fee=integrator_taker_fee // 2, # integrator fees can also be modified |
| 48 | + integrator_maker_fee=integrator_maker_fee // 2, |
| 49 | + nonce=nonce, |
| 50 | + api_key_index=api_key_index, |
| 51 | + ) |
| 52 | + print(f"Modify Order {tx=} {tx_hash=} {err=}") |
| 53 | + if err is not None: |
| 54 | + raise Exception(err) |
| 55 | + |
| 56 | + ## cancel order |
| 57 | + # use the same API key so the TX goes after the modify order TX |
| 58 | + api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index) |
| 59 | + tx, tx_hash, err = await client.cancel_order( |
| 60 | + market_index=market_index, |
| 61 | + order_index=123, |
| 62 | + nonce=nonce, |
| 63 | + api_key_index=api_key_index, |
| 64 | + ) |
| 65 | + print(f"Cancel Order {tx=} {tx_hash=} {err=}") |
| 66 | + if err is not None: |
| 67 | + raise Exception(err) |
| 68 | + |
| 69 | + await client.close() |
| 70 | + await api_client.close() |
| 71 | + |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + asyncio.run(main()) |
0 commit comments