diff --git a/artifacts/APITradingClassicPic1.png b/artifacts/APITradingClassicPic1.png new file mode 100644 index 00000000..1ea7a179 Binary files /dev/null and b/artifacts/APITradingClassicPic1.png differ diff --git a/artifacts/APITradingClassicPic2.png b/artifacts/APITradingClassicPic2.png new file mode 100644 index 00000000..9dff7f2f Binary files /dev/null and b/artifacts/APITradingClassicPic2.png differ diff --git a/artifacts/APITradingClassicPic3.png b/artifacts/APITradingClassicPic3.png new file mode 100644 index 00000000..9e9c459e Binary files /dev/null and b/artifacts/APITradingClassicPic3.png differ diff --git a/artifacts/APITradingClassicPic4.png b/artifacts/APITradingClassicPic4.png new file mode 100644 index 00000000..19966102 Binary files /dev/null and b/artifacts/APITradingClassicPic4.png differ diff --git a/artifacts/CLIPythonScript1.png b/artifacts/CLIPythonScript1.png new file mode 100644 index 00000000..f9145ef3 Binary files /dev/null and b/artifacts/CLIPythonScript1.png differ diff --git a/artifacts/CLIPythonScript10.png b/artifacts/CLIPythonScript10.png new file mode 100644 index 00000000..c64ea002 Binary files /dev/null and b/artifacts/CLIPythonScript10.png differ diff --git a/artifacts/CLIPythonScript11.png b/artifacts/CLIPythonScript11.png new file mode 100644 index 00000000..dc2d65e6 Binary files /dev/null and b/artifacts/CLIPythonScript11.png differ diff --git a/artifacts/CLIPythonScript12.png b/artifacts/CLIPythonScript12.png new file mode 100644 index 00000000..3e612270 Binary files /dev/null and b/artifacts/CLIPythonScript12.png differ diff --git a/artifacts/CLIPythonScript13.png b/artifacts/CLIPythonScript13.png new file mode 100644 index 00000000..dd8c83d6 Binary files /dev/null and b/artifacts/CLIPythonScript13.png differ diff --git a/artifacts/CLIPythonScript2.png b/artifacts/CLIPythonScript2.png new file mode 100644 index 00000000..e865ad54 Binary files /dev/null and b/artifacts/CLIPythonScript2.png differ diff --git a/artifacts/CLIPythonScript3.png b/artifacts/CLIPythonScript3.png new file mode 100644 index 00000000..c22d376e Binary files /dev/null and b/artifacts/CLIPythonScript3.png differ diff --git a/artifacts/CLIPythonScript4.png b/artifacts/CLIPythonScript4.png new file mode 100644 index 00000000..42af803a Binary files /dev/null and b/artifacts/CLIPythonScript4.png differ diff --git a/artifacts/CLIPythonScript5.png b/artifacts/CLIPythonScript5.png new file mode 100644 index 00000000..71bcc16c Binary files /dev/null and b/artifacts/CLIPythonScript5.png differ diff --git a/artifacts/CLIPythonScript6.png b/artifacts/CLIPythonScript6.png new file mode 100644 index 00000000..8e4ca8b3 Binary files /dev/null and b/artifacts/CLIPythonScript6.png differ diff --git a/artifacts/CLIPythonScript7.png b/artifacts/CLIPythonScript7.png new file mode 100644 index 00000000..6e184dec Binary files /dev/null and b/artifacts/CLIPythonScript7.png differ diff --git a/artifacts/CLIPythonScript8.png b/artifacts/CLIPythonScript8.png new file mode 100644 index 00000000..67dc0838 Binary files /dev/null and b/artifacts/CLIPythonScript8.png differ diff --git a/artifacts/CLIPythonScript9.png b/artifacts/CLIPythonScript9.png new file mode 100644 index 00000000..aeb9b4f4 Binary files /dev/null and b/artifacts/CLIPythonScript9.png differ diff --git a/pages/api_integration-guides/_meta.json b/pages/api_integration-guides/_meta.json index b16c7893..12f3531e 100644 --- a/pages/api_integration-guides/_meta.json +++ b/pages/api_integration-guides/_meta.json @@ -1,9 +1,10 @@ { "Getting_started_with_the_typescript_client": "Getting started with the Typescript client", + "api_trading_with_classic_python_client": "API Trading with Classic Python Client", + "cli_python_script": "CLI Python Script", "how_to_uncross_orderbook": "How to uncross the orderbook", "how_to_interpret_block_data_for_trades": "How to interpret block data for trades", "setting_up_raspberry_pi_for_api_trading": "Setting up Raspberry Pi for API Trading", - "cli_python_script": "CLI Python Script", "how_to_transfer_tokens_between_accounts": "How to transfer tokens between accounts", "how_to_isolated": "How to integrate APIs with FE isolated positions" } diff --git a/pages/api_integration-guides/api_trading_with_classic_python_client.md b/pages/api_integration-guides/api_trading_with_classic_python_client.md new file mode 100644 index 00000000..959e9aca --- /dev/null +++ b/pages/api_integration-guides/api_trading_with_classic_python_client.md @@ -0,0 +1,60 @@ +# API Trading with (Classic) v4 dYdX Python Client + +## Pros and Cons of (Classic) V4 dYdX Python Client +1. Pro: Used by many traders already +2. Pro: Easy setup (this document) +3. Pro: Required for V4 dYdX CLI Tool +4. Con: Can only trade cross-margin markets in cross-margin mode. As of December 3, 2024, the following markets are cross-margin capable or isolated-margin only. + +![APITradingClassicPic1](../../artifacts/APITradingClassicPic1.png) + +## Requirements (Initial Setup) +1. Recommended OS: Ubuntu 22.04.4 LTS server (ubuntu-22.04.4-live-server-amd64.iso) +2. Install dependencies. + +`sudo apt-get install python3-pip` + +`pip3 install v4-proto` + +`pip3 install python-dateutil` + +`pip3 install bip_utils` + +`pip3 install bech32` + +`pip3 install websocket-client` + +`git clone https://github.com/kaloureyes3/v4-clients` + +3. Create a APIKEY file. In this file, type the line `DYDX_TEST_MNEMONIC = '’ +vi myapikeyfile.py'` + +![APITradingClassicPic2](../../artifacts/APITradingClassicPic2.png) + +4. Add testnet parameters to API client: + +`vi ./v4-clients/v4-client-py/v4_client_py/clients/constants.py` + +![APITradingClassicPic4](../../artifacts/APITradingClassicPic4.png) + +![APITradingClassicPic3](../../artifacts/APITradingClassicPic3.png) + +`VALIDATOR_GRPC_ENDPOINT = 'test-dydx-grpc.kingnodes.com:443'` + +`AERIAL_CONFIG_URL = 'https://test-dydx-grpc.kingnodes.com:443'` + +`AERIAL_GRPC_OR_REST_PREFIX = "grpc"` + +`INDEXER_REST_ENDPOINT = 'https://dydx-testnet.imperator.co'` + +`INDEXER_WS_ENDPOINT = 'wss://indexer.v4testnet.dydx.exchange/v4/ws'` + +`CHAIN_ID = "dydx-testnet-4"` + +`ENV = 'testnet'` + +5. Setup is complete. + +## The V4 dYdX CLI Tool +1. Download the tool from https://github.com/chiwalfrm/solutions-public/tree/main/v4dydxcli +2. Refer to this document for instructions: https://docs.google.com/document/d/13aZz9o4g0WyLrteelBYDUOUmzJgOaPouVwRrF0kn-to/edit?usp=sharing diff --git a/pages/api_integration-guides/cli_python_script.md b/pages/api_integration-guides/cli_python_script.mdx similarity index 80% rename from pages/api_integration-guides/cli_python_script.md rename to pages/api_integration-guides/cli_python_script.mdx index 563e3f23..12f818b0 100644 --- a/pages/api_integration-guides/cli_python_script.md +++ b/pages/api_integration-guides/cli_python_script.mdx @@ -1,12 +1,12 @@ # CLI Python Script -## Command syntax - +## Command: syntax Run the script like this: -- Syntax: +- Syntax `python3 v4dydxcli.py ` -- where: + + - where: `` is the apikeyfile, and @@ -15,7 +15,6 @@ Run the script like this: `` are any parameters required by the command ## Command: balance - This command gets the balance of all of your subaccounts or a specific subaccount. - Parameters: None required. May optionally specify a single subaccount to only display the balance for that subaccount. - Syntax: @@ -29,40 +28,40 @@ This command gets the balance of all of your subaccounts or a specific subaccoun `python3 v4dydxcli.py testnet.py balance 0` - Screenshot: - -![CLIPython1](../../artifacts/CLIPython1.png) -## Command: buyquantity +![CLIPythonScript1](../../artifacts/CLIPythonScript1.png) +## Command: buyquantity This command buys a specific amount of crypto using MARKET order. - Parameters: Must specify the market and amount. - Syntax: `python3 v4dydxcli.py buyquantity ` + - Example: `python3 v4dydxcli.py testnet.py buyquantity BTC-USD 0.001` - Screenshot: -![CLIPython2](../../artifacts/CLIPython2.png) +![CLIPythonScript2](../../artifacts/CLIPythonScript2.png) ## Command: sellquantity - This command sells a specific amount of crypto using MARKET order. - Parameters: Must specify the market and amount. - Syntax: `python3 v4dydxcli.py sellquantity ` + - Example: `python3 v4dydxcli.py testnet.py sellquantity ETH-USD 0.01` + - Screenshot: -![CLIPython3](../../artifacts/CLIPython3.png) +![CLIPythonScript3](../../artifacts/CLIPythonScript3.png) ## Command: buyusdc - This command buys a specific USD-amount of crypto using MARKET order. - Parameters: Must specify the market and USD-amount. - Syntax: @@ -71,13 +70,13 @@ This command buys a specific USD-amount of crypto using MARKET order. - Example: -` python3 v4dydxcli.py testnet.py buyusdc SOL-USD 200` +`python3 v4dydxcli.py testnet.py buyusdc SOL-USD 200` + - Screenshot: -![CLIPython4](../../artifacts/CLIPython4.png) +![CLIPythonScript4](../../artifacts/CLIPythonScript4.png) ## Command: sellusdc - This command sells a specific USD-amount of crypto using MARKET order. - Parameters: Must specify the market and USD-amount. - Syntax: @@ -87,12 +86,12 @@ This command sells a specific USD-amount of crypto using MARKET order. - Example: `python3 v4dydxcli.py testnet.py sellusdc LINK-USD 200` + - Screenshot: -![CLIPython5](../../artifacts/CLIPython5.png) +![CLIPythonScript5](../../artifacts/CLIPythonScript5.png) ## Command: positions - This command shows open positions. If no open positions, it returns nothing. If you have been following the examples so far, we have opened 4 positions and this is displayed below. - Parameters: None. - Syntax: @@ -102,63 +101,70 @@ This command shows open positions. If no open positions, it returns nothing. I - Example: `python3 v4dydxcli.py testnet.py positions` + - Screenshot: -![CLIPython6](../../artifacts/CLIPython6.png) +![CLIPythonScript6](../../artifacts/CLIPythonScript6.png) ## Command: buyquantitylimit - This command buys a specific amount of crypto using LIMIT order. - Parameters: Must specify the market, quantity, limit-price, and expiration (in seconds). - Syntax: `python3 v4dydxcli.py buyquantitylimit ` + - Example: `python3 v4dydxcli.py testnet.py buyquantitylimit BTC-USD 0.002 30000 3600` + - Screenshot: -![CLIPython7](../../artifacts/CLIPython7.png) +![CLIPythonScript7](../../artifacts/CLIPythonScript7.png) ## Command: sellquantitylimit - This command sells a specific amount of crypto using LIMIT order. - Parameters: Must specify the market, quantity, limit-price, and expiration (in seconds). + - Syntax: `python3 v4dydxcli.py sellquantitylimit ` + - Example: `python3 v4dydxcli.py testnet.py sellquantitylimit ETH-USD 0.02 4000 3600` + - Screenshot: -![CLIPython8](../../artifacts/CLIPython8.png) +![CLIPythonScript8](../../artifacts/CLIPythonScript8.png) ## Command: getorder - -This command gets the data on an order with a specific client-id. Alternatively, you can specify a status to find all orders with that status. +This command gets the data on an order with a specific client-id. Alternatively, you can specify a status to find all orders with that status. - Parameters: Must specify the client-id or a status. + - Syntax: `python3 v4dydxcli.py getorder ` + - Example: -`python3 v4dydxcli.py testnet.py getorder 525086946` +`python3 v4dydxcli.py testnet.py getorder 525086946 + - Screenshot: -![CLIPython9](../../artifacts/CLIPython9.png) +![CLIPythonScript9](../../artifacts/CLIPythonScript9.png) -- Example: +- Example `python3 v4dydxcli.py testnet.py getorder OPEN` + - Screenshot: -![CLIPython10](../../artifacts/CLIPython10.png) +![CLIPythonScript10](../../artifacts/CLIPythonScript10.png) ## Command: getorderid - This command gets the data on an order with a specific order-id. - Parameters: Must specify the order-id. + - Syntax: `python3 v4dydxcli.py getorderid ` @@ -166,28 +172,30 @@ This command gets the data on an order with a specific order-id. - Example: `python3 v4dydxcli.py testnet.py getorderid e7474df1-669c-5c06-a331-889d91b0306b` + - Screenshot: -![CLIPython11](../../artifacts/CLIPython11.png) +![CLIPythonScript11](../../artifacts/CLIPythonScript11.png) ## Command: cancelorder - This command cancels an order with a specific client-id. Alternatively, you can specify a status to cancel all orders with that status. - Parameters: Must specify the client-id or a status. - Syntax: `python3 v4dydxcli.py cancelorder ` + - Example: `python3 v4dydxcli.py testnet.py cancelorder 314604016` + - Screenshot: -![CLIPython12](../../artifacts/CLIPython12.png) +![CLIPythonScript12](../../artifacts/CLIPythonScript12.png) - Example: -`python3 v4dydxcli.py testnet.py cancelorder OPEN` - - Screenshot: -![CLIPython13](../../artifacts/CLIPython3.png) +`python3 v4dydxcli.py testnet.py cancelorder OPEN` + +![CLIPythonScript13](../../artifacts/CLIPythonScript13.png)