Overview
OKEx.Net is a comprehensive .NET wrapper for the OKEx V5 API, providing developers with easy access to both REST and WebSocket functionalities. This open-source solution offers clear, readable objects that simplify interaction with OKEx's cryptocurrency trading platform.
Migration Notice
๐ We strongly recommend migrating to OKX.Api for continued updates and to avoid issues related to CryptoExchange.Net dependencies. The new package offers improved functionality and maintenance.
Key Features
Full API Coverage: Supports all OKEx V5 features including:
- Spot, margin, futures, options, and swap trading
- Account management
- Funding operations
- Market data streams
WebSocket Implementation: Real-time updates for:
- Order books
- Tickers
- Trades
- Account balances
- Structured Objects: Well-organized C# classes that mirror OKEx's API structure
Implementation Details
Built upon the CryptoExchange.Net library, this wrapper inherits its robust WebSocket handling and connection management features.
Technical Foundation
- CryptoExchange.Net: Core networking functionality
- Newtonsoft.Json: For JSON serialization
- Async/Await: Fully asynchronous API calls
Getting Started
Installation
PM> Install-Package OKEx.NetBasic Usage
using Okex.Net;
// REST Client
var client = new OkexClient();
// WebSocket Client
var socketClient = new OkexSocketClient();API Examples
REST API Endpoints
Public Market Data
var instruments = client.GetInstruments(OkexInstrumentType.Spot);
var ticker = client.GetTicker("BTC-USDT");Account Management (Authenticated)
client.SetApiCredentials("API_KEY", "API_SECRET", "PASSPHRASE");
var balance = client.GetAccountBalance();WebSocket Subscriptions
Real-time Order Book
socketClient.SubscribeToOrderBook("BTC-USDT", OkexOrderBookType.OrderBook, data =>
{
// Handle updates
});Private Account Updates
socketClient.SetApiCredentials("API_KEY", "API_SECRET", "PASSPHRASE");
socketClient.SubscribeToAccountUpdates(data =>
{
// Handle balance changes
});Best Practices
- Connection Management: Always dispose clients properly
- Error Handling: Implement robust exception handling
- Rate Limiting: Respect OKEx's API rate limits
- WebSocket Reconnection: Implement automatic reconnection logic
FAQ
Q: How do I migrate from OKEx.Net to OKX.Api?
A: Update your NuGet package reference and modify any namespace references from Okex.Net to OKX.Api.
Q: What's the difference between REST and WebSocket APIs?
A: REST is for request-response operations while WebSocket provides real-time streaming data.
Q: How do I handle authentication?
A: Use the SetApiCredentials method with your API key, secret, and passphrase.
Q: Where can I report issues?
A: Issues can be reported on the GitHub repository's issue tracker.
Q: Is there support for algorithmic orders?
A: Yes, through both REST and WebSocket interfaces.
Conclusion
OKEx.Net provides a powerful, developer-friendly way to integrate with OKEx's trading platform. Whether you're building trading bots, analytical tools, or portfolio management applications, this wrapper simplifies complex API interactions.