### Run an example Source: https://docs.dydx.xyz/interaction/client/quick-start-rs Execute the account_endpoint example using Cargo. ```bash cargo run --example account_endpoint ``` -------------------------------- ### Run an example file Source: https://docs.dydx.xyz/interaction/client/quick-start-ts Execute the account endpoints example script. ```bash node ../build/examples/account_endpoints.js ``` -------------------------------- ### Install dependencies and build Source: https://docs.dydx.xyz/interaction/client/quick-start-ts Install project dependencies and build the library. ```bash npm install npm run build ``` -------------------------------- ### Run an example script Source: https://docs.dydx.xyz/interaction/client/quick-start-py Execute the account endpoints example using the Poetry environment. ```bash poetry run python -m examples.account_endpoints ``` -------------------------------- ### Install Cosmovisor Source: https://docs.dydx.xyz/nodes/upgrades/using-cosmovisor Install the latest version of Cosmovisor using the Go toolchain. ```bash go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest ``` -------------------------------- ### Install Go Source: https://docs.dydx.xyz/nodes/running-node/setup Commands to download, extract, and clean up the Go installation package for AMD64 architecture. ```bash # Example for AMD64 architecture and Go version 1.22.2 wget https://golang.org/dl/go1.22.2.linux-amd64.tar.gz # Download the compressed file sudo tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz # Extract the file to /usr/local rm go1.22.2.linux-amd64.tar.gz # Delete the installer package ``` -------------------------------- ### Install project dependencies Source: https://docs.dydx.xyz/interaction/client/quick-start-py Use Poetry to install all required dependencies for the Python client. ```bash poetry install ``` -------------------------------- ### Install the npm package Source: https://docs.dydx.xyz/interaction/client/quick-start-ts Install the dYdX v4-client-js package via npm. ```bash npm i @dydxprotocol/v4-client-js ``` -------------------------------- ### Start Node via Systemd Source: https://docs.dydx.xyz/nodes/running-node/optimize Command to start the dYdX protocol daemon as a system service. ```bash stystemctl start dydxprotocold ``` -------------------------------- ### Install via PyPI Source: https://docs.dydx.xyz/interaction/client/quick-start-py Install the dYdX Python client package directly from PyPI using pip. ```bash pip install dydx-v4-client ``` -------------------------------- ### Start Node with Cosmovisor or Binary Source: https://docs.dydx.xyz/nodes/running-node/optimize Commands to start the node with the non-validating flag enabled. ```bash cosmovisor run start --non-validating-full-node=true ``` ```bash dydxprotocold run start --non-validating-full-node=true ``` -------------------------------- ### Run Automated Setup Script Source: https://docs.dydx.xyz/nodes/running-node/setup Commands to execute the dYdX automated node setup script after saving it to the home directory. ```bash cd $HOME bash create_full_node.sh ``` -------------------------------- ### Install Cosmovisor from source Source: https://docs.dydx.xyz/nodes/upgrades/cosmovisor Builds the Cosmovisor binary from the cosmos-sdk repository. ```bash git clone https://github.com/cosmos/cosmos-sdk.git cd cosmos-sdk git checkout cosmovisor/vx.x.x make cosmovisor ``` -------------------------------- ### Install and use Node.js version Source: https://docs.dydx.xyz/interaction/client/quick-start-ts Set up the required Node.js version using nvm. ```bash nvm install nvm use ``` -------------------------------- ### Update System and Install Dependencies Source: https://docs.dydx.xyz/nodes/running-node/setup Commands to update the package list and install necessary utilities including curl, jq, and lz4. ```bash sudo apt-get -y update sudo apt-get install -y curl jq lz4 ``` -------------------------------- ### Configure Persistent Peers Source: https://docs.dydx.xyz/nodes/running-node/optimize Example configuration for the persistent_peers field in config.toml. ```toml # config.toml # Example values from Polkachu for dydx-mainnet-1 persistent_peers=83c299de2052db247f08422b6592e1383dd7a104@136.243.36.60:23856,[[email protected]]:26656,[[email protected]]:26656,[[email protected]]:23856,[[email protected]]:26656 ``` -------------------------------- ### Install the dYdX crate Source: https://docs.dydx.xyz/interaction/client/quick-start-rs Add the dYdX dependency to your project via Cargo. ```bash cargo add dydx ``` -------------------------------- ### Check Cosmovisor version Source: https://docs.dydx.xyz/nodes/upgrades/cosmovisor Verifies the installed version of the Cosmovisor tool. ```bash cosmovisor version ``` -------------------------------- ### Get All Affiliate Tiers Method Declaration Source: https://docs.dydx.xyz/node-client/public Retrieves all configured affiliate tiers. ```python async def get_all_affiliate_tiers( self, ) -> affiliate_query.AllAffiliateTiersResponse ``` -------------------------------- ### Get Prices Method Declaration Source: https://docs.dydx.xyz/node-client/public Queries all market prices from the system. ```python async def get_prices(self) -> QueryAllMarketPricesResponse ``` -------------------------------- ### Get Rewards Params Source: https://docs.dydx.xyz/interaction/data/market Retrieves the configuration parameters for the rewards system. ```python rewards_params = await node.get_rewards_params() ``` -------------------------------- ### Get Affiliate White List Method Declaration Source: https://docs.dydx.xyz/node-client/public Retrieves the current affiliate whitelist. ```python async def get_affiliate_whitelist( self, ) -> affiliate_query.AffiliateWhitelistResponse ``` -------------------------------- ### GET /v4/time Source: https://docs.dydx.xyz/indexer-client/http Get current server time of the Indexer. ```APIDOC ## GET /v4/time ### Description Get current server time of the Indexer. ### Method GET ### Endpoint /v4/time ### Response #### Success Response (200) - **TimeResponse** (object) - The current server time. ``` -------------------------------- ### Initialize Cosmovisor Source: https://docs.dydx.xyz/nodes/upgrades/using-cosmovisor Initialize the Cosmovisor directory structure with the path to the current binary. ```bash cosmovisor init ``` -------------------------------- ### Initialize Account Client Source: https://docs.dydx.xyz/indexer-client/http Initializes the account client instance. ```python account = indexer_client.account() ``` -------------------------------- ### Prepare Binary for Cosmovisor Source: https://docs.dydx.xyz/nodes/upgrades/performing-upgrades Rename and set permissions for the new binary before moving it to the appropriate upgrade directory. ```bash mv dydxprotocold.- dydxprotocold ``` ```bash chmod 755 dydxprotocold ``` ```bash mkdir -p $DAEMON_HOME/cosmovisor/upgrades//bin ``` ```bash mv $DAEMON_HOME/cosmovisor/upgrades//bin ``` -------------------------------- ### Create Cosmovisor Directories Source: https://docs.dydx.xyz/nodes/running-node/setup Sets up the required directory structure for Cosmovisor within the home directory. ```bash mkdir -p $HOME/.dydxprotocol/cosmovisor/genesis/bin mkdir -p $HOME/.dydxprotocol/cosmovisor/upgrades ``` -------------------------------- ### Configure Binary and Path Source: https://docs.dydx.xyz/nodes/running-node/setup Extracts the binary, moves it to the Cosmovisor genesis directory, and adds it to the system PATH. ```bash # Example for AMD64 architecture sudo tar -xzvf dydxprotocold-v5.0.5-linux-amd64.tar.gz # Extract the file sudo mv ./build/dydxprotocold-v5.0.5-linux-amd64 ./.dydxprotocol/cosmovisor/genesis/bin/dydxprotocold # Move the file to /.dydxprotocol and rename it rm dydxprotocold-v5.0.5-linux-amd64.tar.gz # Delete the installer package rm -rf build # Delete the now-empty /build directory ``` ```bash echo 'export PATH=$PATH:$HOME/.dydxprotocol/cosmovisor/genesis/bin' >> $HOME/.bashrc # Write to your .bashrc profile ``` -------------------------------- ### Initialize Faucet Client Source: https://docs.dydx.xyz/interaction/endpoints Request test funds for trading strategies on the testnet. ```python from dydx_v4_client.network import TESTNET_FAUCET from dydx_v4_client.faucet_client import FaucetClient faucet = FaucetClient(TESTNET_FAUCET) ``` -------------------------------- ### get_all_affiliate_tiers Source: https://docs.dydx.xyz/node-client/public Get all affiliate tiers. ```APIDOC ## GET /dydxprotocol/affiliates/all_affiliate_tiers ### Description Get all affiliate tiers. ### Method GET ### Endpoint /dydxprotocol/affiliates/all_affiliate_tiers ### Response #### Success Response (200) - **AllAffiliateTiersResponse** (Object) - The response containing all affiliate tiers. ``` -------------------------------- ### Initialize Indexer Client Source: https://docs.dydx.xyz/interaction/endpoints Setup the Indexer client using REST and WebSocket endpoints for data retrieval and trading feeds. ```python from dydx_v4_client.network import make_mainnet from dydx_v4_client.indexer.rest.indexer_client import IndexerClient from dydx_v4_client.indexer.socket.websocket import IndexerSocket config = make_mainnet( node_url="your-custom-grpc-node.com", rest_indexer="https://your-custom-rest-indexer.com", websocket_indexer="wss://your-custom-websocket-indexer.com" ).node # Instantiate the HTTP sub-client. indexer = IndexerClient(config.rest_indexer) # Instatiate the WebSockets sub-client, connecting to the network. socket = await IndexerSocket(network.websocket_indexer).connect() ``` -------------------------------- ### get_affiliate_whitelist Source: https://docs.dydx.xyz/node-client/public Get affiliate white list. ```APIDOC ## GET /dydxprotocol/affiliates/affiliate_whitelist ### Description Get affiliate white list. ### Method GET ### Endpoint /dydxprotocol/affiliates/affiliate_whitelist ### Response #### Success Response (200) - **AffiliateWhitelistResponse** (Object) - The affiliate whitelist response. ``` -------------------------------- ### Setup Permissioned Wallet Source: https://docs.dydx.xyz/interaction/permissioned-keys Initialize a permissioned wallet using a private key and configure the subaccount for trading. ```typescript const fromWallet = await LocalWallet.fromPrivateKey(DYDX_TEST_PRIVATE_KEY, BECH32_PREFIX); const authenticatedSubaccount = SubaccountInfo.forPermissionedWallet( fromWallet, address, //owner dydx address subaccountNumber, //subaccount to trade onbehalf of [authenticatorId], ) ``` -------------------------------- ### get_affiliate_info Source: https://docs.dydx.xyz/node-client/public Get affiliate info by address. ```APIDOC ## GET /dydxprotocol/affiliates/affiliate_info/{address} ### Description Get affiliate info by address. ### Method GET ### Endpoint /dydxprotocol/affiliates/affiliate_info/{address} ### Parameters #### Path Parameters - **address** (Address) - Required - Address to get affiliate info ### Response #### Success Response (200) - **AffiliateInfoResponse** (Object) - The affiliate information for the provided address. ``` -------------------------------- ### GET /v4/vault/v1/megavault/positions Source: https://docs.dydx.xyz/indexer-client/http Retrieves the current positions for the MegaVault. ```APIDOC ## GET /v4/vault/v1/megavault/positions ### Description Retrieves the current positions held by the MegaVault. ### Method GET ### Endpoint /v4/vault/v1/megavault/positions ### Response #### Success Response (200) - **VaultPosition** - The vault position data. ``` -------------------------------- ### Start node with configuration Source: https://docs.dydx.xyz/nodes/upgrades/performing-upgrades Restarts the node using specific p2p seed nodes and an Ethereum RPC endpoint. ```bash ./dydxprotocold start --p2p.seeds="[seed_node_id]@[seed_node_ip_addr]:26656" --bridge-daemon-eth-rpc-endpoint="" ``` -------------------------------- ### GET /v4/vault/v1/vaults/historicalPnl Source: https://docs.dydx.xyz/indexer-client/http Retrieves the historical PnL for vaults. ```APIDOC ## GET /v4/vault/v1/vaults/historicalPnl ### Description Retrieves the historical PnL data for vaults based on the specified resolution. ### Method GET ### Endpoint /v4/vault/v1/vaults/historicalPnl ### Parameters #### Query Parameters - **resolution** (PnlTickInterval) - Required - PnL tick resolution. ### Response #### Success Response (200) - **VaultHistoricalPnl** - The vault historical PnL data. ``` -------------------------------- ### GET /v4/vault/v1/megavault/historicalPnl Source: https://docs.dydx.xyz/indexer-client/http Retrieves the historical PnL for the MegaVault. ```APIDOC ## GET /v4/vault/v1/megavault/historicalPnl ### Description Retrieves the historical PnL data for the MegaVault based on the specified resolution. ### Method GET ### Endpoint /v4/vault/v1/megavault/historicalPnl ### Parameters #### Query Parameters - **resolution** (PnlTickInterval) - Required - PnL tick resolution. ### Response #### Success Response (200) - **PnlTicksResponseObject** - The PnL ticks data. ``` -------------------------------- ### GET /perpetualPositions/parentSubaccountNumber Source: https://docs.dydx.xyz/indexer-client/http List all positions of a parent subaccount. ```APIDOC ## GET /perpetualPositions/parentSubaccountNumber ### Description List all positions of a parent subaccount. ### Method GET ### Endpoint /perpetualPositions/parentSubaccountNumber ### Parameters #### Query Parameters - **address** (Address) - Required - The wallet address that owns the account. - **parentSubaccountNumber** (SubaccountNumber) - Required - Subaccount number of the parent subaccount. - **limit** (u32) - Optional - Maximum number of asset positions to return in the response. ### Response #### Success Response (200) - **PerpetualPositionResponseObject** (Object) - The perpetual positions data. ``` -------------------------------- ### GET /dydxprotocol/subaccounts/subaccount Source: https://docs.dydx.xyz/node-client/public Retrieves a comprehensive list of all subaccounts. ```APIDOC ## GET /dydxprotocol/subaccounts/subaccount ### Description Retrieves a comprehensive list of all subaccounts, returning structured information encapsulated in a response object. ### Method GET ### Endpoint /dydxprotocol/subaccounts/subaccount ### Response #### Success Response (200) - **SubaccountInfo** (Object) - The response containing subaccount information. ``` -------------------------------- ### Create the Wallet Source: https://docs.dydx.xyz/interaction/wallet-setup Initializes a Wallet instance using the mnemonic and address to enable transaction signing. ```python from dydx_v4_client.key_pair import KeyPair from dydx_v4_client.wallet import Wallet # Define your address. address = Wallet(KeyPair.from_mnemonic(mnemonic), 0, 0).address() # Create a Wallet with updated parameters required for trading wallet = await Wallet.from_mnemonic(node, mnemonic, address) ``` -------------------------------- ### Get Node Information Source: https://docs.dydx.xyz/node-client/public Queries general information about the node. ```python async def get_node_info(self) -> tendermint_query.GetNodeInfoResponse ``` -------------------------------- ### GET /v4/screen Source: https://docs.dydx.xyz/indexer-client/http Query for screening results (compliance) of the address. ```APIDOC ## GET /v4/screen ### Description Query for screening results (compliance) of the address. ### Method GET ### Endpoint /v4/screen ### Parameters #### Query Parameters - **address** (Address) - Required - The wallet address that owns the account. ### Response #### Success Response (200) - **ComplianceResponse** (object) - The compliance data. #### Error Response (400) - The request was malformed or invalid. ``` -------------------------------- ### Initialize Node Client in Python Source: https://docs.dydx.xyz/interaction/endpoints Configures and connects the NodeClient using OEGS endpoints. Use make_testnet() for testing environments. ```python from dydx_v4_client.network import make_mainnet from dydx_v4_client.node.client import NodeClient config = make_mainnet( node_url="oegs.dydx.trade:443" rest_indexer="https://indexer.dydx.trade", websocket_indexer="wss://indexer.dydx.trade/v4/ws", ).node # Call make_testnet() to use the testnet instead. # Connect to the network. node = await NodeClient.connect(config) ``` -------------------------------- ### GET /v4/sparklines Source: https://docs.dydx.xyz/indexer-client/http Retrieves sparkline data for perpetual markets. ```APIDOC ## GET /v4/sparklines ### Description Retrieves sparkline data for perpetual markets. ### Method GET ### Endpoint /v4/sparklines ### Parameters #### Query Parameters - **timePeriod** (SparklineTimePeriod) - Required - The time period for the sparkline data (e.g., "ONE_DAY", "SEVEN_DAYS"). ### Response #### Success Response (200) - **SparklineResponseObject** (object) - The sparkline data. #### Error Response (400) - The request was malformed or invalid. ``` -------------------------------- ### Configure mainnet.toml Source: https://docs.dydx.xyz/interaction/client/quick-start-rs Configuration file for connecting to the dYdX mainnet. ```toml [node] endpoint = "https://dydx-ops-grpc.kingnodes.com:443" chain_id = "dydx-mainnet-1" fee_denom = "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5" [indexer] http.endpoint = "https://indexer.dydx.trade" ws.endpoint = "wss://indexer.dydx.trade/v4/ws" [noble] # optional endpoint = "http://noble-grpc.polkachu.com:21590" chain_id = "noble-1" fee_denom = "uusdc" ``` -------------------------------- ### Get Compliance Screen Source: https://docs.dydx.xyz/indexer-client/http Screens an address to determine if it is restricted. ```python async def compliance_screen(self, address: str) -> Any ``` -------------------------------- ### Get Subaccounts Method Declaration Source: https://docs.dydx.xyz/node-client/public Retrieves a list of all subaccounts. ```python async def get_subaccounts(self) -> QuerySubaccountAllResponse ``` -------------------------------- ### Configure Oracle in app.toml Source: https://docs.dydx.xyz/nodes/running-node/required-node-configs Set up the connection to the out-of-process oracle sidecar and define price feed parameters. ```toml # ... other sections [oracle] # Enabled indicates whether the oracle is enabled. enabled = "true" # Oracle Address is the URL of the out of process oracle sidecar. This is used to # connect to the oracle sidecar when the application boots up. oracle_address = "SLINKY_ADDRESS_HERE:SLINKY_PORT_HERE" # default Slinky port is 8080. # Client Timeout is the time that the application is willing to wait for responses from # the oracle before timing out. client_timeout = "250ms" # MetricsEnabled determines whether oracle metrics are enabled. Specifically, # this enables instrumentation of the oracle client and the interaction between # the oracle and the app. metrics_enabled = "true" # PriceTTL is the maximum age of the latest price response before it is considered stale. # The recommended max age is 10 seconds (10s). If this is greater than 1 minute (1m), the app # will not start. price_ttl = "10s" # Interval is the time between each price update request. The recommended interval # is the block time of the chain. Otherwise, 0.6 seconds (600ms) is a good default. If this # is greater than 1 minute (1m), the app will not start. interval = "600ms" ``` -------------------------------- ### Subscribe to the Orders channel in Python Source: https://docs.dydx.xyz/interaction/data/watch-orderbook Demonstrates how to initiate a subscription to the orders channel for a specific market upon connection. ```python def handler(ws: IndexerSocket, message: dict): if message["type"] == "connected": # Subscribe. ws.orders.subscribe(ETH_USD) print(message) ``` -------------------------------- ### Get Transfers Source: https://docs.dydx.xyz/indexer-client/http Retrieves the transfer history for a specific subaccount. ```APIDOC ## GET /v4/transfers ### Description Retrieves the transfer history for a specific subaccount. ### Method GET ### Endpoint /v4/transfers ### Parameters #### Query Parameters - **address** (Address) - Required - The wallet address that owns the account. - **subaccountNumber** (SubaccountNumber) - Required - The identifier for the specific subaccount within the wallet address. - **limit** (u32) - Optional - Maximum number of items in the response. - **createdBeforeOrAtHeight** (Height) - Optional - Restricts results to positions created at or before a specific blockchain height. - **createdBeforeOrAt** (DateTime) - Optional - Restricts results to positions created at or before a specific timestamp. - **page** (u32) - Optional - The page number for paginated results. ### Response #### Success Response (200) - **TransferResponseObject** (Object) - The transfers data. ``` -------------------------------- ### Add Cosmovisor to PATH Source: https://docs.dydx.xyz/nodes/upgrades/cosmovisor Moves the built binary to the user's local bin directory. ```bash cp cosmovisor/cosmovisor ~/go/bin/cosmovisor ``` -------------------------------- ### Get Referred By Source: https://docs.dydx.xyz/node-client/public Retrieves the referral information associated with a specific address. ```python async def get_referred_by(self, address: str) -> affiliate_query.ReferredByResponse ``` -------------------------------- ### Run Binary with Cosmovisor Source: https://docs.dydx.xyz/nodes/upgrades/using-cosmovisor Replace the standard binary execution command with the Cosmovisor run command. ```bash cosmovisor run start --p2p.seeds="ade4d8…" ``` -------------------------------- ### Get Server Time Source: https://docs.dydx.xyz/indexer-client/http Retrieves the current server time from the Indexer. ```python async def get_time(self) -> Dict[str, str] ``` -------------------------------- ### Initialize Noble Client Source: https://docs.dydx.xyz/interaction/endpoints Connect to the Noble network to facilitate asset transfers in and out of the dYdX network. ```python from dydx_v4_client.indexer.rest.noble_client import NobleClient client = NobleClient("https://rpc.testnet.noble.strange.love") await client.connect(MNEMONIC) ``` -------------------------------- ### Change to Home Directory Source: https://docs.dydx.xyz/nodes/running-node/setup Navigate to the dYdX protocol home directory. ```bash cd $HOME/.dydxprotocol ``` -------------------------------- ### GET /v4/orderbooks/perpetualMarket/{market} Source: https://docs.dydx.xyz/indexer-client/http Retrieves the orderbook for a specific perpetual market. ```APIDOC ## GET /v4/orderbooks/perpetualMarket/{market} ### Description Retrieves the orderbook for a specific perpetual market. ### Method GET ### Endpoint /v4/orderbooks/perpetualMarket/{market} ### Parameters #### Path Parameters - **market** (Ticker) - Required - The market ticker. ### Response #### Success Response (200) - **OrderBookResponseObject** - The orderbook data. #### Error Response (400) - The request was malformed or invalid. #### Error Response (404) - The market was not found. ``` -------------------------------- ### Place Market Order and Verify Fills Source: https://docs.dydx.xyz/interaction/integration/integration-builder-codes Demonstrates connecting to the dYdX testnet, constructing a market order, executing the transaction, and querying the indexer for order fills. ```python import asyncio import random from dydx_v4_client import MAX_CLIENT_ID, OrderFlags from v4_proto.dydxprotocol.clob.order_pb2 import Order 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.client import NodeClient from dydx_v4_client.node.market import Market from dydx_v4_client.wallet import Wallet from tests.conftest import DYDX_TEST_MNEMONIC, TEST_ADDRESS MARKET_ID = "ETH-USD" 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) order_id = market.order_id( TEST_ADDRESS, 0, random.randint(0, MAX_CLIENT_ID), OrderFlags.SHORT_TERM ) current_block = await node.latest_block_height() new_order = market.order( order_id=order_id, order_type=OrderType.MARKET, side=Order.Side.SIDE_SELL, size=size, price=0, # Recommend set to oracle price - 5% or lower for SELL, oracle price + 5% for BUY time_in_force=Order.TimeInForce.TIME_IN_FORCE_UNSPECIFIED, reduce_only=False, good_til_block=current_block + 10, builder_address=TEST_ADDRESS, fee_ppm=500, ) transaction = await node.place_order( wallet=wallet, order=new_order, ) print(transaction) wallet.sequence += 1 await asyncio.sleep(5) fills = await indexer.account.get_subaccount_fills( address=TEST_ADDRESS, subaccount_number=0, ticker=MARKET_ID, limit=1 ) print(f"Fills: {fills}") assert fills["fills"][0]["builderAddress"] == TEST_ADDRESS ``` -------------------------------- ### Connect to dYdX WebSocket via CLI Source: https://docs.dydx.xyz/interaction/data/feeds Use a command-line WebSocket client to connect to the dYdX indexer and subscribe to specific market channels. ```bash # For the deployment by DYDX token holders (mainnet), use # wscli connect wss://indexer.dydx.trade/v4/ws wscli connect wss://indexer.v4testnet.dydx.exchange/v4/ws { "type": "subscribe", "channel": "v4_trades", "id": "BTC-USD" } ``` -------------------------------- ### GET /v4/transfers/parentSubaccountNumber Source: https://docs.dydx.xyz/indexer-client/http Query for transfers between subaccounts associated with a parent subaccount. ```APIDOC ## GET /v4/transfers/parentSubaccountNumber ### Description Query for transfers between subaccounts associated with a parent subaccount. ### Method GET ### Endpoint /v4/transfers/parentSubaccountNumber ### Parameters #### Query Parameters - **address** (Address) - Required - The wallet address that owns the parent subaccount. - **parentSubaccountNumber** (SubaccountNumber) - Required - The identifier for the specific subaccount within the wallet address. - **limit** (u32) - Optional - Maximum number of asset positions to return in the response. - **createdBeforeOrAtHeight** (Height) - Optional - Restricts results to positions created at or before a specific blockchain height. - **createdBeforeOrAt** (DateTime) - Optional - Restricts results to positions created at or before a specific timestamp (ISO 8601 format). ### Response #### Success Response (200) - **TransferResponseObject** (Object) - The transfer data. ``` -------------------------------- ### Navigate to Rust client directory Source: https://docs.dydx.xyz/interaction/client/quick-start-rs Change the working directory to the Rust client library folder. ```bash cd v4-clients/v4-client-rs ``` -------------------------------- ### GET /v4/fills Source: https://docs.dydx.xyz/indexer-client/http Retrieves fill records for a specific subaccount on the exchange. ```APIDOC ## GET /v4/fills ### Description Retrieves fill records for a specific subaccount on the exchange. A fill represents a trade that has been executed. ### Method GET ### Endpoint /v4/fills ### Parameters #### Query Parameters - **address** (Address) - Required - The wallet address that owns the account. - **subaccountNumber** (SubaccountNumber) - Required - The identifier for the specific subaccount within the wallet address. - **market** (Ticker) - Optional - The market symbol to filter fills by (e.g., "BTC-USD"). - **marketType** (MarketType) - Optional - The type of market to filter by. - **limit** (u32) - Optional - Maximum number of asset positions to return in the response. - **createdBeforeOrAtHeight** (Height) - Optional - Filters results to positions created at or before a specific blockchain height. - **createdBeforeOrAt** (DateTime) - Optional - Filters results to positions created at or before a specific timestamp (ISO 8601 format). - **page** (u32) - Optional - The page number for paginated results. ### Response #### Success Response (200) - **FillResponseObject** (Object) - The fills data containing details such as order ID, market, side, size, price, and execution time. ``` -------------------------------- ### Get Transfers Between Source: https://docs.dydx.xyz/indexer-client/http Fetch information regarding a transfer between two subaccounts. ```APIDOC ## GET /v4/transfers/between ### Description Fetch information regarding a transfer between two subaccounts. ### Method GET ### Endpoint /v4/transfers/between ### Parameters #### Query Parameters - **sourceAddress** (string) - Required - Sender's wallet address - **sourceSubaccountNumber** (string) - Required - The identifier for the specific subaccount within the sender wallet address. - **recipientAddress** (string) - Required - Receiver wallet address - **recipientSubaccountNumber** (string) - Required - The identifier for the specific subaccount within the receiver wallet address. - **createdBeforeOrAtHeight** (number) - Optional - Restricts results to positions created at or before a specific blockchain height. - **createdBeforeOrAt** (string) - Optional - Restricts results to positions created at or before a specific timestamp (ISO 8601 format). ``` -------------------------------- ### Place Order with Revenue Share Source: https://docs.dydx.xyz/interaction/integration/integration-revshare Demonstrates how to configure an order with an order_router_address and verify the transaction, fills, and revenue share parameters. ```python import asyncio import random import time from dydx_v4_client import MAX_CLIENT_ID, OrderFlags from dydx_v4_client.indexer.rest.constants import OrderType from dydx_v4_client.indexer.rest.indexer_client import IndexerClient from dydx_v4_client.key_pair import KeyPair from dydx_v4_client.network import TESTNET from dydx_v4_client.node.client import NodeClient from dydx_v4_client.node.market import Market from dydx_v4_client.node.message import order_id from dydx_v4_client.wallet import Wallet from tests.conftest import TEST_ADDRESS_2, TEST_ADDRESS, DYDX_TEST_MNEMONIC from v4_proto.dydxprotocol.clob.order_pb2 import Order node = await NodeClient.connect(TESTNET.node) indexer = IndexerClient(TESTNET.rest_indexer) MARKET_ID = "ETH-USD" market = Market( (await indexer.markets.get_perpetual_markets(MARKET_ID))["markets"][ MARKET_ID ] ) wallet = await Wallet.from_mnemonic(node, DYDX_TEST_MNEMONIC, TEST_ADDRESS) order_id = market.order_id( TEST_ADDRESS, 0, random.randint(0, MAX_CLIENT_ID), OrderFlags.SHORT_TERM ) current_block = await node.latest_block_height() new_order = market.order( order_id=order_id, order_type=OrderType.MARKET, side=Order.Side.SIDE_SELL, size=0.0001, price=0, # Recommend set to oracle price - 5% or lower for SELL, oracle price + 5% for BUY time_in_force=Order.TimeInForce.TIME_IN_FORCE_UNSPECIFIED, reduce_only=False, good_til_block=current_block + 10, order_router_address=TEST_ADDRESS_2, ) transaction = await node.place_order( wallet=wallet, order=new_order, ) print(transaction) await asyncio.sleep(5) fills = await indexer.account.get_subaccount_fills( address=TEST_ADDRESS, subaccount_number=0, limit=1 ) print(f"Fills: {fills}") response = await node.get_market_mapper_revenue_share_param() print(response) response = await node.get_order_router_revenue_share(TEST_ADDRESS_2) print(response) ``` -------------------------------- ### Navigate to the Python client directory Source: https://docs.dydx.xyz/interaction/client/quick-start-py Change the working directory to the Python client library folder. ```bash cd v4-clients/v4-client-py-v2 ``` -------------------------------- ### Start Slinky Command Source: https://docs.dydx.xyz/nodes/running-node/running-a-validator Command to launch the Slinky process using the specified configuration file. ```bash connect \ --marketmap-provider dydx_migration_api \ --oracle-config path/to/oracle.json ``` -------------------------------- ### Get account balances Source: https://docs.dydx.xyz/interaction/data/accounts Retrieves the balances for all assets held by an account. ```python response = await node.get_account_balances(ADDRESS) ``` -------------------------------- ### Get Withdrawal Capacity By Denom Source: https://docs.dydx.xyz/node-client/public Retrieves the withdrawal capacity for a specific denomination. ```python async def get_withdrawal_capacity_by_denom( self, denom: str ) -> rate_query.QueryCapacityByDenomResponse ``` -------------------------------- ### Configure Gas Prices in app.toml Source: https://docs.dydx.xyz/nodes/running-node/required-node-configs Set the minimum gas prices for the node. Replace $NATIVE_TOKEN_DENOM with the appropriate network constant. ```toml ### Gas Prices ### minimum-gas-prices = "0.025ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5,12500000000$NATIVE_TOKEN_DENOM" ``` -------------------------------- ### Perpetual ID vs Market ID Example Source: https://docs.dydx.xyz/node-client/public Demonstrates the distinction between perpetual ID and market ID using the dYdX protocol CLI. ```bash dydxprotocold query perpetuals show-perpetual 145 perpetual: funding_index: "6530" open_interest: "0" params: atomic_resolution: -5 default_funding_ppm: 100 id: 145 liquidity_tier: 4 market_id: 71 market_type: PERPETUAL_MARKET_TYPE_ISOLATED ticker: LUCE-USD ``` -------------------------------- ### GET /cosmos/staking/v1beta1/validators Source: https://docs.dydx.xyz/node-client/public Fetches a list of all validators, optionally filtering them by a specified status. ```APIDOC ## GET /cosmos/staking/v1beta1/validators ### Description Fetches a list of all validators, optionally filtering them by a specified status. ### Method GET ### Endpoint /cosmos/staking/v1beta1/validators ### Parameters #### Query Parameters - **status** (string) - Optional - Status to filter out the matched result. ### Response #### Success Response (200) - **Validator** (Object) - The response containing all validators. #### Error Response (400) - The request was malformed or invalid. ``` -------------------------------- ### Configure Go Path Source: https://docs.dydx.xyz/nodes/running-node/setup Command to append the Go binary directories to the system PATH in the .bashrc profile. ```bash echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bashrc # Write to your .bashrc profile ``` -------------------------------- ### Get Latest Block Method Declaration Source: https://docs.dydx.xyz/node-client/public Retrieves the most recent block from the network. ```python async def latest_block(self) -> tendermint_query.GetLatestBlockResponse ``` -------------------------------- ### Install gRPC dependencies Source: https://docs.dydx.xyz/nodes/full-node-streaming/example Required packages for handling gRPC streams and Protocol Buffers in Python. ```bash grpcio>=1.67.0 grpcio-tools==1.64.1 protobuf==5.28.1 PyYAML==6.0.1 sortedcontainers==2.4.0 v4-proto==6.0.8 ``` -------------------------------- ### Get Subaccounts Method Source: https://docs.dydx.xyz/indexer-client/http Retrieves a list of subaccounts associated with a primary address. ```python async def get_subaccounts( self, address: str, limit: Optional[int] = None, ) -> Any ```