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-EPOCHheader — already wired in. - Auto-minted
client_order_idoncreate_orderfor safe retries. - A single
_request/sendmethod you can extend if a new endpoint ships before the recipe is updated.
Install
- Python
- Java
- Go
- Node.js
pip install cryptography requests
Gradle:
dependencies {
implementation 'org.bouncycastle:bcprov-jdk18on:1.78'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
}
go get github.com/google/uuid
Standard library handles signing (crypto/ed25519, net/http).
Node 18+ — no dependencies. Uses native fetch and crypto.sign.
Use it
- Python
- Java
- Go
- Node.js
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",
)
import com.example.coinswitch.CoinswitchSpot;
import java.util.Map;
CoinswitchSpot cs = new CoinswitchSpot(
"<your api key>", "<your secret key>");
// Health
System.out.println(cs.serverTime());
System.out.println(cs.validateKeys());
// Account
System.out.println(cs.portfolio());
// Place an order
String resp = cs.createOrder(Map.of(
"side", "buy",
"symbol", "BTC/USDT",
"type", "limit",
"price", 60000,
"quantity", 0.001,
"exchange", "c2c1"
));
System.out.println(resp);
// List orders
System.out.println(cs.listOrders(true,
Map.of("exchanges", "coinswitchx,c2c1")));
import (
"fmt"
coinswitchspot "your.module/path/coinswitchspot"
)
cs := coinswitchspot.NewClient("<api key>", "<secret key>")
// Health
if t, err := cs.ServerTime(); err == nil { fmt.Println(string(t)) }
// Account
p, _ := cs.Portfolio()
fmt.Println(string(p))
// Place order
resp, err := cs.CreateOrder(map[string]any{
"side": "buy", "symbol": "BTC/USDT",
"type": "limit", "price": 60000,
"quantity": 0.001, "exchange": "c2c1",
})
if err != nil { panic(err) }
fmt.Println(string(resp))
// List
orders, _ := cs.ListOrders(true, map[string]string{"exchanges": "coinswitchx,c2c1"})
fmt.Println(string(orders))
const { SpotClient } = require('./coinswitch_spot');
const cs = new SpotClient({
apiKey: '<your hex api key>',
secretKey: '<your hex secret key>',
});
// Health
console.log(await cs.serverTime());
console.log(await cs.validateKeys());
// Account
console.log(await cs.portfolio());
// Place an order
const placed = await cs.createOrder({
side: 'buy', symbol: 'BTC/USDT',
type: 'limit', price: 60000, quantity: 0.001,
exchange: 'c2c1',
});
const orderId = placed.data.order_id;
console.log(await cs.getOrder(orderId));
console.log(await cs.listOrders({ open: true, exchanges: 'coinswitchx,c2c1' }));
console.log(await cs.cancelOrder(orderId));
Endpoints covered
All Spot v2 endpoints are wrapped:
| Method | Endpoint |
|---|---|
server_time / serverTime | GET /trade/api/v2/time |
validate_keys / validateKeys | GET /trade/api/v2/validate/keys |
ping | GET /trade/api/v2/ping |
active_coins / activeCoins / ActiveCoins | GET /trade/api/v2/coins |
exchange_precision / exchangePrecision / ExchangePrecision | POST /trade/api/v2/exchangePrecision |
trade_info / tradeInfo / TradeInfo | GET /trade/api/v2/tradeInfo |
trading_fee / tradingFee / TradingFee | GET /trade/api/v2/tradingFee |
portfolio / Portfolio | GET /trade/api/v2/user/portfolio |
tds / TDS | GET /trade/api/v2/tds |
create_order / createOrder / CreateOrder | POST /trade/api/v2/order |
cancel_order / cancelOrder / CancelOrder | DELETE /trade/api/v2/order |
get_order / getOrder / GetOrder | GET /trade/api/v2/order |
list_orders / listOrders / ListOrders | GET /trade/api/v2/orders |
depth / Depth | GET /trade/api/v2/depth |
candles / Candles | GET /trade/api/v2/candles |
trades / Trades | GET /trade/api/v2/trades |
ticker / Ticker | GET /trade/api/v2/24hr/ticker |
ticker_all_pairs / tickerAllPairs / TickerAllPairs | GET /trade/api/v2/24hr/all-pairs/ticker |
For per-endpoint request/response details and edge cases, see Spot Reference.
Related
- Authentication — how the signature is computed.
- Order Lifecycle — terminal vs intermediate statuses.
- Errors & Rate Limits — and the idempotency-on-retries pattern the client uses.