SharpCryptoExchange.Okx: A Comprehensive .NET 6 API Wrapper for OKX REST and WebSocket V5 APIs

·

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

Installation

  1. Clone the Repository:

    git clone https://github.com/crx-master/SharpCryptoExchange.Okx.git
  2. 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:

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.

👉 Start trading on OKX today


Release Notes

For updates, check the VERSION file.


Conclusion

SharpCryptoExchange.Okx simplifies OKX integration for .NET developers, offering:

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.

👉 Get started with OKX API


### Keywords:
1. OKX API  
2. .NET 6 wrapper  
3. Cryptocurrency exchange  
4. WebSocket V5  
5. REST API  
6. Trading bot  
7. Market data