Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two docs that Lawrence made :) #289

Merged
merged 27 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0f5e62d
Create Doc 1 for Lawrence
TommyGarch Dec 12, 2024
e58a4d8
Update API_Trading_with_Classic_v4_Python_Client.json
TommyGarch Dec 12, 2024
66ff509
Update _meta.json
TommyGarch Dec 12, 2024
1a43ae8
Rename API_Trading_with_Classic_v4_Python_Client.json to API_Trading_…
TommyGarch Dec 12, 2024
8fc9c2e
Add files via upload
TommyGarch Dec 12, 2024
a298b6c
Update API_Trading_with_Classic_v4_Python_Client.mdx
TommyGarch Dec 12, 2024
3597c27
Update API_Trading_with_Classic_v4_Python_Client.mdx
TommyGarch Dec 12, 2024
e342b43
Update _meta.json
TommyGarch Dec 12, 2024
d022481
Create CLI_Python_Script.mdx
TommyGarch Dec 12, 2024
d1e5c88
Update API_Trading_with_Classic_v4_Python_Client.mdx
TommyGarch Dec 12, 2024
3901b1c
Update CLI_Python_Script.mdx
TommyGarch Dec 12, 2024
90b1910
Add files via upload
TommyGarch Dec 12, 2024
6ef1d85
Update CLI_Python_Script.mdx
TommyGarch Dec 12, 2024
b78cee1
Update CLI_Python_Script.mdx
TommyGarch Dec 12, 2024
f9a7314
Update API_Trading_with_Classic_v4_Python_Client.mdx
TommyGarch Dec 13, 2024
6723c04
Rename API_Trading_with_Classic_v4_Python_Client.mdx to api_trading_w…
TommyGarch Dec 16, 2024
b2727bc
Update _meta.json
TommyGarch Dec 16, 2024
5172d9b
Update cli_python_script.md
TommyGarch Dec 16, 2024
9ec45df
Update _meta.json
TommyGarch Dec 16, 2024
54432cb
Delete pages/api_integration-guides/cli_python_script.md
TommyGarch Dec 16, 2024
e00a1a2
Rename CLI_Python_Script.mdx to cli_python_Script.md
TommyGarch Dec 16, 2024
1a0fca5
Update _meta.json
TommyGarch Dec 16, 2024
b4d294b
Rename api_trading_with_classic_v4_python_client.mdx to api_trading_w…
TommyGarch Dec 16, 2024
6a6e363
Rename cli_python_Script.md to cli_python_script.md
TommyGarch Dec 16, 2024
e06c7e3
Update cli_python_script.md
TommyGarch Dec 16, 2024
fefe3ad
Update cli_python_script.md
TommyGarch Dec 16, 2024
3623ce3
Rename cli_python_script.md to cli_python_script.mdx
TommyGarch Dec 16, 2024
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
Binary file added artifacts/APITradingClassicPic1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/APITradingClassicPic2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/APITradingClassicPic3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/APITradingClassicPic4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added artifacts/CLIPythonScript9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion pages/api_integration-guides/_meta.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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 = '<your 24 word dydx seed on testnet-4>’
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# CLI Python Script

## Command syntax

## Command: syntax
Run the script like this:
- Syntax:
- Syntax

`python3 v4dydxcli.py <apikeyfile> <command> <parameters>`
- where:

- where:

`<apikeyfile>` is the apikeyfile, and

Expand All @@ -15,7 +15,6 @@ Run the script like this:
`<parameters>` 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:
Expand All @@ -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 <apikeyfile> buyquantity <market> <quantity>`

- 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 <apikeyfile> sellquantity <market> <quantity>`

- 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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -102,92 +101,101 @@ 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 <apikeyfile> buyquantitylimit <market> <quantity> <limitprice> <expiration>`

- 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 <apikeyfile> sellquantitylimit <market> <quantity> <limitprice> <expiration>`

- 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 <apikeyfile> getorder <clientid or status>`

- 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 <apikeyfile> getorderid <orderid>`

- 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 <apikeyfile> cancelorder <client-id or status>`

- 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)
Loading