
Binance
- 1 installs
- 1 repo stars
- Updated July 29, 2026
- starchild-ai-agent/community-skills
Trades spot and USDM futures on Binance with market, limit, stop, trailing, and OCO orders, plus balances, order history, and public market data.
About
Lets an agent trade on Binance Spot and USDM Futures using a bundled ccxt engine, placing order types and reading balances and market data. A developer uses it to automate Binance trading or fetch market data with API keys in the environment.
- Supports Spot and USDM Futures with market/limit/stop/trailing/OCO orders
- Market data is public; trading requires BINANCE_API_KEY and BINANCE_SECRET
Binance by the numbers
- 1 all-time installs (skills.sh)
- Ranked #909 of 1,106 Finance & Trading skills by installs in the Skillselion catalog
- Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/starchild-ai-agent/community-skills --skill binanceAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| repo stars | ★ 1 |
| Last updated | July 29, 2026 |
| Repository | starchild-ai-agent/community-skills ↗ |
What it does
Trades spot and USDM futures on Binance with market, limit, stop, trailing, and OCO orders, plus balances, order history, and public market data.
Files
Binance Skill
Trade on Binance — the world's largest CEX — directly from Starchild.
Supports Spot and USDM Futures. Uses the bundled scripts/ccex_core.py engine under the hood.
---
Setup
1. Get your Binance API Keys
1. Log in to binance.com 2. Go to Profile → API Management 3. Create a new API key — enable Spot & Margin Trading and Futures Trading 4. Save your API key and secret
2. Add to environment
Add to workspace/.env:
BINANCE_API_KEY=your_api_key_here
BINANCE_SECRET=your_secret_here3. Install dependencies
pip install --break-system-packages ccxt---
What You Can Do
Market Data (No API key needed)
- Get current price / ticker
- View orderbook (bids & asks)
- Candlestick OHLCV data
- List all available markets
Account (API key required)
- Check spot and futures balances
- View open orders
- View order history
- View open futures positions
Trading (API key required)
- Market orders
- Limit orders
- Stop market / stop limit orders
- Take profit orders
- Trailing stop orders (delta-based)
- OCO orders (native Binance support)
- Futures orders with reduce-only
---
Workflow
ALWAYS follow this order:
1. Check balance before trading 2. Get current price / ticker 3. Place order 4. Confirm order via open orders or history
---
How to Execute
All actions run via the bundled engine. Use bash to call:
python3 skills/binance/scripts/ccex_core.py <action> --exchange binance [options]Examples
Get BTC/USDT price:
python3 skills/binance/scripts/ccex_core.py ticker --exchange binance --symbol BTC/USDTCheck balances:
python3 skills/binance/scripts/ccex_core.py balance --exchange binanceBuy 0.001 BTC at market:
python3 skills/binance/scripts/ccex_core.py order --exchange binance \
--symbol BTC/USDT --side buy --type market --amount 0.001Place limit buy at $90,000:
python3 skills/binance/scripts/ccex_core.py order --exchange binance \
--symbol BTC/USDT --side buy --type limit --amount 0.001 --price 90000Stop loss at $85,000:
python3 skills/binance/scripts/ccex_core.py order --exchange binance \
--symbol BTC/USDT --side sell --type stop --amount 0.001 --stop_price 85000Trailing stop (500 BIPS = 5%):
python3 skills/binance/scripts/ccex_core.py order --exchange binance \
--symbol BTC/USDT --side sell --type stop --amount 0.001 --trailing_delta 500OCO order — limit sell at $100k, stop at $85k:
python3 skills/binance/scripts/ccex_core.py oco --exchange binance \
--symbol BTC/USDT --side sell --amount 0.001 \
--price 100000 --stop_price 85000 --stop_limit_price 84900Futures: Long 0.01 BTC on Binance USDM:
python3 skills/binance/scripts/ccex_core.py order --exchange binance \
--symbol BTC/USDT --side buy --type market --amount 0.01 --futuresCancel an order:
python3 skills/binance/scripts/ccex_core.py cancel --exchange binance \
--symbol BTC/USDT --order_id 12345678---
Binance-Specific Notes
OCO Orders
Binance is the only major exchange with native OCO support. An OCO places a limit order and a stop-limit order simultaneously — when one fills, the other is automatically cancelled.
Parameters:
--price— the limit (take profit) price--stop_price— the stop trigger price--stop_limit_price— the actual limit price when stop triggers (optional, defaults to 0.1% below stop)
Futures vs Spot
Add --futures flag to any order command to route to Binance USDM Futures instead of spot.
Rate Limits
Binance rate limits: 1200 requests/minute (weight-based). CCXT handles this automatically with enableRateLimit: true.
Testnet
To use Binance testnet, set:
BINANCE_API_KEY=your_testnet_key
BINANCE_SECRET=your_testnet_secretAnd modify the exchange config in skills/binance/scripts/ccex_core.py to add "test": True to options.
---
Error Handling
| Error | Likely Cause | Fix |
|---|---|---|
Invalid API Key | Wrong key in .env | Re-check BINANCE_API_KEY |
Timestamp for this request | Clock skew | Sync system clock |
MIN_NOTIONAL | Order too small | Increase amount (min ~$10 USDT) |
Insufficient balance | Not enough funds | Check balance first |
OCO price rules violation | Price ordering wrong | limit > current price > stop for sell OCO |
#!/usr/bin/env python3
"""
ccex-core: Shared CCXT engine for all Starchild CEX skills.
Used internally by exchange-specific skills (binance, bybit, okx, etc.)
Not published to the marketplace directly.
Usage:
python ccex_core.py <action> [--exchange <name>] [options]
Actions:
balance - Get account balances
ticker - Get ticker for a symbol
orderbook - Get orderbook for a symbol
markets - List all available markets
order - Place an order
cancel - Cancel an order
orders - List open orders
history - Order history
position - Get open positions (futures)
ohlcv - Get OHLCV candlestick data
oco - Place an OCO order (Binance only)
"""
import os
import sys
import json
import argparse
import ccxt
# ──────────────────────────────────────────────
# Exchange factory
# ──────────────────────────────────────────────
EXCHANGE_ENV_KEYS = {
"binance": ("BINANCE_API_KEY", "BINANCE_SECRET"),
"bybit": ("BYBIT_API_KEY", "BYBIT_SECRET"),
"okx": ("OKX_API_KEY", "OKX_SECRET", "OKX_PASSPHRASE"),
"coinbase": ("COINBASE_API_KEY", "COINBASE_SECRET"),
"kraken": ("KRAKEN_API_KEY", "KRAKEN_SECRET"),
"kucoin": ("KUCOIN_API_KEY", "KUCOIN_SECRET", "KUCOIN_PASSPHRASE"),
"gateio": ("GATEIO_API_KEY", "GATEIO_SECRET"),
"mexc": ("MEXC_API_KEY", "MEXC_SECRET"),
"htx": ("HTX_API_KEY", "HTX_SECRET"),
"bitget": ("BITGET_API_KEY", "BITGET_SECRET", "BITGET_PASSPHRASE"),
}
def get_exchange(exchange_id: str, futures: bool = False) -> ccxt.Exchange:
"""Create and authenticate a CCXT exchange instance."""
exchange_id = exchange_id.lower()
if exchange_id not in dir(ccxt):
raise ValueError(f"Exchange '{exchange_id}' not supported by CCXT")
env_keys = EXCHANGE_ENV_KEYS.get(exchange_id, ())
config = {"enableRateLimit": True}
if len(env_keys) >= 2:
api_key = os.environ.get(env_keys[0])
secret = os.environ.get(env_keys[1])
if api_key and secret:
config["apiKey"] = api_key
config["secret"] = secret
if len(env_keys) == 3:
passphrase = os.environ.get(env_keys[2])
if passphrase:
config["password"] = passphrase
# Futures mode
if futures:
if exchange_id == "binance":
config["options"] = {"defaultType": "future"}
elif exchange_id == "bybit":
config["options"] = {"defaultType": "linear"}
elif exchange_id == "okx":
config["options"] = {"defaultType": "swap"}
exchange_class = getattr(ccxt, exchange_id)
return exchange_class(config)
# ──────────────────────────────────────────────
# Actions
# ──────────────────────────────────────────────
def action_balance(exchange: ccxt.Exchange, args) -> dict:
balance = exchange.fetch_balance()
# Filter to non-zero balances for cleaner output
clean = {
"total": {k: v for k, v in balance["total"].items() if v and v > 0},
"free": {k: v for k, v in balance["free"].items() if v and v > 0},
"used": {k: v for k, v in balance["used"].items() if v and v > 0},
}
return clean
def action_ticker(exchange: ccxt.Exchange, args) -> dict:
if not args.symbol:
raise ValueError("--symbol required for ticker")
return exchange.fetch_ticker(args.symbol)
def action_orderbook(exchange: ccxt.Exchange, args) -> dict:
if not args.symbol:
raise ValueError("--symbol required for orderbook")
limit = args.limit or 20
ob = exchange.fetch_order_book(args.symbol, limit)
return {
"symbol": args.symbol,
"bids": ob["bids"][:10],
"asks": ob["asks"][:10],
"timestamp": ob.get("timestamp"),
}
def action_markets(exchange: ccxt.Exchange, args) -> list:
markets = exchange.load_markets()
result = []
for symbol, m in list(markets.items())[:100]: # cap at 100 for readability
result.append({
"symbol": symbol,
"base": m.get("base"),
"quote": m.get("quote"),
"type": m.get("type"),
"active": m.get("active"),
})
return result
def action_ohlcv(exchange: ccxt.Exchange, args) -> list:
if not args.symbol:
raise ValueError("--symbol required for ohlcv")
timeframe = args.timeframe or "1h"
limit = args.limit or 100
ohlcv = exchange.fetch_ohlcv(args.symbol, timeframe, limit=limit)
return [
{"timestamp": c[0], "open": c[1], "high": c[2], "low": c[3], "close": c[4], "volume": c[5]}
for c in ohlcv
]
def action_order(exchange: ccxt.Exchange, args) -> dict:
"""Place a standard order using CCXT unified API."""
if not args.symbol:
raise ValueError("--symbol required")
if not args.side:
raise ValueError("--side required (buy/sell)")
if not args.type:
raise ValueError("--type required (market/limit/stop/etc.)")
if not args.amount:
raise ValueError("--amount required")
params = {}
# Stop/trigger price
if args.stop_price:
params["stopPrice"] = float(args.stop_price)
# Trailing
if args.trailing_delta:
params["trailingDelta"] = int(args.trailing_delta)
# Reduce only (futures)
if args.reduce_only:
params["reduceOnly"] = True
# Post only
if args.post_only:
params["postOnly"] = True
price = float(args.price) if args.price else None
amount = float(args.amount)
order = exchange.create_order(
symbol=args.symbol,
type=args.type,
side=args.side,
amount=amount,
price=price,
params=params,
)
return order
def action_oco(exchange: ccxt.Exchange, args) -> dict:
"""
Place an OCO order.
Currently supported: Binance (raw API), simulated on others.
OCO = One-Cancels-the-Other
Requires: symbol, side, amount, price (limit), stop_price, stop_limit_price
"""
if not all([args.symbol, args.side, args.amount, args.price, args.stop_price]):
raise ValueError("OCO requires --symbol, --side, --amount, --price, --stop_price")
exchange_id = exchange.id.lower()
if exchange_id == "binance":
# Binance native OCO via raw API
stop_limit_price = args.stop_limit_price or str(float(args.stop_price) * 0.999)
result = exchange.private_post_order_oco({
"symbol": exchange.market_id(args.symbol),
"side": args.side.upper(),
"quantity": args.amount,
"price": args.price,
"stopPrice": args.stop_price,
"stopLimitPrice": stop_limit_price,
"stopLimitTimeInForce": "GTC",
})
return {"type": "native_oco", "exchange": "binance", "result": result}
else:
# Simulate OCO with two separate orders + warning
limit_order = exchange.create_order(
symbol=args.symbol,
type="limit",
side=args.side,
amount=float(args.amount),
price=float(args.price),
)
stop_order = exchange.create_order(
symbol=args.symbol,
type="stop",
side=args.side,
amount=float(args.amount),
price=float(args.stop_price),
params={"stopPrice": float(args.stop_price)},
)
return {
"type": "simulated_oco",
"exchange": exchange_id,
"warning": f"{exchange_id} does not support native OCO. Placed as two separate orders. You must cancel one manually when the other fills.",
"limit_order": limit_order,
"stop_order": stop_order,
}
def action_cancel(exchange: ccxt.Exchange, args) -> dict:
if not args.order_id:
raise ValueError("--order_id required")
if not args.symbol:
raise ValueError("--symbol required")
return exchange.cancel_order(args.order_id, args.symbol)
def action_orders(exchange: ccxt.Exchange, args) -> list:
symbol = args.symbol or None
return exchange.fetch_open_orders(symbol)
def action_history(exchange: ccxt.Exchange, args) -> list:
symbol = args.symbol or None
limit = args.limit or 50
return exchange.fetch_closed_orders(symbol, limit=limit)
def action_position(exchange: ccxt.Exchange, args) -> list:
symbol = args.symbol or None
if hasattr(exchange, 'fetch_positions'):
positions = exchange.fetch_positions([symbol] if symbol else None)
return [p for p in positions if p.get("contracts") and p["contracts"] > 0]
return []
# ──────────────────────────────────────────────
# CLI
# ──────────────────────────────────────────────
ACTION_MAP = {
"balance": action_balance,
"ticker": action_ticker,
"orderbook": action_orderbook,
"markets": action_markets,
"ohlcv": action_ohlcv,
"order": action_order,
"oco": action_oco,
"cancel": action_cancel,
"orders": action_orders,
"history": action_history,
"position": action_position,
}
def main():
parser = argparse.ArgumentParser(description="ccex-core CCXT engine")
parser.add_argument("action", choices=list(ACTION_MAP.keys()))
parser.add_argument("--exchange", required=True, help="Exchange ID (binance, bybit, okx, ...)")
parser.add_argument("--symbol", help="Trading pair, e.g. BTC/USDT")
parser.add_argument("--side", help="buy or sell")
parser.add_argument("--type", help="order type: market, limit, stop, stop_limit")
parser.add_argument("--amount", help="Order amount in base currency")
parser.add_argument("--price", help="Limit price")
parser.add_argument("--stop_price", help="Stop/trigger price")
parser.add_argument("--stop_limit_price", help="Stop limit price (OCO)")
parser.add_argument("--trailing_delta", help="Trailing delta in BIPS (Binance)")
parser.add_argument("--order_id", help="Order ID for cancel")
parser.add_argument("--timeframe", help="OHLCV timeframe, e.g. 1h, 4h, 1d")
parser.add_argument("--limit", type=int, help="Result limit")
parser.add_argument("--futures", action="store_true", help="Use futures/perp market")
parser.add_argument("--reduce_only", action="store_true", help="Reduce-only order")
parser.add_argument("--post_only", action="store_true", help="Post-only (maker) order")
args = parser.parse_args()
try:
exchange = get_exchange(args.exchange, futures=args.futures)
result = ACTION_MAP[args.action](exchange, args)
print(json.dumps(result, indent=2, default=str))
except Exception as e:
print(json.dumps({"error": str(e)}, indent=2), file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()