Trading Data
This section guides you on how to fetch some important data points. We focus here on getting data using spontaneous (single) requests. For continuous data streams of data see also the WebSockets guide.
List Positions
Assets are used to trade and manage (perpetual) positions opened and closed by issuing orders. See the example below on how to check your perpetual positions.
from dydx_v4_client.indexer.rest.constants import PositionStatus
# Fetch all subaccount '0' positions.
perpetual_positions_response = await indexer
.account
.get_subaccount_perpetual_positions(ADDRESS, 0)
# Fetch only open positions.
perpetual_positions_response = await indexer
.account
.get_subaccount_perpetual_positions(address, 0, PositionStatus.OPEN)
See the API reference for the complete method definition.
Market List
A market (sometimes referred by the ticker name, e.g., ETH-USD
) is associated with a perpetual and it is the place where trading happens.
To fetch the available markets see the code below.
response = await indexer.markets.get_perpetual_markets()
print(response["markets"])
See the API reference for the complete method definition.
List Orders
Retrieve orders for a specific subaccount, with various filtering options to narrow down the results based on order characteristics.
orders_response = indexer.account.get_subaccount_orders(address, 0)
See the API reference the complete method definition.
Get Fills
Retrieve order fill records for a specific subaccount on the exchange. Fills are matched orders.
fills_response = indexer.account.get_subaccount_fills(address, 0)
See the API reference the complete method definition.
Price History
Price history in the classic candlestick can also be fetched. Data will be organized into a open, high, low, and close (OHLC) prices for some period.
from dydx_v4_client.indexer.candles_resolution import CandlesResolution
response = await indexer.markets.get_perpetual_market_candles(
market="BTC-USD", resolution=CandlesResolution.ONE_MINUTE
)
print(response["candles"])
See the API reference for the complete method definition.
Get User Fee Tier
The Get User Fee Tier function retrieves the perpetual fee tier associated with a specific wallet address, providing information on the user's current fee structure.
user_fee_tier = await node.get_user_fee_tier(ADDRESS)
See the API reference for the complete method definition.
Get Rewards Params
The Get Rewards Params function retrieves the parameters for the rewards system, providing insight into the set configurations for earning and distributing rewards.
rewards_params = await node.get_rewards_params()
See the API reference for the complete method definition.
Trading Rewards
Retrieve historical block trading rewards for the specified address.
response = await indexer.account.get_historical_block_trading_rewards(test_address, limit)
See the API reference for the complete method definition.
Get Latest Block Height
Retrieve the most recent block's height. This can serve to see if the blockchain node you are connected to is in sync.
height = await node.latest_block_height()
See the API reference for the complete method definition.