dYdX

Interact with dYdX v4 API

Overview

This node integrates with the dYdX v4 API to perform various trading-related operations on the dYdX platform. Specifically, the Smart Position operation allows users to adjust their position size in a given market intelligently. Instead of manually placing orders, this operation attempts to bring the current position to a target size (positive for long positions, negative for short) within a specified subaccount.

Common scenarios where this node is beneficial include:

  • Automatically managing exposure in a specific market by adjusting position sizes programmatically.
  • Implementing trading strategies that require dynamic position sizing without manual intervention.
  • Managing multiple subaccounts and markets efficiently through automation.

For example, a trader wanting to increase their BTC-USD position to 2 BTC long can use this node to set the target size to 2, and the node will handle the necessary trades to reach that position.

Properties

Name Meaning
Market Market symbol to trade on, e.g., "BTC-USD".
Target Position Size Desired size of the position: positive number for a long position, negative for short.
Subaccount ID Identifier of the subaccount where the position adjustment should be made. Defaults to 0.

Output

The output JSON object for the Smart Position operation includes:

  • success: Boolean indicating if the smart position operation was initiated successfully.
  • message: A confirmation message, e.g., "Smart position initiated".
  • market: The market symbol used in the operation.
  • targetSize: The desired target position size provided as input.
  • currentSize: The current position size after the operation (retrieved from the service).
  • timestamp: ISO string timestamp when the operation was performed.

If an error occurs and the node is configured to continue on failure, the output JSON will contain:

  • success: false
  • error: Error message describing what went wrong.
  • market and targetSize: Echoed input values for context.

Dependencies

  • Requires an API key credential for authenticating with the dYdX v4 API.
  • Uses internal trading and account services to interact with the dYdX network.
  • Network configuration and user address are obtained from credentials.
  • No additional external dependencies beyond the dYdX API and its authentication.

Troubleshooting

  • Common issues:

    • Invalid or missing API credentials will cause authentication failures.
    • Incorrect market symbols may result in errors from the dYdX API.
    • Insufficient funds or margin in the specified subaccount can prevent position adjustments.
    • Network connectivity issues to the dYdX API endpoint.
  • Error messages:

    • "Failed to execute smart position: <error message>" indicates the operation failed due to API or logic errors. Check the error details for specifics.
    • If the node is set to continue on failure, errors will appear in the output JSON under the error field instead of stopping execution.
  • Resolution tips:

    • Verify API credentials and permissions.
    • Confirm the market symbol format matches dYdX expectations.
    • Ensure the subaccount has sufficient balance and margin.
    • Enable "Continue On Fail" to handle intermittent errors gracefully during batch executions.

Links and References

Discussion