Introduction
SharpCryptoExchange.Okx is an open-source .NET 6 API wrapper designed to interact seamlessly with the OKX cryptocurrency exchange via its REST and WebSocket V5 APIs. This library provides a robust, developer-friendly interface to access all features offered by OKX, including trading, account management, and market data retrieval.
Built upon the CryptoExchange.Net framework, this wrapper ensures high performance, reliability, and maintainability. It was forked from OKEx.Net to address rebranding (OKEx → OKX) and dependency updates, eliminating confusion for new users.
Key Features
- Full API Coverage: Supports all OKX V5 REST and WebSocket endpoints.
- Object-Oriented Design: Clear, readable objects for easy integration.
- WebSocket Efficiency: Real-time data streaming for market updates and order book depth.
- Cross-Platform: Compatible with any .NET 6+ application (Windows, Linux, macOS).
Installation
Clone the Repository:
git clone https://github.com/crx-master/SharpCryptoExchange.Okx.git- Add Reference: Include the project in your solution and reference it in your .NET application.
Getting Started
Namespace Setup
using OkxNet;Client Initialization
Two primary clients are available:
OkxClient: For REST API interactions.OkxSocketClient: For WebSocket connections.
Example:
using var restClient = new OkxClient();
using var socketClient = new OkxSocketClient();👉 Explore OKX API documentation
WebSocket API Examples
Public Feeds
Subscribe to real-time market data:
var ws = new OkxSocketClient();
var samplePairs = new List<string> { "BTC-USDT", "ETH-USDT" };
// Ticker Subscriptions
foreach (var pair in samplePairs)
{
ws.SubscribeToTickers(pair, data =>
{
Console.WriteLine($"Ticker Update: {data.LastPrice}");
});
}
// Order Book Subscription
ws.SubscribeToOrderBook("BTC-USDT", OkexOrderBookType.OrderBook, data =>
{
Console.WriteLine($"Ask: {data.Asks[0].Price}, Bid: {data.Bids[0].Price}");
});Private Feeds (Authentication Required)
ws.SetApiCredentials("API_KEY", "API_SECRET", "API_PASSPHRASE");
// Account Updates
ws.SubscribeToAccountUpdates(data =>
{
Console.WriteLine($"Balance Update: {data.TotalEquity}");
});REST API Examples
Public Endpoints
var api = new OkxClient();
var instruments = api.GetInstruments(OkexInstrumentType.Spot);
var ticker = api.GetTicker("BTC-USDT");Authenticated Endpoints
api.SetApiCredentials("API_KEY", "API_SECRET", "API_PASSPHRASE");
// Account Balance
var balance = api.GetAccountBalance();
// Place Order
var order = api.PlaceOrder(
instrumentId: "BTC-USDT",
tradeMode: OkexTradeMode.Cash,
side: OkexOrderSide.Buy,
type: OkexOrderType.MarketOrder,
size: 0.1m
);FAQ Section
Q1: How do I handle WebSocket disconnections?
A: The OkxSocketClient automatically reconnects. Use the OnConnectionLost event for custom logic.
Q2: What’s the rate limit for OKX APIs?
A: Refer to OKX rate limits. The wrapper includes built-in rate-limiting.
Q3: Can I use this for algorithmic trading?
A: Yes! The library supports all order types (market, limit, stop-loss) and algo orders.
Release Notes
For updates, check the VERSION file.
Conclusion
SharpCryptoExchange.Okx simplifies OKX integration for .NET developers, offering:
- Comprehensive API coverage.
- Real-time WebSocket support.
- Secure authentication.
Whether you’re building a trading bot, portfolio tracker, or market analyzer, this wrapper provides the tools needed to interact efficiently with OKX’s advanced trading platform.
### Keywords:
1. OKX API
2. .NET 6 wrapper
3. Cryptocurrency exchange
4. WebSocket V5
5. REST API
6. Trading bot
7. Market data