The SharpCryptoExchange.Okx project delivers a powerful, open-source .NET 6 wrapper tailored for seamless integration with the OKX cryptocurrency exchange via its REST and WebSocket V5 APIs. Built on the robust foundation of the CryptoExchange.Net framework and forked from OKEx.Net, this library ensures clarity, performance, and modern .NET compatibility—perfect for developers building trading bots, analytics dashboards, or automated investment systems.
Whether you're retrieving real-time market data or managing complex trading strategies, this SDK simplifies interactions with OKX's full suite of services while maintaining clean, readable code architecture.
Why Use This .NET 6 Wrapper?
This library was created to address key gaps in the original implementation:
- Rebranded from OKEx to OKX to reflect the exchange’s updated identity and prevent user confusion.
- Updated dependencies ensure compatibility with modern development environments and security standards.
- Improved debugging capabilities make troubleshooting faster and more intuitive.
- Built on the proven CryptoExchange.Net, which offers built-in rate limiting, automatic retries, logging, and configuration flexibility.
With comprehensive support for both REST and WebSocket APIs, it empowers developers to build responsive, high-performance applications that interact efficiently with one of the world’s leading digital asset platforms.
Core Keywords
- OKX API
- .NET 6 wrapper
- WebSocket V5 API
- REST API client
- Crypto trading SDK
- Open source crypto library
- Real-time market data
- Algorithmic trading tools
These keywords are naturally integrated throughout the content to enhance search visibility without compromising readability.
Getting Started with OkxNet
To begin using the library, follow these straightforward steps:
- Clone the repository into your solution.
- Add a project reference to include
OkxNet. Import the namespace:
using OkxNet;
Two primary clients are available:
OkxClient: Handles all REST API requests (e.g., account balance, order placement).OkxSocketClient: Manages WebSocket connections for real-time updates (e.g., price feeds, order book changes).
Both clients implement IDisposable, so they can be safely used within using statements to manage resource cleanup.
Tip: For applications requiring live data—such as market monitoring or algorithmic execution—the WebSocket API is strongly recommended due to its full-duplex communication and lower latency compared to HTTP polling.
Leveraging WebSocket Feeds
WebSocket provides real-time streaming of public and private data, making it ideal for time-sensitive operations.
Public Market Data Subscriptions
You can subscribe to multiple public channels simultaneously:
var ws = new OkxSocketClient();
var pairs = new List<string> { "BTC-USDT", "ETH-USDT", "XRP-USDT" };
// Subscribe to tickers
foreach (var pair in pairs)
{
ws.SubscribeToTickers(pair, data =>
{
if (data != null) { /* Handle ticker update */ }
});
}
// Candlestick data every 5 minutes
ws.SubscribeToCandlesticks("BTC-USDT", OkxPeriod.FiveMinutes, data =>
{
if (data != null) { /* Process OHLC data */ }
});
// Order book with depth
ws.SubscribeToOrderBook("BTC-USDT", OkxOrderBookType.OrderBook, data =>
{
if (data?.Asks?.Any() == true && data?.Bids?.Any() == true)
{
/* Analyze bid/ask spread */
}
});Other supported public feeds include:
- Trades
- Mark prices
- Funding rates
- Index tickers
- System status alerts
Private User Data Streams
For authenticated access to personal account activity:
ws.SetApiCredentials("API_KEY", "API_SECRET", "PASSPHRASE");
// Listen for account balance changes
ws.SubscribeToAccountUpdates(data =>
{
if (data != null) { /* Update UI or trigger logic */ }
});
// Track open positions
ws.SubscribeToPositionUpdates(OkxInstrumentType.Futures, "BTC-USD", null, data =>
{
if (data != null) { /* React to position adjustments */ }
});
// Monitor order execution
ws.SubscribeToOrderUpdates(OkxInstrumentType.Spot, "BTC-USDT", null, data =>
{
if (data != null) { /* Log fills or cancellations */ }
});Private subscriptions enable real-time tracking of trades, balances, and algorithmic orders—critical for active traders and bot operators.
Using REST API Endpoints
While WebSockets excel at real-time data delivery, REST remains essential for stateful operations like placing orders or fetching historical records.
Public Endpoints (No Authentication Required)
Retrieve general market information:
var api = new OkxClient();
var instruments = api.GetInstruments(OkxInstrumentType.Spot);
var fundingRate = api.GetFundingRates("BTC-USD-SWAP");
var systemTime = api.GetSystemTime();Useful for:
- Listing tradable assets
- Checking open interest
- Accessing insurance fund levels
- Converting contract sizes to currency values
Trading Analytics with Rubik Endpoints
OKX provides advanced market insights through its Rubik analytics engine:
var longShortRatio = api.GetRubikLongShortRatio("BTC", OkxPeriod.OneDay);
var takerVolume = api.GetRubikTakerVolume("ETH", OkxInstrumentType.Spot);These endpoints help assess market sentiment and detect potential trend reversals.
Account & Trading Operations (Requires Authentication)
Securely manage your portfolio:
api.SetApiCredentials("KEY", "SECRET", "PASSPHRASE");
// Check balance and positions
var balance = api.GetAccountBalance();
var positions = api.GetAccountPositions();
// Place a market buy order
api.PlaceOrder("BTC-USDT", OkxTradeMode.Cash, OkxOrderSide.Buy, null,
OkxOrderType.MarketOrder, 0.01m);
// Withdraw funds
api.Withdraw("USDT", 100.0m, OkxWithdrawalDestination.DigitalCurrencyAddress,
"wallet_address", "pwd", 1.0m, "USDT-TRC20");Full support includes:
- Sub-account management
- Margin adjustments
- Fee rate queries
- Withdrawal history tracking
Frequently Asked Questions (FAQ)
What is the difference between REST and WebSocket APIs?
REST is request-response based—ideal for one-off queries like placing an order. WebSocket enables continuous, bidirectional data flow—perfect for live price updates or real-time order tracking.
Is this library thread-safe?
Yes. Thanks to its foundation on CryptoExchange.Net, the client handles synchronization internally, allowing safe use across multiple threads.
Can I use this wrapper for algorithmic trading?
Absolutely. With full access to order execution, real-time feeds, and historical data, it's well-suited for developing automated trading systems.
How do I handle API rate limits?
The underlying framework automatically manages rate limiting based on OKX’s policies. You can customize throttle behavior in the client settings if needed.
Does it support testnet environments?
Yes. Configuration options allow you to point the client to sandbox endpoints during development and testing.
Is there documentation available?
While formal docs are limited, the source code is well-commented, and examples cover most common use cases.
Ready to supercharge your crypto development workflow? This open-source .NET 6 wrapper makes integrating with OKX faster, safer, and more maintainable than ever before.