
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
coindcx
Advanced tools
This is an unofficial Python wrapper for the CoinDCX Exchange API with support for public market data and authenticated trading.
pip install coindcx
from coindcx import Client
# Initialize client without credentials for public endpoints
client = Client()
# Get all markets
markets = client.get_markets()
print(f"Available markets: {len(markets)}")
# Get ticker for all markets
tickers = client.get_ticker()
for ticker in tickers[:5]: # Show first 5
print(f"{ticker['market']}: {ticker['last_price']}")
# Get market details
details = client.get_markets_details()
for market in details[:3]:
print(f"{market['coindcx_name']}: Min quantity = {market['min_quantity']}")
# Get order book
orderbook = client.get_orderbook('KC-BTC_USDT')
print(f"Best bid: {list(orderbook['bids'].keys())[0]}")
print(f"Best ask: {list(orderbook['asks'].keys())[0]}")
# Get recent trades
trades = client.get_trades('KC-BTC_USDT', limit=10)
print(f"Latest trade price: {trades[0]['p']}")
# Get candlestick data
candles = client.get_candles('KC-BTC_USDT', interval='1h', limit=24)
print(f"24h candles received: {len(candles)}")
from coindcx import Client
import time
client = Client()
# Get all active USDT margined futures instruments
instruments = client.get_active_instruments(['USDT'])
print(f"Total USDT instruments: {len(instruments)}")
print(f"Sample instruments: {instruments[:5]}")
# Get detailed information for a specific instrument
details = client.get_instrument_details('B-BTC_USDT', 'USDT')
instrument = details['instrument']
print(f"Status: {instrument['status']}")
print(f"Max leverage: {instrument['max_leverage_long']}x")
print(f"Maker fee: {instrument['maker_fee']}%")
print(f"Min quantity: {instrument['min_quantity']}")
# Get futures candlestick data
to_time = int(time.time())
from_time = to_time - (7 * 24 * 60 * 60) # 7 days ago
candles = client.get_futures_candles('B-BTC_USDT', from_time, to_time, '1D')
print(f"Futures candles: {len(candles['data'])}")
# Get futures trade history
trades = client.get_futures_trade_history('B-BTC_USDT')
for trade in trades[:5]:
print(f"Trade: {trade['quantity']} @ {trade['price']} (Maker: {trade['is_maker']})")
from coindcx import Client, OrderSide, OrderType, FuturesOrderType, TimeInForce
# Initialize client with API credentials
client = Client(
api_key='your_api_key_here',
api_secret='your_api_secret_here'
)
# Get account balances
balances = client.get_balances()
for balance in balances:
if float(balance['balance']) > 0:
print(f"{balance['currency']}: {balance['balance']}")
# Get user info
user_info = client.get_user_info()
print(f"User ID: {user_info['coindcx_id']}")
print(f"Email: {user_info['email']}")
from coindcx import Client, OrderSide, OrderType
client = Client(api_key='your_key', api_secret='your_secret')
# Create a market buy order - buy 0.001 BTC at market price
market_order = client.create_spot_order(
market='KC-BTC_USDT',
side=OrderSide.BUY,
order_type=OrderType.MARKET_ORDER,
total_quantity=0.001
)
print(f"Market Order ID: {market_order['id']}, Status: {market_order['status']}")
# Create a limit sell order - sell 0.001 BTC at $52,000
limit_order = client.create_spot_order(
market='KC-BTC_USDT',
side=OrderSide.SELL,
order_type=OrderType.LIMIT_ORDER,
total_quantity=0.001,
price_per_unit=52000,
client_order_id='my-custom-order-id' # Optional tracking ID
)
print(f"Limit Order ID: {limit_order['id']}, Price: {limit_order['price_per_unit']}")
from coindcx import Client, OrderSide, FuturesOrderType, TimeInForce
client = Client(api_key='your_key', api_secret='your_secret')
# Create a market futures order with 10x leverage
futures_market = client.create_futures_order(
pair='B-BTC_USDT',
side=OrderSide.BUY,
order_type=FuturesOrderType.MARKET,
total_quantity=0.01,
leverage=10,
margin_currency_short_name='USDT'
)
print(f"Futures Market Order: {futures_market['id']}, Leverage: {futures_market['leverage']}x")
# Create a limit futures order with take profit and stop loss
futures_limit = client.create_futures_order(
pair='B-BTC_USDT',
side=OrderSide.BUY,
order_type=FuturesOrderType.LIMIT,
total_quantity=0.01,
price=49000,
leverage=5,
time_in_force=TimeInForce.GOOD_TILL_CANCEL,
take_profit_price=55000, # Take profit at $55,000
stop_loss_price=47000, # Stop loss at $47,000
post_only=True # Maker-only order
)
print(f"Futures Limit Order: {futures_limit['id']}")
# Create a stop-limit order (triggered when price hits stop_price)
stop_limit = client.create_futures_order(
pair='B-ETH_USDT',
side=OrderSide.SELL,
order_type=FuturesOrderType.STOP_LIMIT,
total_quantity=0.1,
price=3200, # Limit price once triggered
stop_price=3250, # Trigger price
leverage=3,
time_in_force=TimeInForce.FILL_OR_KILL
)
# Create a take profit market order
take_profit = client.create_futures_order(
pair='B-BTC_USDT',
side=OrderSide.SELL,
order_type=FuturesOrderType.TAKE_PROFIT_MARKET,
total_quantity=0.005,
stop_price=60000, # Trigger when BTC hits $60,000
leverage=2
)
# List open futures orders
open_orders = client.list_futures_orders(
side=OrderSide.BUY,
status='open',
margin_currency_short_name=['USDT']
)
print(f"Open Orders: {len(open_orders)}")
# Edit an existing futures order
edited_order = client.edit_futures_order(
id='order_id_here',
total_quantity=0.5,
price=51000,
take_profit_price=55000,
stop_loss_price=48000
)
print(f"Edited Order ID: {edited_order['id']}")
from coindcx import Client
# Automatically closes session when done
with Client(api_key='...', api_secret='...') as client:
balances = client.get_balances()
print(balances)
# Session automatically closed here
The library includes a powerful generic CLI tool that automatically exposes all client methods for command-line usage. Perfect for quick testing, scripting, and automation.
# View all available methods and their parameters
python cli.py --help
# Call any method with named parameters
python cli.py [method_name] --arg1=value1 --arg2=value2
Public Endpoints (No Authentication):
# Get all markets
python cli.py get_markets
# Get ticker data for all markets
python cli.py get_ticker
# Get recent trades with parameters
python cli.py get_trades --pair=KC-BTC_USDT --limit=10
# Get order book for a specific pair
python cli.py get_orderbook --pair=KC-BTC_USDT
# Get candlestick data
python cli.py get_candles --pair=KC-BTC_USDT --interval=1h --limit=24
# Get markets details
python cli.py get_markets_details
# Get futures candles
python cli.py get_futures_candles --pair=B-BTC_USDT --from_time=1700000000 --to_time=1700086400 --resolution=1D
# Get futures trade history
python cli.py get_futures_trade_history --pair=B-BTC_USDT
# Get active futures instruments (JSON format or comma-separated)
python cli.py get_active_instruments --margin_currency_short_name=["USDT"]
python cli.py get_active_instruments --margin_currency_short_name=USDT,INR
# Get instrument details
python cli.py get_instrument_details --pair=B-BTC_USDT --margin_currency_short_name=USDT
Authenticated Endpoints:
# Option 1: Pass credentials as arguments
python cli.py get_balances --api-key=YOUR_KEY --api-secret=YOUR_SECRET
python cli.py get_user_info --api-key=YOUR_KEY --api-secret=YOUR_SECRET
# Option 2: Use environment variables (recommended for security)
export COINDCX_API_KEY="your_api_key"
export COINDCX_API_SECRET="your_api_secret"
python cli.py get_balances
python cli.py get_user_info
# Create spot orders
python cli.py create_spot_order --market=KC-BTC_USDT --side=buy --order_type=market_order --total_quantity=0.001
python cli.py create_spot_order --market=KC-ETH_USDT --side=sell --order_type=limit_order --total_quantity=0.1 --price_per_unit=3500 --client_order_id=my-custom-id
# Create futures orders
python cli.py create_futures_order --pair=B-BTC_USDT --side=buy --order_type=market --total_quantity=0.01 --leverage=10 --margin_currency_short_name=USDT
python cli.py create_futures_order --pair=B-BTC_USDT --side=buy --order_type=limit --total_quantity=0.01 --price=50000 --leverage=5 --time_in_force=good_till_cancel
# List futures orders
python cli.py list_futures_orders --side=buy --status=open
# Edit futures order
python cli.py edit_futures_order --id=ORDER_ID --total_quantity=0.5 --price=51000
Additional Options:
# Customize timeout
python cli.py get_candles --pair=KC-BTC_USDT --interval=1h --timeout=60
# Disable pretty printing (compact JSON)
python cli.py get_markets --pretty=false
The CLI uses Python's introspection to:
Client classThis means any new methods you add to the Client class are automatically available in the CLI without any changes!
| Option | Description | Example |
|---|---|---|
--api-key | API key for authentication | --api-key=YOUR_KEY |
--api-secret | API secret for authentication | --api-secret=YOUR_SECRET |
--timeout | Request timeout in seconds (default: 30) | --timeout=60 |
--pretty | Pretty print JSON output (default: true) | --pretty=false |
--help, -h | Show help message | python cli.py --help |
The CLI is perfect for shell scripts and automation:
#!/bin/bash
# Monitor BTC price every 30 seconds
export COINDCX_API_KEY="your_key"
export COINDCX_API_SECRET="your_secret"
while true; do
echo "Checking BTC price at $(date)"
python cli.py get_orderbook --pair=KC-BTC_USDT | jq -r '.asks | keys[0]'
sleep 30
done
#!/bin/bash
# Get account balances and filter non-zero balances
python cli.py get_balances | jq '.[] | select((.balance | tonumber) > 0)'
The library provides specific exceptions for different error scenarios:
from coindcx import Client, CoinDCXAPIException, CoinDCXAuthenticationException
client = Client()
try:
# This will fail - authentication required
balances = client.get_balances()
except CoinDCXAuthenticationException as e:
print(f"Authentication error: {e}")
try:
# Invalid market
orderbook = client.get_orderbook('INVALID_MARKET')
except CoinDCXAPIException as e:
print(f"API error [{e.status_code}]: {e.message}")
CoinDCXException (base)
βββ CoinDCXAPIException # API errors (4xx, 5xx responses)
βββ CoinDCXRequestException # Network/timeout errors
βββ CoinDCXAuthenticationException # Missing or invalid credentials
βββ CoinDCXRateLimitException # Rate limit exceeded (429)
βββ CoinDCXOrderException # Order-related errors
βββ CoinDCXInvalidOrderException
The library provides enums for various constants:
from coindcx import Client, OrderSide, OrderType, CandleInterval
# Use enums for type safety
candles = client.get_candles(
pair='KC-BTC_USDT',
interval=CandleInterval.ONE_HOUR,
limit=100
)
Available enums:
OrderSide: BUY, SELLOrderType: MARKET_ORDER, LIMIT_ORDER, STOP_LIMIT, TAKE_PROFITOrderStatus: INIT, OPEN, FILLED, CANCELLED, etc.CandleInterval: ONE_MINUTE, FIVE_MINUTES, ONE_HOUR, ONE_DAY, etc.ExchangeCode: COINDCX_INR, BINANCE, HUOBI, KUCOINTimeInForce: GOOD_TILL_CANCEL, IMMEDIATE_OR_CANCEL, FILL_OR_KILLFuturesMarginMode: INR, USDTPositionMarginType: ISOLATED, CROSSEDPublic Endpoints:
get_ticker() - Get ticker for all marketsget_markets() - Get list of all marketsget_markets_details() - Get detailed market informationget_trades(pair, limit) - Get recent tradesget_orderbook(pair) - Get order bookget_candles(pair, interval, ...) - Get candlestick dataFutures Public Endpoints:
get_futures_candles(pair, from_time, to_time, resolution) - Get futures candlestick dataget_active_instruments(margin_currency_short_name) - Get list of active futures instrumentsget_instrument_details(pair, margin_currency_short_name) - Get detailed instrument informationget_futures_trade_history(pair) - Get real-time trade history for futuresAuthenticated Endpoints:
get_balances() - Get account balancesget_user_info() - Get user informationSpot Trading:
create_spot_order(market, side, order_type, total_quantity, ...) - Create spot orders (market/limit)Futures Trading:
create_futures_order(pair, side, order_type, total_quantity, ...) - Create futures orders (market/limit/stop/take-profit)list_futures_orders(side, status, ...) - List futures orders filtering by statusedit_futures_order(id, total_quantity, price, ...) - Edit open futures ordersSpot Trading:
Margin Trading:
Futures Trading:
WebSocket Streams:
You can customize the client behavior:
from coindcx import Client
client = Client(
api_key='your_key',
api_secret='your_secret',
timeout=60, # Request timeout in seconds (default: 30)
base_url='https://api.coindcx.com', # Override base URL if needed
public_url='https://public.coindcx.com', # Override public URL
)
coindcx-python/
βββ coindcx/
β βββ __init__.py
β βββ client.py # Main Client class
β βββ exceptions.py # Custom exceptions
β βββ enums.py # Enums and constants
β βββ endpoints/ # Modular endpoint implementations
β βββ __init__.py
β βββ market.py # Public market endpoints
β βββ spot.py # Spot trading
β βββ margin.py # Margin trading
β βββ futures.py # Futures trading
βββ examples/
β βββ basic_usage.py
βββ cli.py # Command-line interface tool
βββ setup.py
βββ requirements.txt
βββ README.md
# Set your API credentials as environment variables (optional)
export COINDCX_API_KEY="your_api_key"
export COINDCX_API_SECRET="your_api_secret"
# Run Python examples
python examples/basic_usage.py
python examples/futures_instruments.py # Futures instruments example
# Or use the CLI tool for quick testing
python cli.py get_markets
python cli.py get_ticker
python cli.py get_balances # Requires API credentials
python cli.py get_active_instruments --margin_currency_short_name=USDT
python cli.py get_instrument_details --pair=B-BTC_USDT
Security Notes:
CoinDCX enforces rate limits on API calls. The library will raise CoinDCXRateLimitException when limits are exceeded.
| Endpoint | Limit | Period |
|---|---|---|
| Create Order | 2000 | 60s |
| Cancel Order | 2000 | 60s |
| Order Status | 2000 | 60s |
| Active Orders | 300 | 60s |
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License
This library is not officially affiliated with CoinDCX. Use at your own risk. Trading cryptocurrencies carries risk - ensure you understand the risks before trading.
create_spot_order() for spot trading
create_futures_order() for futures trading
list_futures_orders() - List orders with status filtersedit_futures_order() - Edit open order quantity, price, and TP/SL triggersmake
OR
html-to-markdown ai/coindcx_documentation.html -o ai/coindcx_documentation.md
FAQs
Python wrapper for CoinDCX API with support for spot, margin, and futures trading
We found that coindcx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: whatβs affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.