Skip to main content

dYdX API Setup for Gunbot

Connecting Gunbot to dYdX is a unique process compared to other exchanges due to its decentralized nature. This guide will walk you through the steps to set up your dYdX API for use with Gunbot.

Understanding the dYdX Connection

Unlike centralized exchanges, dYdX generates API credentials automatically when you connect your MetaMask wallet. These credentials are stored in your browser. It's important to use a MetaMask wallet that is not connected to a hardware wallet, as the private key of a hardware wallet cannot be used for signing messages due to security protocols.


Wallet Choice: You don't need to use the same wallet as your Gunthy Wallet Address for dYdX. You can create a new Metamask wallet separate from your Gunbot License Wallet.


Info about market orders: dYdX enforces 'fill or kill' on market orders, meaning the order gets cancelled when it cannot fill immediately. This is fine in most trading strategies as they would just replace the order at next opportunity. When you're using an alert based sell trigger, please be aware that market orders might get cancelled.

Step-by-Step dYdX API Setup

Step 1: Connect Wallet

Step 1

  • Go to dYdX.
  • Select 'Connect wallet' to start the process.

Step 2: Choose MetaMask

Step 2

  • Select 'MetaMask' to continue.

Step 3: Choose Connect

Step 3

  • Click on 'Connect'.

Step 4: Enter MetaMask Password

Step 4

  • Enter your MetaMask password to log in.

Step 5: Remember Me and Permissions

Step 5

  • Select 'Remember me' and click 'Send requests'.
  • Approve the connection prompts in MetaMask.
  • Log out and back in to ensure the account is remembered.

Step 6: Export Private Key

  • This step is optional, it allows Gunbot to ensure position data on L2 gets updated at the time orders get placed. You can leave the field blank or enter a placeholder when you do not want to enter the real key.
  • Open MetaMask and select the three dots icon.
  • Go to 'Account details'.
  • Select 'Export private key' and save it.

Step 7: Open Local Storage Manager

Step 7

  • Open browser developer tools (F12 or Ctrl-Shift-i).
  • Navigate to the local storage section.

Step 8: Stark Private Key

Step 8

  • Save the 'privateKey' in 'STARK_KEY_PAIRS'.

Step 9: Wallet Address

Step 9

  • Save the 'walletAddress' in 'STARK_KEY_PAIRS'.

Step 10: API Key

Step 10

  • Save the 'key' in 'API_KEY_PAIRS'.

Step 11: API Secret

Step 11

  • Save the 'secret' in 'API_KEY_PAIRS'.

Step 12: Passphrase

Step 12

  • Save the 'passphrase' in 'API_KEY_PAIRS'.

Step 13: Add dYdX to Gunbot

  • Use the Manage API Slots page to save the credentials that you've just gathered.

Ensuring Security

After configuring Gunbot, ensure to delete the plain text credentials collected during the setup. Gunbot encrypts and stores these credentials in the config file for security.

Follow these steps carefully to ensure a secure and successful setup of dYdX with Gunbot.