API key security for crypto trading bots: how to protect your exchange keys

Last updated: 17 November 2026. Author: David Lee.

Disclosure: this guide mentions products that TradeNorte has a partnership with. If you open an account or subscribe through one of our links, we may earn a commission. That does not change the price or fees you pay, and it is not a rating. This is not financial advice. You can lose all of the capital you put at risk. See our affiliate disclosure and risk disclaimer.

A trading bot never needs your exchange password. It works through an API key: a login, a secret and a set of permissions made for software. That makes API key security the part of bot trading that decides how much a single leak can cost you. This guide shows how to set up a key so that a leak stays small, with step notes for Bybit and OKX and for connecting Veles and 3Commas. It is written for readers anywhere, including India, Nigeria, the Philippines and the UAE; check that the exchange and the bot serve your country before you connect anything.

Why this matters now: the Lighter API key theft

On 16 November 2026 about 10.39 million USDC left Lighter, a decentralised exchange for perpetual futures. Lighter halted all withdrawals less than an hour later. It said an attacker had worked out one trader’s API keys from signatures made by that trader’s own code: the code reused a one-time signing value (a nonce), which let the attacker compute the key. Lighter said its smart contracts were not affected (CoinDesk, The Defiant).

Later the same day Lighter said withdrawals were back to normal. Its Security Council returned about 5 million USDC to the trader from a second attempt, and traders who run custom signing code were told to rotate their keys (The Defiant).

The detail that matters for bot users is how the money left. According to Lighter’s documentation, as summarised by The Defiant, an API key there can trade and move funds between accounts with the same owner. The attacker’s pool counted as the trader’s own sub-account, so the stolen key could fill it. The key never needed a “withdraw” right to do damage. The Defiant counted four exploits over that weekend, worth about $20.5 million in total; in three of them, about $16.8 million, attackers used access that the owner had granted to software, while the owner’s main key stayed safe (The Defiant).

Lighter is a decentralised exchange, and its keys work differently from those on a centralised exchange such as Bybit or OKX. The lesson carries over: whatever a key is allowed to do, a thief can do too. The settings below are about shrinking that list.

What an exchange API key can do

On centralised exchanges a key usually has a few permission groups. OKX lists three core ones: Read (view balances and order history), Trade (place and cancel orders, and in OKX’s wording also make funding transfers and settings) and Withdraw (OKX API docs). OKX’s API FAQ also lists separate Transfer, Loan and Earn permissions; Transfer moves funds between your own accounts, and OKX says keys that already had Trade got all three switched on automatically when they were introduced (OKX API FAQ). Bybit’s API reference shows wallet permissions such as account transfer, sub-account transfer and withdrawal, and notes that withdrawal is a master-account permission (Bybit API docs).

So “no withdrawal” is the first rule, not the only one. A key that can move money between your own accounts, or trade into a thin market, can still lose you money if it leaks.

API key security best practices for trading bots

1. Never enable withdrawal

Every bot platform we review says the same. 3Commas tells users to give “TRADING access only” and to disable withdrawal (3Commas help). Veles writes that no trading bot “needs direct access to withdrawals” (Veles blog). OKX says placing and managing orders does not require withdrawal permission (OKX). If a bot or a “support agent” asks for a key with withdrawal rights, treat it as a scam.

2. Untick everything the bot does not use

Give the key the least access the tool needs, as OKX puts it (OKX). A spot grid bot does not need futures; an analytics or portfolio tracker needs read-only. Veles makes the same point: if the bot trades only spot, do not give it futures access (Veles blog). On OKX, check whether Transfer, Loan or Earn were switched on automatically and switch off what you do not use, if the bot still works without them.

3. Bind the key to IP addresses

An IP-bound key only works from the listed addresses, so a stolen copy is useless elsewhere. OKX lets you link up to 20 IP addresses per key and strongly recommends it (OKX API FAQ, OKX API docs). Bot platforms publish their server IPs: 3Commas shows them under My Exchanges → Add exchange → your exchange (3Commas help), and Veles lists its trusted IPs in its help centre (Veles help). Where the exchange offers a built-in “third-party application” option for your bot, Veles and 3Commas both use that instead.

4. One key per bot

Create a separate key for every tool and name it after that tool. Then you can switch one off without breaking the others, and you know which tool a suspicious order came from (OKX). In Veles one key can sit behind several “Bindings”, and replacing the key in one Binding updates every bot that uses it (Veles help).

5. Use a sub-account per bot or strategy

A sub-account is a separate balance inside your exchange account. Put only the capital a bot needs there and create that bot’s key on the sub-account: a leaked key then reaches only that balance. OKX keys are created for a chosen account or sub-account, and a sub-account key does not see the main account’s funds (OKX API FAQ, OKX). Bybit’s API reference lists withdrawal as a master-account permission (Bybit API docs). Veles explains how to create a Bybit sub-account and connect it manually (Veles help).

6. Know when keys expire, and rotate them

