LX C SDK
High-performance C client for LX trading.
Features
- WebSocket client using libwebsockets
- Async event-driven architecture
- Full orderbook management
- Order placement, modification, cancellation
- Market data subscriptions
- Thread-safe with minimal locking
- C11 with no external dependencies beyond libwebsockets
Requirements
- CMake 3.10+
- C11 compiler (GCC, Clang)
- libwebsockets 4.0+
- pthread
macOS
Linux (Debian/Ubuntu)
Build
Options
Usage
Basic Connection
Placing Orders
Market Data Subscriptions
Local Orderbook Management
API Reference
Client Lifecycle
| Function |
Description |
lxdex_init() |
Initialize library (call once) |
lxdex_cleanup() |
Cleanup library (call once) |
lxdex_client_new(config) |
Create client |
lxdex_client_set_callbacks(client, cb) |
Set event callbacks |
lxdex_client_connect(client) |
Connect to DEX |
lxdex_client_auth(client) |
Authenticate |
lxdex_client_disconnect(client) |
Disconnect |
lxdex_client_free(client) |
Free client |
lxdex_client_state(client) |
Get connection state |
lxdex_client_service(client, timeout_ms) |
Process events |
Orders
| Function |
Description |
lxdex_place_order(client, order, &id) |
Place order |
lxdex_cancel_order(client, id) |
Cancel order |
lxdex_modify_order(client, id, price, size) |
Modify order |
lxdex_order_init(order) |
Initialize order struct |
lxdex_order_limit(order, sym, side, price, size) |
Create limit order |
lxdex_order_market(order, sym, side, size) |
Create market order |
Market Data
| Function |
Description |
lxdex_subscribe_orderbook(client, symbol) |
Subscribe to orderbook |
lxdex_subscribe_trades(client, symbol) |
Subscribe to trades |
lxdex_unsubscribe(client, channel) |
Unsubscribe |
Orderbook Utilities
| Function |
Description |
lxdex_orderbook_init(book, capacity) |
Initialize orderbook |
lxdex_orderbook_free(book) |
Free orderbook |
lxdex_orderbook_best_bid(book) |
Get best bid |
lxdex_orderbook_best_ask(book) |
Get best ask |
lxdex_orderbook_spread(book) |
Get spread |
lxdex_orderbook_mid(book) |
Get mid price |
Error Handling
| Function |
Description |
lxdex_strerror(err) |
Error code to string |
lxdex_last_error() |
Get last error message |
Error Codes
| Code |
Description |
LXDEX_OK |
Success |
LXDEX_ERR_INVALID_ARG |
Invalid argument |
LXDEX_ERR_NO_MEMORY |
Out of memory |
LXDEX_ERR_CONNECTION |
Connection error |
LXDEX_ERR_TIMEOUT |
Operation timed out |
LXDEX_ERR_AUTH |
Authentication failed |
LXDEX_ERR_PARSE |
JSON parse error |
LXDEX_ERR_PROTOCOL |
Protocol error |
LXDEX_ERR_RATE_LIMIT |
Rate limit exceeded |
LXDEX_ERR_ORDER_REJECTED |
Order rejected |
LXDEX_ERR_NOT_CONNECTED |
Not connected |
Connection States
| State |
Description |
LXDEX_STATE_DISCONNECTED |
Not connected |
LXDEX_STATE_CONNECTING |
Connection in progress |
LXDEX_STATE_CONNECTED |
Connected, not authenticated |
LXDEX_STATE_AUTHENTICATED |
Connected and authenticated |
LXDEX_STATE_ERROR |
Error state |
Thread Safety
- The client is thread-safe for sending messages from multiple threads
- Callbacks are invoked from the service thread
- Use external synchronization if callbacks access shared data
Performance
- Event-driven, non-blocking I/O
- Lock-free message queue for sends
- Minimal allocations in hot path
- Binary search for orderbook operations
Example
Run the basic example:
With authentication and test order:
License
Copyright (c) 2025 Lux Partners Limited. All rights reserved.