Overview
The node integrates with the dYdX v4 API, a decentralized exchange platform for perpetual contracts. It enables users to perform various trading-related operations such as retrieving market data, managing positions, placing orders, transferring funds between subaccounts, and executing "smart position" adjustments.
The Smart Position operation specifically allows users to adjust their position size on a given market to a target size. This means if you currently hold a smaller or larger position than desired, the node will calculate and execute the necessary trades to reach the specified target size. This is useful for automated portfolio rebalancing, risk management, or scaling into/out of positions programmatically.
Practical examples:
- Automatically increase your BTC-USD position to 2 contracts when a signal triggers.
- Reduce your ETH-USD exposure to zero by closing out any open positions.
- Switch from a short to a long position on a market by specifying a negative to positive target size.
Properties
| Name | Meaning |
|---|---|
| Market | Market symbol to trade on (e.g., BTC-USD). |
| Target Position Size | Desired final size of the position. Positive values indicate a long position; negative values indicate a short position. |
| Subaccount ID | Identifier of the subaccount under which the position adjustment should be made. |
Output
The output JSON object for the Smart Position operation includes:
success: Boolean indicating whether the smart position adjustment was initiated successfully.message: A confirmation string, e.g., "Smart position initiated".market: The market symbol used in the operation.targetSize: The target position size requested.currentSize: The current position size before adjustment (returned from the service).timestamp: ISO timestamp of when the operation was executed.
If an error occurs and the node is configured to continue on failure, the output will contain:
success: falseerror: Error message describing what went wrong.marketandtargetSize: Echoed input parameters for context.
No binary data output is produced by this operation.
Dependencies
- Requires an API key credential for authenticating with the dYdX v4 API.
- Uses internal services (
TradingServiceandAccountService) to interact with the dYdX network. - Network configuration and user address are obtained from credentials.
- No additional external dependencies beyond the dYdX API and n8n credential setup.
Troubleshooting
Common issues:
- Invalid or missing market symbol can cause failures.
- Insufficient permissions or incorrect API credentials will prevent successful API calls.
- Network connectivity problems may lead to timeouts or errors.
- Specifying a subaccount ID that does not exist or is unauthorized can cause errors.
Error messages:
"Failed to execute smart position: <error message>"indicates the underlying API call or logic failed. Check the error details for specifics.- If the node is set to stop on failure, it will throw an error stopping execution; otherwise, it outputs the error in the JSON response.
Resolution tips:
- Verify the market symbol format matches dYdX expectations.
- Ensure API credentials are valid and have required scopes.
- Confirm the subaccount ID exists and belongs to the authenticated user.
- Enable "Continue On Fail" in the node settings to handle errors gracefully during batch executions.