Skip to main content

Spot Client

A single-file client that wraps every CoinSwitch PRO Spot REST endpoint. Drop it into your project, set your API key + secret, and start trading.

What it gives you

  • Every Spot REST endpoint as a method on SpotClient.
  • Ed25519 signing + the X-AUTH-EPOCH header — already wired in.
  • Auto-minted client_order_id on create_order for safe retries.
  • A single _request / send method you can extend if a new endpoint ships before the recipe is updated.

Install

pip install cryptography requests

Use it

from coinswitch_spot import SpotClient, place_with_retry

cs = SpotClient(
api_key="<your hex api key>",
secret_key="<your hex secret key>",
)

# Health
print(cs.server_time())
print(cs.validate_keys())

# Account
print(cs.portfolio())
print(cs.tds())

# Reference data
print(cs.active_coins("coinswitchx"))
print(cs.trade_info()) # all symbols
print(cs.exchange_precision("c2c1", "BTC/USDT"))

# Orders
placed = cs.create_order(
side="buy", symbol="BTC/USDT",
type="limit", price=60000, quantity=0.001,
exchange="c2c1",
)
order_id = placed["data"]["order_id"]

print(cs.get_order(order_id))
print(cs.list_orders(open=True, exchanges=["coinswitchx", "c2c1"]))
print(cs.cancel_order(order_id))

# Market data
print(cs.depth("coinswitchx", "BTC/INR"))
print(cs.candles(
exchange="coinswitchx", symbol="BTC/INR",
interval=60,
start_time=1647388800000, end_time=1662681600000,
))

# Retry-safe placement using the idempotency pattern
safe = place_with_retry(
cs,
side="buy", symbol="BTC/USDT", type="limit",
price=60000, quantity=0.001, exchange="c2c1",
)

Endpoints covered

All Spot v2 endpoints are wrapped:

MethodEndpoint
server_time / serverTimeGET /trade/api/v2/time
validate_keys / validateKeysGET /trade/api/v2/validate/keys
pingGET /trade/api/v2/ping
active_coins / activeCoins / ActiveCoinsGET /trade/api/v2/coins
exchange_precision / exchangePrecision / ExchangePrecisionPOST /trade/api/v2/exchangePrecision
trade_info / tradeInfo / TradeInfoGET /trade/api/v2/tradeInfo
trading_fee / tradingFee / TradingFeeGET /trade/api/v2/tradingFee
portfolio / PortfolioGET /trade/api/v2/user/portfolio
tds / TDSGET /trade/api/v2/tds
create_order / createOrder / CreateOrderPOST /trade/api/v2/order
cancel_order / cancelOrder / CancelOrderDELETE /trade/api/v2/order
get_order / getOrder / GetOrderGET /trade/api/v2/order
list_orders / listOrders / ListOrdersGET /trade/api/v2/orders
depth / DepthGET /trade/api/v2/depth
candles / CandlesGET /trade/api/v2/candles
trades / TradesGET /trade/api/v2/trades
ticker / TickerGET /trade/api/v2/24hr/ticker
ticker_all_pairs / tickerAllPairs / TickerAllPairsGET /trade/api/v2/24hr/all-pairs/ticker

For per-endpoint request/response details and edge cases, see Spot Reference.