From 02de6868649253ba2bafb8ff15c52c8f0c977c78 Mon Sep 17 00:00:00 2001 From: samtin0x <40127309+samtin0x@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:25:00 +0100 Subject: [PATCH 1/3] add batch cancel example --- v4-client-py-v2/dydx_v4_client/node/client.py | 29 ++++++++++++++++++- .../dydx_v4_client/node/message.py | 17 +++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/v4-client-py-v2/dydx_v4_client/node/client.py b/v4-client-py-v2/dydx_v4_client/node/client.py index 6d3098c0..8d02e959 100644 --- a/v4-client-py-v2/dydx_v4_client/node/client.py +++ b/v4-client-py-v2/dydx_v4_client/node/client.py @@ -66,6 +66,7 @@ QuerySubaccountAllResponse, ) from v4_proto.dydxprotocol.subaccounts.subaccount_pb2 import SubaccountId +from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch from dydx_v4_client.network import NodeConfig from dydx_v4_client.node.builder import Builder @@ -76,7 +77,7 @@ place_order, send_token, transfer, - withdraw, + withdraw, batch_cancel, ) from dydx_v4_client.wallet import Wallet @@ -743,3 +744,29 @@ async def cancel_order( return await self.broadcast_message( wallet, cancel_order(order_id, good_til_block, good_til_block_time) ) + + async def batch_cancel_orders( + self, + wallet: Wallet, + subaccount_id: SubaccountId, + short_term_cancels: List[OrderBatch], + good_til_block: int + ): + """ + Batch cancels orders for a subaccount. + + Args: + wallet (Wallet): The wallet to use for signing the transaction. + subaccount_id (SubaccountId): The subaccount ID for which to cancel orders. + short_term_cancels (List[OrderBatch]): List of OrderBatch objects containing the orders to cancel. + good_til_block (int): The last block the short term order cancellations can be executed at. + + Returns: + The response from the transaction broadcast. + """ + batch_cancel_msg = batch_cancel( + subaccount_id=subaccount_id, + short_term_cancels=short_term_cancels, + good_til_block=good_til_block + ) + return await self.broadcast_message(wallet, batch_cancel_msg) diff --git a/v4-client-py-v2/dydx_v4_client/node/message.py b/v4-client-py-v2/dydx_v4_client/node/message.py index 0466a115..9d55cfb1 100644 --- a/v4-client-py-v2/dydx_v4_client/node/message.py +++ b/v4-client-py-v2/dydx_v4_client/node/message.py @@ -1,3 +1,5 @@ +from typing import List + from v4_proto.cosmos.bank.v1beta1.tx_pb2 import MsgSend from v4_proto.cosmos.base.v1beta1.coin_pb2 import Coin from v4_proto.dydxprotocol.clob.order_pb2 import Order, OrderId @@ -9,6 +11,8 @@ ) from v4_proto.dydxprotocol.sending.tx_pb2 import MsgCreateTransfer from v4_proto.dydxprotocol.subaccounts.subaccount_pb2 import SubaccountId +from v4_proto.dydxprotocol.clob.tx_pb2 import MsgBatchCancel +from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch def order( @@ -75,6 +79,19 @@ def cancel_order( return message +def batch_cancel( + subaccount_id: SubaccountId, + short_term_cancels: List[OrderBatch], + good_til_block: int +): + message = MsgBatchCancel( + subaccount_id=subaccount_id, + short_term_cancels=short_term_cancels, + good_til_block=good_til_block + ) + return message + + def transfer( sender_subaccount: SubaccountId, recipient_subaccount: SubaccountId, From 108826d727018ce5cefb9781b72119ed8ef03d5e Mon Sep 17 00:00:00 2001 From: samtin0x <40127309+samtin0x@users.noreply.github.com> Date: Tue, 13 Aug 2024 12:19:19 +0100 Subject: [PATCH 2/3] add batch cancel docs --- .../documentation/cancelling_orders.md | 55 +++++++++ .../documentation/placing_orders.md | 2 +- v4-client-py-v2/dydx_v4_client/__init__.py | 8 -- .../dydx_v4_client/indexer/rest/__init__.py | 1 - .../dydx_v4_client/indexer/socket/__init__.py | 2 - .../dydx_v4_client/node/chain_helpers.py | 1 - v4-client-py-v2/dydx_v4_client/node/client.py | 19 ++-- .../dydx_v4_client/node/message.py | 7 +- .../examples/batch_cancel_example.py | 66 +++++++++++ v4-client-py-v2/poetry.lock | 104 +++++++++--------- v4-client-py-v2/pyproject.toml | 3 +- v4-client-py-v2/tests/conftest.py | 3 +- 12 files changed, 191 insertions(+), 80 deletions(-) create mode 100644 v4-client-py-v2/documentation/cancelling_orders.md create mode 100644 v4-client-py-v2/examples/batch_cancel_example.py diff --git a/v4-client-py-v2/documentation/cancelling_orders.md b/v4-client-py-v2/documentation/cancelling_orders.md new file mode 100644 index 00000000..3b1512c1 --- /dev/null +++ b/v4-client-py-v2/documentation/cancelling_orders.md @@ -0,0 +1,55 @@ +# Cancelling Orders + +This guide demonstrates how to cancel orders using the dYdX Python SDK. + +## Cancelling Orders + +There are two ways to cancel orders using the dYdX Python SDK: + +### 1. Cancel a Specific Order + +To cancel a specific order, you can use the `cancel_order` method. Here's an example: + +```python +from dydx_v4_client.node.message import cancel_order + +cancel_order_msg = cancel_order( + order_id, + good_til_block, + good_til_block_time +) + +response = await node_client.cancel_order( + wallet, + order_id, + good_til_block=good_til_block, + good_til_block_time=good_til_block_time +) +``` + +### 2. Batch Cancel Orders +For cancelling multiple orders at once, you can use the batch_cancel_orders method. Here's an example: +pythonCopyfrom dydx_v4_client.node.message import batch_cancel +from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch + +```python +batch_cancel_msg = batch_cancel( + subaccount_id, + short_term_cancels, + good_til_block +) + +response = await node_client.batch_cancel_orders( + wallet, + subaccount_id, + short_term_cancels, + good_til_block +) +``` + +### Examples +For more detailed examples of how to cancel orders: +- **Cancelling a specific order**: See `examples/long_term_order_cancel_example.py` +- **Batch cancelling orders**: See `examples/batch_cancel_example.py` + + diff --git a/v4-client-py-v2/documentation/placing_orders.md b/v4-client-py-v2/documentation/placing_orders.md index 127b2441..0ed2e235 100644 --- a/v4-client-py-v2/documentation/placing_orders.md +++ b/v4-client-py-v2/documentation/placing_orders.md @@ -33,4 +33,4 @@ Alternatively, you can use the market-based calculator, which provides more conv - Long term order + cancel: Example in `examples/long_term_order_cancel_example.py` ## Next Steps -Continue reading to learn how to [manage your positions](./account_order_information.md) using the dYdX Python SDK. +Continue reading to learn how to [cancel orders](./cancelling_orders.md) using the dYdX Python SDK. diff --git a/v4-client-py-v2/dydx_v4_client/__init__.py b/v4-client-py-v2/dydx_v4_client/__init__.py index 94c4918c..1d9402c8 100644 --- a/v4-client-py-v2/dydx_v4_client/__init__.py +++ b/v4-client-py-v2/dydx_v4_client/__init__.py @@ -1,13 +1,5 @@ from enum import IntEnum -from v4_proto.dydxprotocol.clob.order_pb2 import Order - -from dydx_v4_client.faucet_client import FaucetClient -from dydx_v4_client.indexer.rest.indexer_client import IndexerClient -from dydx_v4_client.indexer.socket.websocket import IndexerSocket -from dydx_v4_client.node.client import NodeClient, QueryNodeClient -from dydx_v4_client.wallet import Wallet - class OrderFlags(IntEnum): SHORT_TERM = 0 diff --git a/v4-client-py-v2/dydx_v4_client/indexer/rest/__init__.py b/v4-client-py-v2/dydx_v4_client/indexer/rest/__init__.py index e25297d8..e69de29b 100644 --- a/v4-client-py-v2/dydx_v4_client/indexer/rest/__init__.py +++ b/v4-client-py-v2/dydx_v4_client/indexer/rest/__init__.py @@ -1 +0,0 @@ -from dydx_v4_client.indexer.rest.indexer_client import IndexerClient diff --git a/v4-client-py-v2/dydx_v4_client/indexer/socket/__init__.py b/v4-client-py-v2/dydx_v4_client/indexer/socket/__init__.py index fa7109a8..e69de29b 100644 --- a/v4-client-py-v2/dydx_v4_client/indexer/socket/__init__.py +++ b/v4-client-py-v2/dydx_v4_client/indexer/socket/__init__.py @@ -1,2 +0,0 @@ -from dydx_v4_client.indexer.socket.websocket import IndexerSocket -from dydx_v4_client.indexer.candles_resolution import CandlesResolution diff --git a/v4-client-py-v2/dydx_v4_client/node/chain_helpers.py b/v4-client-py-v2/dydx_v4_client/node/chain_helpers.py index 829eaf7c..baf91a7e 100644 --- a/v4-client-py-v2/dydx_v4_client/node/chain_helpers.py +++ b/v4-client-py-v2/dydx_v4_client/node/chain_helpers.py @@ -1,7 +1,6 @@ from dydx_v4_client.indexer.rest.constants import ( OrderType, OrderExecution, - OrderTimeInForce, ) from v4_proto.dydxprotocol.clob.order_pb2 import Order diff --git a/v4-client-py-v2/dydx_v4_client/node/client.py b/v4-client-py-v2/dydx_v4_client/node/client.py index 8d02e959..937fd58d 100644 --- a/v4-client-py-v2/dydx_v4_client/node/client.py +++ b/v4-client-py-v2/dydx_v4_client/node/client.py @@ -5,7 +5,7 @@ import grpc from google._upb._message import Message -from google.protobuf.json_format import MessageToDict, MessageToJson +from google.protobuf.json_format import MessageToDict from typing_extensions import List, Optional, Self from v4_proto.cosmos.auth.v1beta1 import query_pb2_grpc as auth from v4_proto.cosmos.auth.v1beta1.auth_pb2 import BaseAccount @@ -66,7 +66,7 @@ QuerySubaccountAllResponse, ) from v4_proto.dydxprotocol.subaccounts.subaccount_pb2 import SubaccountId -from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch +from v4_proto.dydxprotocol.clob.tx_pb2 import OrderBatch from dydx_v4_client.network import NodeConfig from dydx_v4_client.node.builder import Builder @@ -77,7 +77,8 @@ place_order, send_token, transfer, - withdraw, batch_cancel, + withdraw, + batch_cancel, ) from dydx_v4_client.wallet import Wallet @@ -746,11 +747,11 @@ async def cancel_order( ) async def batch_cancel_orders( - self, - wallet: Wallet, - subaccount_id: SubaccountId, - short_term_cancels: List[OrderBatch], - good_til_block: int + self, + wallet: Wallet, + subaccount_id: SubaccountId, + short_term_cancels: List[OrderBatch], + good_til_block: int, ): """ Batch cancels orders for a subaccount. @@ -767,6 +768,6 @@ async def batch_cancel_orders( batch_cancel_msg = batch_cancel( subaccount_id=subaccount_id, short_term_cancels=short_term_cancels, - good_til_block=good_til_block + good_til_block=good_til_block, ) return await self.broadcast_message(wallet, batch_cancel_msg) diff --git a/v4-client-py-v2/dydx_v4_client/node/message.py b/v4-client-py-v2/dydx_v4_client/node/message.py index 9d55cfb1..aedd1186 100644 --- a/v4-client-py-v2/dydx_v4_client/node/message.py +++ b/v4-client-py-v2/dydx_v4_client/node/message.py @@ -11,8 +11,7 @@ ) from v4_proto.dydxprotocol.sending.tx_pb2 import MsgCreateTransfer from v4_proto.dydxprotocol.subaccounts.subaccount_pb2 import SubaccountId -from v4_proto.dydxprotocol.clob.tx_pb2 import MsgBatchCancel -from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch +from v4_proto.dydxprotocol.clob.tx_pb2 import MsgBatchCancel, OrderBatch def order( @@ -82,12 +81,12 @@ def cancel_order( def batch_cancel( subaccount_id: SubaccountId, short_term_cancels: List[OrderBatch], - good_til_block: int + good_til_block: int, ): message = MsgBatchCancel( subaccount_id=subaccount_id, short_term_cancels=short_term_cancels, - good_til_block=good_til_block + good_til_block=good_til_block, ) return message diff --git a/v4-client-py-v2/examples/batch_cancel_example.py b/v4-client-py-v2/examples/batch_cancel_example.py new file mode 100644 index 00000000..0ada8901 --- /dev/null +++ b/v4-client-py-v2/examples/batch_cancel_example.py @@ -0,0 +1,66 @@ +import asyncio +import random + +from dydx_v4_client import MAX_CLIENT_ID, NodeClient, Order, OrderFlags +from dydx_v4_client.indexer.rest.constants import OrderType +from dydx_v4_client.indexer.rest.indexer_client import IndexerClient +from dydx_v4_client.network import TESTNET +from dydx_v4_client.node.market import Market +from dydx_v4_client.wallet import Wallet +from tests.conftest import DYDX_TEST_MNEMONIC, TEST_ADDRESS +from v4_proto.dydxprotocol.clob.tx_pb2 import OrderBatch +from v4_proto.dydxprotocol.subaccounts.subaccount_pb2 import SubaccountId + + +MARKET_ID = "BTC-USD" +PERPETUAL_PAIR_BTC_USD = 0 + + +async def test_batch_cancel(): + node = await NodeClient.connect(TESTNET.node) + indexer = IndexerClient(TESTNET.rest_indexer) + + market = Market( + (await indexer.markets.get_perpetual_markets(MARKET_ID))["markets"][MARKET_ID] + ) + wallet = await Wallet.from_mnemonic(node, DYDX_TEST_MNEMONIC, TEST_ADDRESS) + + # Place multiple orders + orders = [] + client_ids = [] + for _ in range(3): + client_id = random.randint(0, MAX_CLIENT_ID) + order_id = market.order_id(TEST_ADDRESS, 0, client_id, OrderFlags.SHORT_TERM) + client_ids.append(client_id) + current_block = await node.latest_block_height() + order = market.order( + order_id, + side=Order.Side.SIDE_SELL, + order_type=OrderType.LIMIT, + size=0.01, + price=40000 + random.randint(-100, 100), + time_in_force=Order.TIME_IN_FORCE_IOC, + reduce_only=False, + good_til_block=current_block + 20, + ) + orders.append(order) + + # Place orders + for order in orders: + place = await node.place_order(wallet, order) + print(f"Placed order: {place}") + wallet.sequence += 1 + + # Prepare batch cancel + subaccount_id = SubaccountId(owner=TEST_ADDRESS, number=0) + order_batch = OrderBatch(clob_pair_id=PERPETUAL_PAIR_BTC_USD, client_ids=client_ids) + cancellation_current_block = await node.latest_block_height() + + # Execute batch cancel + batch_cancel_response = await node.batch_cancel_orders( + wallet, subaccount_id, [order_batch], cancellation_current_block + 10 + ) + print(f"Batch cancel response: {batch_cancel_response}") + + +asyncio.run(test_batch_cancel()) diff --git a/v4-client-py-v2/poetry.lock b/v4-client-py-v2/poetry.lock index 0644604a..d2655998 100644 --- a/v4-client-py-v2/poetry.lock +++ b/v4-client-py-v2/poetry.lock @@ -614,61 +614,61 @@ typing = ["typing-extensions (>=4.8)"] [[package]] name = "grpcio" -version = "1.64.1" +version = "1.65.4" description = "HTTP/2-based RPC framework" optional = false python-versions = ">=3.8" files = [ - {file = "grpcio-1.64.1-cp310-cp310-linux_armv7l.whl", hash = "sha256:55697ecec192bc3f2f3cc13a295ab670f51de29884ca9ae6cd6247df55df2502"}, - {file = "grpcio-1.64.1-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:3b64ae304c175671efdaa7ec9ae2cc36996b681eb63ca39c464958396697daff"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:bac71b4b28bc9af61efcdc7630b166440bbfbaa80940c9a697271b5e1dabbc61"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6c024ffc22d6dc59000faf8ad781696d81e8e38f4078cb0f2630b4a3cf231a90"}, - {file = "grpcio-1.64.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e7cd5c1325f6808b8ae31657d281aadb2a51ac11ab081ae335f4f7fc44c1721d"}, - {file = "grpcio-1.64.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:0a2813093ddb27418a4c99f9b1c223fab0b053157176a64cc9db0f4557b69bd9"}, - {file = "grpcio-1.64.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:2981c7365a9353f9b5c864595c510c983251b1ab403e05b1ccc70a3d9541a73b"}, - {file = "grpcio-1.64.1-cp310-cp310-win32.whl", hash = "sha256:1262402af5a511c245c3ae918167eca57342c72320dffae5d9b51840c4b2f86d"}, - {file = "grpcio-1.64.1-cp310-cp310-win_amd64.whl", hash = "sha256:19264fc964576ddb065368cae953f8d0514ecc6cb3da8903766d9fb9d4554c33"}, - {file = "grpcio-1.64.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:58b1041e7c870bb30ee41d3090cbd6f0851f30ae4eb68228955d973d3efa2e61"}, - {file = "grpcio-1.64.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:bbc5b1d78a7822b0a84c6f8917faa986c1a744e65d762ef6d8be9d75677af2ca"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:5841dd1f284bd1b3d8a6eca3a7f062b06f1eec09b184397e1d1d43447e89a7ae"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8caee47e970b92b3dd948371230fcceb80d3f2277b3bf7fbd7c0564e7d39068e"}, - {file = "grpcio-1.64.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:73819689c169417a4f978e562d24f2def2be75739c4bed1992435d007819da1b"}, - {file = "grpcio-1.64.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:6503b64c8b2dfad299749cad1b595c650c91e5b2c8a1b775380fcf8d2cbba1e9"}, - {file = "grpcio-1.64.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:1de403fc1305fd96cfa75e83be3dee8538f2413a6b1685b8452301c7ba33c294"}, - {file = "grpcio-1.64.1-cp311-cp311-win32.whl", hash = "sha256:d4d29cc612e1332237877dfa7fe687157973aab1d63bd0f84cf06692f04c0367"}, - {file = "grpcio-1.64.1-cp311-cp311-win_amd64.whl", hash = "sha256:5e56462b05a6f860b72f0fa50dca06d5b26543a4e88d0396259a07dc30f4e5aa"}, - {file = "grpcio-1.64.1-cp312-cp312-linux_armv7l.whl", hash = "sha256:4657d24c8063e6095f850b68f2d1ba3b39f2b287a38242dcabc166453e950c59"}, - {file = "grpcio-1.64.1-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:62b4e6eb7bf901719fce0ca83e3ed474ae5022bb3827b0a501e056458c51c0a1"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:ee73a2f5ca4ba44fa33b4d7d2c71e2c8a9e9f78d53f6507ad68e7d2ad5f64a22"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:198908f9b22e2672a998870355e226a725aeab327ac4e6ff3a1399792ece4762"}, - {file = "grpcio-1.64.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39b9d0acaa8d835a6566c640f48b50054f422d03e77e49716d4c4e8e279665a1"}, - {file = "grpcio-1.64.1-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:5e42634a989c3aa6049f132266faf6b949ec2a6f7d302dbb5c15395b77d757eb"}, - {file = "grpcio-1.64.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:b1a82e0b9b3022799c336e1fc0f6210adc019ae84efb7321d668129d28ee1efb"}, - {file = "grpcio-1.64.1-cp312-cp312-win32.whl", hash = "sha256:55260032b95c49bee69a423c2f5365baa9369d2f7d233e933564d8a47b893027"}, - {file = "grpcio-1.64.1-cp312-cp312-win_amd64.whl", hash = "sha256:c1a786ac592b47573a5bb7e35665c08064a5d77ab88a076eec11f8ae86b3e3f6"}, - {file = "grpcio-1.64.1-cp38-cp38-linux_armv7l.whl", hash = "sha256:a011ac6c03cfe162ff2b727bcb530567826cec85eb8d4ad2bfb4bd023287a52d"}, - {file = "grpcio-1.64.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:4d6dab6124225496010bd22690f2d9bd35c7cbb267b3f14e7a3eb05c911325d4"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:a5e771d0252e871ce194d0fdcafd13971f1aae0ddacc5f25615030d5df55c3a2"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2c3c1b90ab93fed424e454e93c0ed0b9d552bdf1b0929712b094f5ecfe7a23ad"}, - {file = "grpcio-1.64.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20405cb8b13fd779135df23fabadc53b86522d0f1cba8cca0e87968587f50650"}, - {file = "grpcio-1.64.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:0cc79c982ccb2feec8aad0e8fb0d168bcbca85bc77b080d0d3c5f2f15c24ea8f"}, - {file = "grpcio-1.64.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:a3a035c37ce7565b8f4f35ff683a4db34d24e53dc487e47438e434eb3f701b2a"}, - {file = "grpcio-1.64.1-cp38-cp38-win32.whl", hash = "sha256:1257b76748612aca0f89beec7fa0615727fd6f2a1ad580a9638816a4b2eb18fd"}, - {file = "grpcio-1.64.1-cp38-cp38-win_amd64.whl", hash = "sha256:0a12ddb1678ebc6a84ec6b0487feac020ee2b1659cbe69b80f06dbffdb249122"}, - {file = "grpcio-1.64.1-cp39-cp39-linux_armv7l.whl", hash = "sha256:75dbbf415026d2862192fe1b28d71f209e2fd87079d98470db90bebe57b33179"}, - {file = "grpcio-1.64.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:e3d9f8d1221baa0ced7ec7322a981e28deb23749c76eeeb3d33e18b72935ab62"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:5f8b75f64d5d324c565b263c67dbe4f0af595635bbdd93bb1a88189fc62ed2e5"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c84ad903d0d94311a2b7eea608da163dace97c5fe9412ea311e72c3684925602"}, - {file = "grpcio-1.64.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:940e3ec884520155f68a3b712d045e077d61c520a195d1a5932c531f11883489"}, - {file = "grpcio-1.64.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:f10193c69fc9d3d726e83bbf0f3d316f1847c3071c8c93d8090cf5f326b14309"}, - {file = "grpcio-1.64.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ac15b6c2c80a4d1338b04d42a02d376a53395ddf0ec9ab157cbaf44191f3ffdd"}, - {file = "grpcio-1.64.1-cp39-cp39-win32.whl", hash = "sha256:03b43d0ccf99c557ec671c7dede64f023c7da9bb632ac65dbc57f166e4970040"}, - {file = "grpcio-1.64.1-cp39-cp39-win_amd64.whl", hash = "sha256:ed6091fa0adcc7e4ff944090cf203a52da35c37a130efa564ded02b7aff63bcd"}, - {file = "grpcio-1.64.1.tar.gz", hash = "sha256:8d51dd1c59d5fa0f34266b80a3805ec29a1f26425c2a54736133f6d87fc4968a"}, + {file = "grpcio-1.65.4-cp310-cp310-linux_armv7l.whl", hash = "sha256:0e85c8766cf7f004ab01aff6a0393935a30d84388fa3c58d77849fcf27f3e98c"}, + {file = "grpcio-1.65.4-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:e4a795c02405c7dfa8affd98c14d980f4acea16ea3b539e7404c645329460e5a"}, + {file = "grpcio-1.65.4-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:d7b984a8dd975d949c2042b9b5ebcf297d6d5af57dcd47f946849ee15d3c2fb8"}, + {file = "grpcio-1.65.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:644a783ce604a7d7c91412bd51cf9418b942cf71896344b6dc8d55713c71ce82"}, + {file = "grpcio-1.65.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5764237d751d3031a36fafd57eb7d36fd2c10c658d2b4057c516ccf114849a3e"}, + {file = "grpcio-1.65.4-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:ee40d058cf20e1dd4cacec9c39e9bce13fedd38ce32f9ba00f639464fcb757de"}, + {file = "grpcio-1.65.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:4482a44ce7cf577a1f8082e807a5b909236bce35b3e3897f839f2fbd9ae6982d"}, + {file = "grpcio-1.65.4-cp310-cp310-win32.whl", hash = "sha256:66bb051881c84aa82e4f22d8ebc9d1704b2e35d7867757f0740c6ef7b902f9b1"}, + {file = "grpcio-1.65.4-cp310-cp310-win_amd64.whl", hash = "sha256:870370524eff3144304da4d1bbe901d39bdd24f858ce849b7197e530c8c8f2ec"}, + {file = "grpcio-1.65.4-cp311-cp311-linux_armv7l.whl", hash = "sha256:85e9c69378af02e483bc626fc19a218451b24a402bdf44c7531e4c9253fb49ef"}, + {file = "grpcio-1.65.4-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:2bd672e005afab8bf0d6aad5ad659e72a06dd713020554182a66d7c0c8f47e18"}, + {file = "grpcio-1.65.4-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:abccc5d73f5988e8f512eb29341ed9ced923b586bb72e785f265131c160231d8"}, + {file = "grpcio-1.65.4-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:886b45b29f3793b0c2576201947258782d7e54a218fe15d4a0468d9a6e00ce17"}, + {file = "grpcio-1.65.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be952436571dacc93ccc7796db06b7daf37b3b56bb97e3420e6503dccfe2f1b4"}, + {file = "grpcio-1.65.4-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:8dc9ddc4603ec43f6238a5c95400c9a901b6d079feb824e890623da7194ff11e"}, + {file = "grpcio-1.65.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:ade1256c98cba5a333ef54636095f2c09e6882c35f76acb04412f3b1aa3c29a5"}, + {file = "grpcio-1.65.4-cp311-cp311-win32.whl", hash = "sha256:280e93356fba6058cbbfc6f91a18e958062ef1bdaf5b1caf46c615ba1ae71b5b"}, + {file = "grpcio-1.65.4-cp311-cp311-win_amd64.whl", hash = "sha256:d2b819f9ee27ed4e3e737a4f3920e337e00bc53f9e254377dd26fc7027c4d558"}, + {file = "grpcio-1.65.4-cp312-cp312-linux_armv7l.whl", hash = "sha256:926a0750a5e6fb002542e80f7fa6cab8b1a2ce5513a1c24641da33e088ca4c56"}, + {file = "grpcio-1.65.4-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:2a1d4c84d9e657f72bfbab8bedf31bdfc6bfc4a1efb10b8f2d28241efabfaaf2"}, + {file = "grpcio-1.65.4-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:17de4fda50967679677712eec0a5c13e8904b76ec90ac845d83386b65da0ae1e"}, + {file = "grpcio-1.65.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3dee50c1b69754a4228e933696408ea87f7e896e8d9797a3ed2aeed8dbd04b74"}, + {file = "grpcio-1.65.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:74c34fc7562bdd169b77966068434a93040bfca990e235f7a67cdf26e1bd5c63"}, + {file = "grpcio-1.65.4-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:24a2246e80a059b9eb981e4c2a6d8111b1b5e03a44421adbf2736cc1d4988a8a"}, + {file = "grpcio-1.65.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:18c10f0d054d2dce34dd15855fcca7cc44ec3b811139437543226776730c0f28"}, + {file = "grpcio-1.65.4-cp312-cp312-win32.whl", hash = "sha256:d72962788b6c22ddbcdb70b10c11fbb37d60ae598c51eb47ec019db66ccfdff0"}, + {file = "grpcio-1.65.4-cp312-cp312-win_amd64.whl", hash = "sha256:7656376821fed8c89e68206a522522317787a3d9ed66fb5110b1dff736a5e416"}, + {file = "grpcio-1.65.4-cp38-cp38-linux_armv7l.whl", hash = "sha256:4934077b33aa6fe0b451de8b71dabde96bf2d9b4cb2b3187be86e5adebcba021"}, + {file = "grpcio-1.65.4-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:0cef8c919a3359847c357cb4314e50ed1f0cca070f828ee8f878d362fd744d52"}, + {file = "grpcio-1.65.4-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:a925446e6aa12ca37114840d8550f308e29026cdc423a73da3043fd1603a6385"}, + {file = "grpcio-1.65.4-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cf53e6247f1e2af93657e62e240e4f12e11ee0b9cef4ddcb37eab03d501ca864"}, + {file = "grpcio-1.65.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cdb34278e4ceb224c89704cd23db0d902e5e3c1c9687ec9d7c5bb4c150f86816"}, + {file = "grpcio-1.65.4-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:e6cbdd107e56bde55c565da5fd16f08e1b4e9b0674851d7749e7f32d8645f524"}, + {file = "grpcio-1.65.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:626319a156b1f19513156a3b0dbfe977f5f93db63ca673a0703238ebd40670d7"}, + {file = "grpcio-1.65.4-cp38-cp38-win32.whl", hash = "sha256:3d1bbf7e1dd1096378bd83c83f554d3b93819b91161deaf63e03b7022a85224a"}, + {file = "grpcio-1.65.4-cp38-cp38-win_amd64.whl", hash = "sha256:a99e6dffefd3027b438116f33ed1261c8d360f0dd4f943cb44541a2782eba72f"}, + {file = "grpcio-1.65.4-cp39-cp39-linux_armv7l.whl", hash = "sha256:874acd010e60a2ec1e30d5e505b0651ab12eb968157cd244f852b27c6dbed733"}, + {file = "grpcio-1.65.4-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:b07f36faf01fca5427d4aa23645e2d492157d56c91fab7e06fe5697d7e171ad4"}, + {file = "grpcio-1.65.4-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:b81711bf4ec08a3710b534e8054c7dcf90f2edc22bebe11c1775a23f145595fe"}, + {file = "grpcio-1.65.4-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:88fcabc332a4aef8bcefadc34a02e9ab9407ab975d2c7d981a8e12c1aed92aa1"}, + {file = "grpcio-1.65.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c9ba3e63108a8749994f02c7c0e156afb39ba5bdf755337de8e75eb685be244b"}, + {file = "grpcio-1.65.4-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:8eb485801957a486bf5de15f2c792d9f9c897a86f2f18db8f3f6795a094b4bb2"}, + {file = "grpcio-1.65.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:075f3903bc1749ace93f2b0664f72964ee5f2da5c15d4b47e0ab68e4f442c257"}, + {file = "grpcio-1.65.4-cp39-cp39-win32.whl", hash = "sha256:0a0720299bdb2cc7306737295d56e41ce8827d5669d4a3cd870af832e3b17c4d"}, + {file = "grpcio-1.65.4-cp39-cp39-win_amd64.whl", hash = "sha256:a146bc40fa78769f22e1e9ff4f110ef36ad271b79707577bf2a31e3e931141b9"}, + {file = "grpcio-1.65.4.tar.gz", hash = "sha256:2a4f476209acffec056360d3e647ae0e14ae13dcf3dfb130c227ae1c594cbe39"}, ] [package.extras] -protobuf = ["grpcio-tools (>=1.64.1)"] +protobuf = ["grpcio-tools (>=1.65.4)"] [[package]] name = "grpcio-tools" @@ -1642,13 +1642,13 @@ zstd = ["zstandard (>=0.18.0)"] [[package]] name = "v4-proto" -version = "4.1.4" +version = "5.2.1" description = "Protos for dYdX Chain protocol" optional = false python-versions = ">=3.8" files = [ - {file = "v4-proto-4.1.4.tar.gz", hash = "sha256:264d29a3f666a8686586789bb9bbec8a6d58ff16ffcece53a18fbb6ff97451c9"}, - {file = "v4_proto-4.1.4-py3-none-any.whl", hash = "sha256:9ee85862a0d9c3005ade4d4479332337d4b074d25e09bc4ca99d181b75de313c"}, + {file = "v4-proto-5.2.1.tar.gz", hash = "sha256:7de9f84cc13adcdae7ab920b0c615d8a878bb4006e11ef501188685fc9b5a9ec"}, + {file = "v4_proto-5.2.1-py3-none-any.whl", hash = "sha256:8b4c802c14fb5d2662191e329129218c26547d296e4f5e745e8217338355b66c"}, ] [package.dependencies] @@ -1710,4 +1710,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "08f167d695bb0327aa94b6bb9bd4ca0671fa89a1e443b6235a1d7f4cfba04f75" +content-hash = "8554d8aff1f50abaeb0ef9f86af09f79ab7835f9f93434cbbae4da906408b253" diff --git a/v4-client-py-v2/pyproject.toml b/v4-client-py-v2/pyproject.toml index 6e4d5e55..ec6b8b32 100644 --- a/v4-client-py-v2/pyproject.toml +++ b/v4-client-py-v2/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.9" -v4-proto = "^4.0.1" +v4-proto = "5.2.1" httpx = "^0.27.0" websocket-client = "^1.7.0" bip-utils = "^2.9.3" @@ -15,6 +15,7 @@ ecdsa = "^0.19.0" typing-extensions = "^4.12.2" bech32 = "^1.2.0" pycryptodome = "^3.20.0" +grpcio = "1.65.4" [tool.poetry.group.dev.dependencies] diff --git a/v4-client-py-v2/tests/conftest.py b/v4-client-py-v2/tests/conftest.py index aa13161f..1a597d66 100644 --- a/v4-client-py-v2/tests/conftest.py +++ b/v4-client-py-v2/tests/conftest.py @@ -6,11 +6,12 @@ import httpx import pytest -from dydx_v4_client import FaucetClient, NodeClient +from dydx_v4_client.faucet_client import FaucetClient from dydx_v4_client.indexer.rest.indexer_client import IndexerClient from dydx_v4_client.indexer.rest.noble_client import NobleClient from dydx_v4_client.indexer.socket.websocket import IndexerSocket from dydx_v4_client.network import TESTNET, TESTNET_FAUCET, TESTNET_NOBLE +from dydx_v4_client.node.client import NodeClient from dydx_v4_client.node.message import order, order_id from dydx_v4_client.wallet import Wallet, from_mnemonic From 81848aaa8aa1eea1fe043f2f90969ebf854f6212 Mon Sep 17 00:00:00 2001 From: samtin0x <40127309+samtin0x@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:56:42 +0100 Subject: [PATCH 3/3] add `short_term_cancels` to documentation --- v4-client-py-v2/documentation/cancelling_orders.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/v4-client-py-v2/documentation/cancelling_orders.md b/v4-client-py-v2/documentation/cancelling_orders.md index 3b1512c1..1de8aab7 100644 --- a/v4-client-py-v2/documentation/cancelling_orders.md +++ b/v4-client-py-v2/documentation/cancelling_orders.md @@ -33,6 +33,11 @@ pythonCopyfrom dydx_v4_client.node.message import batch_cancel from v4_proto.dydxprotocol.clob.order_pb2 import OrderBatch ```python +PERPETUAL_PAIR_BTC_USD = 0 + +client_ids = [tx_client_id1, tx_client_id2] +short_term_cancels = [OrderBatch(clob_pair_id=PERPETUAL_PAIR_BTC_USD, client_ids=client_ids)] + batch_cancel_msg = batch_cancel( subaccount_id, short_term_cancels,