Skip to main content

Creating a dYdX v3 API Key for Trading Bots

This guide explains how to set up API access for dYdX, a decentralized exchange that uses MetaMask for authentication. The process differs from centralized exchanges but remains straightforward when following these steps.

Understanding the dYdX Connection​

dYdX generates API credentials automatically when connecting your MetaMask wallet. These credentials are stored in your browser's local storage. Important considerations:

Info

dYdX is a decentralized exchange (DEX) that allows users to trade perpetual contracts with leverage. Unlike centralized exchanges, users maintain custody of their funds via a connected wallet like MetaMask.

info

Wallet Requirements: Use a MetaMask wallet without a hardware wallet connection, as hardware wallets cannot sign the required messages.

info

Order Execution: dYdX uses 'fill or kill' for market orders – orders that can't be filled immediately are canceled. Trading strategies typically handle this by placing new orders at the next opportunity.

Step-by-Step dYdX API Setup​

Step 1: Connect Your Wallet​

dYdX trading platform connect wallet page

Step 2: Choose MetaMask​

dYdX wallet options with MetaMask selected

  • Select the MetaMask option.

Step 3: Confirm Connection​

dYdX MetaMask connection confirmation page

  • Click 'Connect' to link your wallet.

Step 4: Authenticate with MetaMask​

MetaMask login and authentication page for dYdX

  • Enter your MetaMask password.
  • Complete authentication.

Step 5: Enable "Remember Me"​

dYdX connection approval and permissions page

  • Check 'Remember me'.
  • Click 'Send requests'.
  • Approve MetaMask prompts.
  • Log out and back in to verify the connection.

Step 6: Export Private Key (Optional)​

For Layer 2 position tracking:

  • Open MetaMask settings.
  • Select 'Account details'.
  • Choose 'Export private key'.
  • Store it securely.

Step 7: Access Local Storage​

Browser developer tools local storage section

  • Open developer tools (usually by pressing F12).
  • Navigate to Local Storage.

Step 8: Save Stark Private Key​

dYdX Stark key derivation interface for API setup

  • Find 'privateKey' in 'STARK_KEY_PAIRS'.
  • Save this key for transaction signing.

Step 9: Save Wallet Address​

dYdX wallet address stored in local storage

  • Copy 'walletAddress' from 'STARK_KEY_PAIRS'.

Step 10: Retrieve API Key​

dYdX API key stored in local storage

  • Save 'key' from 'API_KEY_PAIRS'.

Step 11: Retrieve API Secret​

dYdX API secret stored in local storage

  • Save 'secret' from 'API_KEY_PAIRS'.

Step 12: Retrieve API Passphrase​

dYdX API passphrase stored in local storage

  • Save 'passphrase' from 'API_KEY_PAIRS'.

Step 13: Configure Your Trading Bot​

  • Enter the saved credentials into your bot's API configuration.
  • Verify the connection before trading.

Security Best Practices​

  1. Clear browser data after setup.
  2. Store credentials securely.
  3. Never share API information.
  4. Regularly review permissions.
  5. Monitor account activity.

Your trading bot will encrypt and store these credentials securely in its configuration file.

Ready to Start Trading on dYdX?​

Transform your trading approach with automated strategies designed for dYdX. Explore our dYdX Trading Bot features for optimal performance.