Exchanges expire some keys on their own. On Bybit, a key created without IP binding expires after 90 days (Bybit API FAQ). On OKX, keys without IP binding that have trade or withdraw permissions are deleted after 14 days of inactivity (OKX API FAQ). Do not treat expiry as a security plan. Replace keys on your own schedule, after you update or change bot software, and immediately if you have any doubt about where a key has been, as Lighter told traders to do.

7. Revoke keys you no longer use

Removing an exchange inside the bot does not delete the key on the exchange. Veles tells users to remove the Binding in Veles and then delete the key on Bybit’s API management page (Veles help); OKX says that deleting the key in your OKX account is what stops a tool from acting on your account (OKX). 3Commas’ security page gives the same warning: after you delete an exchange in 3Commas, delete the key on the exchange’s website, “otherwise it will remain active” (3Commas security). Stopped testing a bot? Delete its key the same day.

8. Turn on 2FA, store secrets properly, and review connected apps

Use an authenticator app or passkey on the exchange, on the bot platform and on the email inbox that can reset them; our crypto account security checklist covers this in detail. Treat the secret key like a password: keep it in a password manager and never paste it into a chat, a screenshot or a support ticket (OKX). On OKX the passphrase cannot be recovered; if you lose it you create a new key (OKX API FAQ). Once a month, open API management on each exchange and check the list: names, permissions, bound IPs and anything you do not recognise.

If you write your own bot, the Lighter case is a warning about code too. Use the exchange’s official or widely maintained libraries for signing requests, keep them updated, and keep keys out of code repositories and shared folders.

Bybit API key permissions: step notes

  • Bybit API keys can only be created on the website, not in the app. New accounts may be blocked from creating a key for the first 48 hours after registration (Bybit: How to Create Your API Key?).
  • Open your profile icon → API → Create New Key. Creation needs a Google Authenticator code.
  • For a supported bot, choose Connect to Third-Party Applications and select the bot from the list. 3Commas and Veles both describe this route, with Read-Write and Unified Trading ticked (3Commas, Veles). Leave withdrawal unticked.
  • For any other tool, choose a system-generated key and bind it to the IP addresses the tool publishes.
  • Save the API key and secret before you close the window: Veles notes that the secret is shown only once (Veles help). A key without IP binding expires after 90 days (Bybit API FAQ).

Our Bybit review covers fees, KYC and restricted countries. To open an account, go to Bybit (partner link).

OKX API key and passphrase: step notes

  • On the web: Profile → API and connections → Create API key. In the app: Menu → API → Create API key (OKX API FAQ).
  • Name the key, choose the account (main or a sub-account) and what it is used for. For 3Commas, its help page says to pick Linking third-party app → 3Commas and give Trade permission (3Commas help).
  • Add the bot’s IP addresses (up to 20 per key) and select only Read and Trade. Leave Withdraw off.
  • Create a passphrase and store it with the key and secret in a password manager. OKX cannot recover it.
  • OKX notes that in some areas an account needs assets worth more than 100 USD to create an API key (OKX API FAQ).

Our OKX review covers fees, safety and availability. To open an account, go to OKX (partner link).

How Veles connects to your exchange

Veles offers two ways to connect Bybit (Veles help):

  • Fast connection (one-click): you log in to Bybit from Veles and approve the key. It works only for the main account, and the secret is never shown to you.
  • Manual connection: you create the key on Bybit with “Connect to a third-party application” → Veles, Read and Write, Unified trading account, then add it in Veles under Profile → API Keys → Add API Key → Manual connection. This is the route for sub-accounts.

On exchanges without a Veles option, bind the key to Veles’ published IP list (Veles help). To replace a key, remove the Binding in Veles first, then delete the key on the exchange. Read our Veles review for pricing and risks, or visit Veles (partner link).

How 3Commas connects to your exchange

3Commas connects through an API key that you create on the exchange and paste under My Exchanges → Add exchange. Its help page says to give trading access only, disable withdrawal, and use the whitelisted IPs it shows for your exchange when the exchange offers IP linking (3Commas help, 3Commas security). For Bybit it uses Connect to Third-Party Applications → 3Commas; for OKX, Linking third-party app → 3Commas with a passphrase.

3Commas itself confirmed an API-data disclosure incident in December 2022 that affected some users’ keys, secrets and passphrases. That is the case for IP binding and regular rotation even when you trust the platform. The details are in our 3Commas review. To sign up, go to 3Commas (official link, no partnership).

If you think a key has leaked

  1. Delete the key on the exchange first. Deleting it in the bot is not enough.
  2. Cancel orders you did not place and check positions, transfers between sub-accounts and withdrawal history.
  3. Change the exchange and email passwords and check 2FA and active sessions.
  4. Contact the exchange through a support link you typed yourself, not through a message that warned you.
  5. Create a new key with the settings above only after you know how the old one leaked.

New to bots? Start with how to start with a trading bot and our trading bot comparison. When you size a live bot, the position size calculator helps you decide how much capital to put in a sub-account.

Sources

Checked on 17 November 2026:

This is not financial advice. Nothing in this guide is an offer, a solicitation, or a recommendation to open an account, pay for a subscription, or put capital at risk. Exchange menus and rules change; confirm each setting on the official page before you rely on it. You can lose all of the money you leave on an exchange or with a bot.

Leave a Comment