Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HitBTC.Connector

.NET License

High-performance, lock-free C# connector for HitBTC cryptocurrency exchange API v3.

✨ Features

πŸš€ High Performance β€” Lock-free data structures, zero-allocation hot paths, ArrayPool usage

πŸ”’ Thread-Safe β€” MPSC queues, concurrent collections, safe for multi-threaded trading

πŸ“‘ REST API β€” Full support for public, spot, and futures endpoints

πŸ”Œ WebSocket β€” Real-time market data and order updates

πŸ” Authentication β€” HS256 HMAC signature with automatic request signing

πŸ’ͺ Robust β€” Safe decimal parsing, comprehensive error handling

πŸ§ͺ Tested β€” Unit, integration, and stress tests included

πŸ“¦ Installation

dotnet add package HitBTC.Connector

Or add to your .csproj:

<PackageReference Include="HitBTC.Connector" Version="1.0.0" />

πŸš€ Quick Start

REST Client β€” Public Data

using HitBTC.Connector.Rest;
using HitBTC.Connector.Core.Models;

// Public API (no authentication required)
await using var client = new HitBtcRestClient("", "");

// Get symbols
var symbols = await client.GetSymbolsAsync();
var btcUsdt = symbols["BTCUSDT"];
Console.WriteLine($"BTCUSDT tick size: {btcUsdt.TickSize}");

// Get order book
using var orderBook = await client.GetOrderBookAsync("BTCUSDT", depth: 10);
Console.WriteLine($"Best bid: {orderBook.Bids[0].Price}, Best ask: {orderBook.Asks[0].Price}");
Console.WriteLine($"Spread: {orderBook.Asks[0].Price - orderBook.Bids[0].Price}");

// Get candles
var candles = await client.GetCandlesAsync("BTCUSDT", CandlePeriod.H1, limit: 24);
foreach (var c in candles)
{
    Console.WriteLine($"{c.Timestamp:HH:mm} O:{c.Open} H:{c.High} L:{c.Low} C:{c.Close}");
}

REST Client β€” Spot Trading

await using var client = new HitBtcRestClient("YOUR_API_KEY", "YOUR_SECRET_KEY");

// Get active orders
var orders = await client.GetActiveSpotOrdersAsync();

// Place limit order
var order = await client.CreateSpotOrderAsync(new CreateSpotOrderRequest
{
    Symbol = "BTCUSDT",
    Side = OrderSide.Buy,
    Quantity = 0.001m,
    Price = 50000m,
    Type = OrderType.Limit,
    TimeInForce = TimeInForce.GTC,
    PostOnly = true
});
Console.WriteLine($"Order placed: {order.ClientOrderId}");

// Replace order
var replaced = await client.ReplaceSpotOrderAsync(order.ClientOrderId, new ReplaceSpotOrderRequest
{
    Quantity = 0.002m,
    Price = 49000m
});

// Cancel order
var canceled = await client.CancelSpotOrderAsync(replaced.ClientOrderId);

// Cancel all orders
await client.CancelAllSpotOrdersAsync(symbol: "BTCUSDT");

REST Client β€” Futures Trading

await using var client = new HitBtcRestClient("YOUR_API_KEY", "YOUR_SECRET_KEY");

// Get futures balance
var balances = await client.GetFuturesBalanceAsync();
foreach (var b in balances)
{
    Console.WriteLine($"{b.Currency}: {b.Available} available");
}

// Create/update margin account
var account = await client.CreateOrUpdateMarginAccountAsync(
    MarginMode.Isolated,
    "BTCUSDT_PERP",
    marginBalance: 100m,
    leverage: 25m
);

// Place futures order
var futuresOrder = await client.CreateFuturesOrderAsync(new CreateFuturesOrderRequest
{
    Symbol = "BTCUSDT_PERP",
    Side = OrderSide.Buy,
    Quantity = 0.01m,
    Price = 50000m,
    Type = OrderType.Limit,
    MarginMode = MarginMode.Isolated,
    ReduceOnly = false
});

// Close position
await client.CloseFuturesPositionAsync(
    MarginMode.Isolated,
    "BTCUSDT_PERP",
    new ClosePositionRequest { Price = 51000m }
);

// Close margin account (withdraw all funds)
await client.CloseMarginAccountAsync(MarginMode.Isolated, "BTCUSDT_PERP");

πŸ“‹ API Coverage

REST API

Category Endpoints Status
Public Symbols, OrderBook, Candles, Trades βœ…
Spot Trading Get/Create/Replace/Cancel Orders βœ…
Futures Trading Orders, Positions, Margin Accounts βœ…
Futures Balance Get Balance by Currency βœ…
Margin Management Create/Update/Close Accounts, Leverage βœ…

⚑ Performance Features

- Lock-Free Object Pool β€” Reuse objects without locks

- MPSC Queue β€” Multi-producer single-consumer for WebSocket messages

- ValueStringBuilder β€” Stack-allocated string building

- ArrayPool β€” Rent/return buffers for OrderBook levels

- Span/Memory β€” Zero-copy data access where possible

- SocketsHttpHandler β€” HTTP/2, connection pooling

About

High-performance connector for HitBTC cryptocurrency exchange API v3.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages