Weex Trading Bot in Python¶
This guide shows how to build a Weex trading bot in Python with LumiBot, for both AI agent trading and algorithmic trading. LumiBot connects to Weex through CCXT, the open source library that talks to more than 100 crypto exchanges. You will create a Weex 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.
What BotSpot MCP adds
Use Claude, ChatGPT, Codex, Cursor, VS Code or another MCP-compatible assistant? Connect the free BotSpot MCP for:
Skills: build LumiBot strategies.
Free data: news, economics and SEC filings.
Backtests: run tests and read charts.
Cloud hosting: low-cost scheduled bots.
Community: share bots and discuss trades.
Marketplace: discover and publish strategies.
Broker linking: connect accounts through BotSpot.
Weex at a glance¶
CCXT exchange id |
|
Markets |
Spot, Perpetual swaps |
Testnet (sandbox) |
Futures simulation only; spot example is live |
Credentials |
API key, API passphrase (CCXT calls it |
Live data streams |
prices, order book, trades, candles, your orders, your balance, your positions |
CCXT request spacing |
about 20 ms between requests |
Official site |
|
API docs |
What is Weex?¶
WEEX is a crypto exchange for spot trading and USDT-margined futures, with more than 100 coins. Its API covers both spot and futures trading.
Sign up for Weex¶
Create a WEEX account on the website.
Set up your account security. WEEX asks you to pass a security verification when you create an API key.
The spot example places live orders. WEEX futures simulation is a separate mode; do not use it as a spot testnet.
Create a Weex API key¶
Log in to WEEX on the website and go to Account, then API Management (https://www.weex.com/account/newapi).
Click Create API Key.
Make up a passphrase. WEEX cannot recover it, so save it. If you lose it you must make a new key.
Pick the permissions (see below). New keys start as Read Only.
Add your bot’s IP address to the IP allowlist (up to 10 addresses, separated by commas).
Finish the security check, then copy the API key and secret key and store them with the passphrase.
Which permissions to turn on: Keep read access and add the Spot trading permission so the bot can place spot orders. Leave any withdrawal setting off. New WEEX keys start as Read Only, so a key will not trade until you add the trading permission.
Warning
Never turn on withdrawals for a Weex trading bot key. Bind the key to your server’s IP address when Weex lets you, keep the secret out of your code and out of Git, and delete the key if it ever leaks.
Connect Weex to LumiBot¶
The simplest way: put these lines in a .env file next to your strategy. LumiBot loads the file, sees TRADING_BROKER=weex and connects to Weex for you, so your strategy needs no broker code.
TRADING_BROKER=weex
WEEX_API_KEY=your_apiKey
WEEX_API_PASSPHRASE=your_password
WEEX_API_SECRET=your_secret
LumiBot reads exactly the fields CCXT needs for Weex (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 Weex:
import os
WEEX_CONFIG = {
"exchange_id": "weex",
"apiKey": os.environ.get("WEEX_API_KEY"),
"password": os.environ.get("WEEX_API_PASSPHRASE"),
"secret": os.environ.get("WEEX_API_SECRET"),
"sandbox": False, # live connection
}
from lumibot.brokers import Ccxt
broker = Ccxt(WEEX_CONFIG)
# then: MyStrategy(broker=broker, ...)
Either way, LumiBot turns on CCXT’s built-in rate limiting for you.
Testing on Weex¶
CCXT 4.5.91 supports WEEX futures simulation on shared API hosts, using simulated contract endpoints. It rejects private spot requests in sandbox mode. The spot example here is live: leave WEEX_SANDBOX unset and set "sandbox": False. Futures simulation requires a separate configuration and supported swap operations; it does not make spot orders simulated.
Algorithmic trading example: a simple Weex bot¶
This bot buys about 50 USDT of BTC on Weex once 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.
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class WeexBuyOnce(Strategy):
"""Buy a small amount of BTC once, 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):
coin = Asset("BTC", asset_type=Asset.AssetType.CRYPTO)
if self.get_position(coin) is not None:
return # already holding BTC
price = self.get_last_price(coin, quote=self.quote_asset)
if price:
quantity = round(50 / price, 6) # about 50 USDT worth
order = self.create_order(coin, quantity, "buy", quote=self.quote_asset)
self.submit_order(order)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = WeexBuyOnce(quote_asset=Asset("USDT", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
Agentic trading example: an AI agent that trades on Weex¶
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 Weex 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 WeexAITrader(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 Weex. "
"You may trade BTC and ETH against USDT (asset_type 'crypto', quote_symbol 'USDT'), or hold cash. "
"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 and ETH/USDT prices and your current holdings, then decide whether to buy, sell or hold.",
context={"exchange": "Weex", "quote": "USDT", "date": self.get_datetime().isoformat()},
)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = WeexAITrader(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 Weex¶
Market |
Listed by CCXT |
|---|---|
Spot |
Yes |
Margin |
No |
Perpetual swaps |
Yes |
Dated futures |
No |
Options |
No |
CCXT lists these order features for Weex: market orders, limit orders, stop-loss orders, take-profit 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.
Perpetual futures example on Weex¶
Weex also lists perpetual swaps. This bot opens one small long position in BTC/USDT:USDT worth about 50 USDT and then holds it. LumiBot treats a perpetual as asset_type="crypto_future" and sizes it in contracts, the same model as LumiBot’s Bitunix futures broker. Contract symbols can differ by exchange, so check the symbol in self.broker.api.markets before going live. In hedge mode, add position_side="long" to create_order.
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class WeexOpenOneLong(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 = WeexOpenOneLong(quote_asset=Asset("USDT", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
Fees and partner IDs on Weex¶
You pay Weex’s normal trading fees. CCXT, the library underneath, normally tags Weex orders with its own partner ID. LumiBot removes that tag. LumiBot may attach its own exchange partner ID instead. That costs you nothing extra. LumiBot never adds an extra builder fee unless one is turned on, and it logs a warning when one is.
Weex tips¶
WEEX keys have three parts: API key, secret key and passphrase. Put them in
WEEX_API_KEY,WEEX_API_SECRETandWEEX_API_PASSPHRASE.Bind an IP address. WEEX warns that keys with no IP binding are a security risk.
Each WEEX user can have up to 10 API key groups, so you can give each bot its own key.
WEEX uses separate API hosts for spot and for contracts (futures). CCXT’s WEEX setup uses
api-spot.weex.comfor spot, and WEEX’s docs showapi-contract.weex.comfor contract data.
Frequently asked questions¶
Can I build a Weex trading bot in Python?
Yes. Install LumiBot (pip install lumibot), set your Weex keys and use the weex CCXT exchange id as shown above.
Does Weex have a testnet?
CCXT 4.5.91 supports WEEX futures simulation on shared API hosts, using simulated contract endpoints. It rejects private spot requests in sandbox mode. The spot example here is live: leave WEEX_SANDBOX unset and set "sandbox": False. Futures simulation requires a separate configuration and supported swap operations; it does not make spot orders simulated.
Which API permissions does a Weex bot need?
Keep read access and add the Spot trading permission so the bot can place spot orders. Leave any withdrawal setting off. New WEEX keys start as Read Only, so a key will not trade until you add the trading permission.
Can an AI agent trade on Weex 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 Weex 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 Weex 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¶
WEEX API docs: Integration Preparation (read 2026-10-23)
WEEX API docs: Spot Quick Start (read 2026-10-23)
WEEX API page (spot and futures API, FAQ) (read 2026-10-23)
WEEX API Management page (read 2026-10-23)
CCXT 4.5.91 weex adapter source (read 2026-11-01)
Exchange id, URLs, markets, credentials and stream support: CCXT 4.5.91 metadata, generated 2026-11-01