Apex Trading Bot in Python¶
This guide shows how to build a Apex trading bot in Python with LumiBot, for both AI agent trading and algorithmic trading. LumiBot connects to Apex through CCXT, the open source library that talks to more than 100 crypto exchanges. You will create a Apex account and API key, connect it, and run two examples: a simple algorithmic trading bot and an agentic trading bot where an AI agent makes the calls.
Apex at a glance¶
CCXT exchange id |
|
Markets |
Perpetual swaps |
Testnet (sandbox) |
Yes |
Credentials |
API key, API passphrase (CCXT calls it |
Live data streams |
prices, order book, trades, candles, your orders, your positions |
CCXT request spacing |
about 20 ms between requests |
Official site |
|
API docs |
|
Fees |
https://apex-pro.gitbook.io/apex-pro/apex-omni-live-now/trading-perpetual-contracts/trading-fees |
What is Apex?¶
ApeX Omni is a decentralized exchange (DEX) for perpetual futures that you use with a crypto wallet. It supports deposits and withdrawals on Ethereum, BNB Chain, Base, Mantle and Arbitrum.
Sign up for Apex¶
Open ApeX Omni and connect your crypto wallet. Your wallet is your account, and you sign a message with it to set up access.
Deposit funds into your Omni funding account, then move them to your Perps account to trade.
For practice, use the ApeX Omni testnet at https://testnet.omni.apex.exchange. It runs on test chains, and you can get free test assets from its faucet at https://testnet.omni.apex.exchange/faucet.
Create a Apex API key¶
Connect your wallet and open the key management page at https://omni.apex.exchange/keyManagement.
Click Generate API and confirm with a wallet signature. Choose a passphrase you will remember: ApeX cannot recover it, and if you lose it you must make a new key.
Save the three values ApeX shows: the API key, the secret key and your passphrase.
On the same page, click Omni Key to get your seeds. ApeX needs these to sign every order, on top of the API key.
Store all four values somewhere safe. Each account can have up to 30 API keys.
Which permissions to turn on: ApeX Omni works differently from a normal exchange. The API key, secret and passphrase let your bot read the account, but orders, transfers and withdrawals also need a second signature made with your Omni Key seeds. That means anyone with your API key and seeds together could also move money, so treat the seeds like a wallet private key: keep them only on the machine that runs your bot and never share them. Never give LumiBot your main wallet’s private key; the Omni Key seeds are all it needs.
Warning
Never turn on withdrawals for a Apex trading bot key. Bind the key to your server’s IP address when Apex lets you, keep the secret out of your code and out of Git, and delete the key if it ever leaks.
Connect Apex to LumiBot¶
The simplest way: put these lines in a .env file next to your strategy. LumiBot loads the file, sees TRADING_BROKER=apex and connects to Apex for you, so your strategy needs no broker code.
TRADING_BROKER=apex
APEX_API_KEY=your_apiKey
APEX_API_PASSPHRASE=your_password
APEX_API_SECRET=your_secret
APEX_SANDBOX=true # testnet; remove this line for your live account
LumiBot reads exactly the fields CCXT needs for Apex (apiKey, password, secret). If one is missing, LumiBot stops at start-up and names the variable you still need.
You can also build the broker in code. This is handy when one script talks to more than one exchange, or when you need extra CCXT options. The keys in the config are CCXT’s own credential names for Apex:
import os
APEX_CONFIG = {
"exchange_id": "apex",
"apiKey": os.environ.get("APEX_API_KEY"),
"password": os.environ.get("APEX_API_PASSPHRASE"),
"secret": os.environ.get("APEX_API_SECRET"),
"sandbox": True, # testnet first; set False for your live account
}
from lumibot.brokers import Ccxt
broker = Ccxt(APEX_CONFIG)
# then: MyStrategy(broker=broker, ...)
Either way, LumiBot turns on CCXT’s built-in rate limiting for you.
Practice on the Apex testnet¶
ApeX Omni runs a full testnet at https://testnet.omni.apex.exchange, with a faucet for test assets. Make separate keys and an Omni Key on the testnet site. Set APEX_SANDBOX=true (or "sandbox": True in a code config) to use it.
CCXT sends sandbox requests to: https://testnet.omni.apex.exchange/api. Testnet and live accounts use different keys.
Algorithmic trading example: a simple Apex bot¶
CCXT lists no spot market for Apex, so this example trades a perpetual contract. It opens one small long BTC position worth about 50 USDT and then holds it. It is a starting point to check that your keys, balances and orders work. If the exchange’s minimum order is larger, raise the amount. If your account uses hedge mode, add position_side="long" to create_order.
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class ApexOpenOneLong(Strategy):
"""Open one small long BTC perpetual position, then hold it."""
def initialize(self):
self.sleeptime = "1H"
self.set_market("24/7") # crypto trades all day, every day
def on_trading_iteration(self):
# The full CCXT symbol keeps the settlement currency clear.
contract = self.broker.get_asset("BTC/USDT:USDT")
if self.get_position(contract) is not None:
return # already holding the position
price = self.get_last_price(contract)
if price:
# Each contract covers contract.multiplier BTC; size the order to about 50 USDT.
quantity = round(50 / (price * contract.multiplier), 6)
order = self.create_order(contract, quantity, "buy")
self.submit_order(order)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = ApexOpenOneLong(quote_asset=Asset("USDT", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
Agentic trading example: an AI agent that trades on Apex¶
Agentic trading means an AI agent reads the market and decides what to do. In this example one LumiBot agent looks at prices and your Apex account, then places the orders itself. There is no Python logic in between: you set the rules in plain English in the prompt, such as what it may trade and how big each order can be. This follows the same pattern as LumiBot’s AI trading team examples.
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class ApexAITrader(Strategy):
"""One AI agent researches the market and places the trades itself."""
def initialize(self):
self.sleeptime = "4H"
self.set_market("24/7")
self.agents.create(
name="trader",
model="openai/gpt-6-luna",
reasoning_effort="high",
allow_trading=True,
system_prompt=(
"You manage a small crypto account on Apex. "
"You may trade the BTC/USDT:USDT perpetual contract (asset_type 'crypto_future'), long or short, or stay flat. "
"Before every order, call account_portfolio, account_positions and "
"market_last_price for that exact symbol in the same run. "
"Keep each order under 10% of the account value. "
"Explain each decision in one short paragraph."
),
)
def on_trading_iteration(self):
self.agents["trader"].run(
task_prompt="Review recent BTC/USDT:USDT prices and your current position, then decide whether to buy, sell or hold.",
context={"exchange": "Apex", "quote": "USDT", "date": self.get_datetime().isoformat()},
)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = ApexAITrader(quote_asset=Asset("USDT", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
The agent needs a model key such as OPENAI_API_KEY in your environment. See the AI agents quickstart for models, tools and memory.
What you can trade on Apex through CCXT¶
Market |
Listed by CCXT |
|---|---|
Spot |
No |
Margin |
No |
Perpetual swaps |
Yes |
Dated futures |
No |
Options |
No |
CCXT lists these order features for Apex: market orders, limit orders, stop orders, reduce-only orders, canceling orders.
For perpetual contracts, use the full CCXT symbol so the settlement currency is clear, for example BTC/USDT:USDT. See the CCXT guide for contract quantities, position modes and leverage.
Apex tips¶
ApeX Omni needs three API values (API key, secret and passphrase) plus your Omni Key seeds. In CCXT terms, the passphrase is
passwordand the seeds go in the exchange options, for example"options": {"seeds": "..."}in a code config. Without the seeds, CCXT can read your account but cannot place orders.ApeX Omni markets are perpetual futures, so use the full CCXT symbol such as
BTC/USDT:USDT. ApeX’s own API writes it asBTC-USDT.ApeX says to trade you deposit into your Omni funding account and then transfer funds to your Perps account. Make that transfer before starting your bot.
Frequently asked questions¶
Can I build a Apex trading bot in Python?
Yes. Install LumiBot (pip install lumibot), set your Apex keys and use the apex CCXT exchange id as shown above.
Does Apex have a testnet?
Yes. Set APEX_SANDBOX=true and use keys from the Apex testnet.
Which API permissions does a Apex bot need?
ApeX Omni works differently from a normal exchange. The API key, secret and passphrase let your bot read the account, but orders, transfers and withdrawals also need a second signature made with your Omni Key seeds. That means anyone with your API key and seeds together could also move money, so treat the seeds like a wallet private key: keep them only on the machine that runs your bot and never share them. Never give LumiBot your main wallet’s private key; the Omni Key seeds are all it needs.
Can an AI agent trade on Apex by itself?
Yes. The agentic example above gives one agent permission to trade. You control what it may trade and how much through its prompt.
Can I trade Apex perpetual futures with LumiBot?
CCXT lists perpetual swaps for this exchange. Use the full contract symbol, such as BTC/USDT:USDT.
Is LumiBot free?
Yes. LumiBot is open source on GitHub at https://github.com/Lumiwealth/lumibot. You pay only your exchange’s trading fees and, for AI agents, your model provider.
Run it in the cloud with BotSpot¶
Do not want to keep a computer running for your Apex bot? BotSpot is the hosted home for LumiBot strategies and AI trading agents: build with AI, backtest, connect a broker, and watch every trade with logs and alerts.
Sources¶
ApeX Omni API docs: introduction, testnet and signatures (read 2026-10-23)
ApeX Omni API docs: Best Practice (API key credentials and Omni Key) (read 2026-10-23)
ApeX Omni API docs: FAQ (read 2026-10-23)
Exchange id, URLs, markets, credentials and stream support: CCXT 4.5.64 metadata, generated 2026-10-23