Skip to content

Commit 7b671e2

Browse files
committed
Fixed some documentation issues
1 parent dbf3ed6 commit 7b671e2

8 files changed

Lines changed: 53 additions & 24 deletions

File tree

.cursor/rules/binance-net.mdc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This codebase uses **Binance.Net** for Binance cryptocurrency exchange access. D
1414

1515
```csharp
1616
using Binance.Net.Clients;
17+
using Binance.Net;
1718
using Binance.Net.Objects;
1819

1920
var restClient = new BinanceRestClient(options =>
@@ -36,10 +37,10 @@ var price = ticker.Data.LastPrice;
3637

3738
## API surface
3839

39-
- `restClient.SpotApi.{ExchangeData|Account|Trading|Margin|SubAccount|Brokerage}`
40+
- `restClient.SpotApi.{ExchangeData|Account|Trading}`
4041
- `restClient.UsdFuturesApi.{ExchangeData|Account|Trading}`
4142
- `restClient.CoinFuturesApi.{ExchangeData|Account|Trading}`
42-
- `restClient.GeneralApi.`{Brokerage|Futures|CryptoLoans|AutoInvest|Mining|SubAccount|Staking|SimpleEarn|CopyTrading|GiftCard|Nft}
43+
- `restClient.GeneralApi.{Brokerage|Futures|CryptoLoans|AutoInvest|Mining|SubAccount|Staking|SimpleEarn|CopyTrading|GiftCard|Nft}`
4344
- `socketClient.SpotApi.{ExchangeData|Account|Trading}` for WebSocket subscriptions and requests
4445
- `socketClient.UsdFuturesApi.{ExchangeData|Account|Trading}` for WebSocket subscriptions and requests
4546
- `socketClient.CoinFuturesApi.{ExchangeData|Account|Trading}` for WebSocket subscriptions
@@ -61,6 +62,7 @@ var socketClient = new BinanceSocketClient();
6162
var sub = await socketClient.SpotApi.ExchangeData.SubscribeToTickerUpdatesAsync(
6263
"BTCUSDT",
6364
update => { /* update.Data.LastPrice */ });
65+
if (!sub.Success) { /* sub.Error */ return; }
6466

6567
// On shutdown:
6668
await socketClient.UnsubscribeAsync(sub.Data);

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Never generate `HttpClient` calls to `api.binance.com` or `fapi.binance.com`. Al
1212

1313
```csharp
1414
using Binance.Net.Clients;
15+
using Binance.Net;
1516
using Binance.Net.Objects;
1617

1718
var restClient = new BinanceRestClient(options =>

CLAUDE.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Always create the client via `BinanceRestClient`. For trading, configure credent
2525

2626
```csharp
2727
using Binance.Net.Clients;
28+
using Binance.Net;
2829
using Binance.Net.Objects;
2930

3031
var restClient = new BinanceRestClient(options =>
@@ -102,8 +103,9 @@ var order = await restClient.UsdFuturesApi.Trading.PlaceOrderAsync(
102103
symbol: "ETHUSDT",
103104
side: OrderSide.Buy,
104105
type: FuturesOrderType.Market,
105-
quantity: 0.1m,
106-
positionSide: PositionSide.Long);
106+
quantity: 0.1m);
107+
108+
// In Hedge mode add positionSide: PositionSide.Long / PositionSide.Short.
107109
```
108110

109111
## Core Pattern: WebSocket Subscriptions
@@ -148,6 +150,7 @@ For exchange-agnostic code, use the unified shared interfaces. Same code works a
148150

149151
```csharp
150152
using Binance.Net.Clients;
153+
using Binance.Net;
151154
using CryptoExchange.Net.SharedApis;
152155

153156
var binanceShared = new BinanceRestClient().SpotApi.SharedClient;
@@ -166,13 +169,10 @@ Available shared client interfaces include: `ISpotTickerRestClient`, `ISpotOrder
166169
```csharp
167170
using Binance.Net;
168171

169-
services.AddBinance(restOptions =>
172+
services.AddBinance(options =>
170173
{
171-
restOptions.ApiCredentials = new BinanceCredentials("API_KEY", "API_SECRET");
172-
},
173-
socketOptions =>
174-
{
175-
socketOptions.ApiCredentials = new BinanceCredentials("API_KEY", "API_SECRET");
174+
options.Rest.ApiCredentials = new BinanceCredentials("API_KEY", "API_SECRET");
175+
options.Socket.ApiCredentials = new BinanceCredentials("API_KEY", "API_SECRET");
176176
});
177177

178178
// Inject IBinanceRestClient and IBinanceSocketClient into your services.
@@ -192,7 +192,7 @@ socketOptions =>
192192
## Environments
193193

194194
```csharp
195-
using Binance.Net.Objects;
195+
using Binance.Net;
196196

197197
// Live (default)
198198
var live = new BinanceRestClient(o => o.Environment = BinanceEnvironment.Live);
@@ -206,11 +206,11 @@ var us = new BinanceRestClient(o => o.Environment = BinanceEnvironment.Us);
206206

207207
## When the user wants other Binance features
208208

209-
- **Sub-accounts / Brokerage**: `restClient.SpotApi.SubAccount` and `Brokerage` namespaces
210-
- **Margin**: `restClient.SpotApi.Margin`
209+
- **Sub-accounts / Brokerage**: `restClient.GeneralApi.SubAccount` and `restClient.GeneralApi.Brokerage`
210+
- **Margin**: margin endpoints are under `restClient.SpotApi.Account` and `restClient.SpotApi.Trading`
211211
- **Wallet**: `restClient.SpotApi.Account` (deposit, withdrawal, asset details)
212-
- **Convert**: `restClient.SpotApi.Trading.ConvertAsync*`
213-
- **Portfolio Margin**: `restClient.SpotApi.PortfolioMargin`
212+
- **Convert**: `restClient.SpotApi.Trading.ConvertQuoteRequestAsync`, `ConvertAcceptQuoteAsync`, `GetConvertOrderStatusAsync`, etc.
213+
- **Portfolio Margin**: `restClient.SpotApi.Account.GetPortfolioMargin*` / `PortfolioMarginBankruptcyLoanRepayAsync`
214214
- **Options**: separate Options API (less commonly used)
215215

216216
## Reference

Examples/ai-friendly/01-spot-quickstart.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Substitute API_KEY / API_SECRET below
1111
// dotnet run
1212

13+
using Binance.Net;
1314
using Binance.Net.Clients;
1415
using Binance.Net.Enums;
1516
using Binance.Net.Objects;

Examples/ai-friendly/02-futures.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Setup: dotnet add package Binance.Net
77
// Substitute API_KEY / API_SECRET. The API key must have Futures trading enabled.
88

9+
using Binance.Net;
910
using Binance.Net.Clients;
1011
using Binance.Net.Enums;
1112
using Binance.Net.Objects;
@@ -29,13 +30,12 @@
2930

3031
// ---- 2. PLACE MARKET ORDER (open long position) ----
3132
// Market order — fills immediately at best available price.
32-
// PositionSide.Long required if account is in Hedge mode; ignore if One-way mode.
33+
// In Hedge mode add positionSide: PositionSide.Long.
3334
var openOrder = await client.UsdFuturesApi.Trading.PlaceOrderAsync(
3435
symbol: symbol,
3536
side: OrderSide.Buy,
3637
type: FuturesOrderType.Market,
37-
quantity: 0.01m,
38-
positionSide: PositionSide.Long);
38+
quantity: 0.01m);
3939

4040
if (!openOrder.Success)
4141
{
@@ -71,7 +71,6 @@
7171
side: OrderSide.Sell,
7272
type: FuturesOrderType.Market,
7373
quantity: Math.Abs(position.Quantity),
74-
positionSide: PositionSide.Long,
7574
reduceOnly: true);
7675

7776
if (closeOrder.Success)
@@ -84,5 +83,5 @@
8483
// Stop-market: type: FuturesOrderType.StopMarket, add stopPrice
8584
// Take-profit: type: FuturesOrderType.TakeProfitMarket, add stopPrice
8685
// COIN-M futures: use client.CoinFuturesApi.* (same API surface)
87-
// Hedge vs One-way: client.UsdFuturesApi.Account.ModifyPositionModeAsync(...)
86+
// Hedge mode: add positionSide: PositionSide.Long / PositionSide.Short to orders
8887
// Margin type: client.UsdFuturesApi.Account.ChangeMarginTypeAsync(symbol, FuturesMarginType.Isolated)

Examples/ai-friendly/03-websocket.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66
// Setup: dotnet add package Binance.Net
77

8+
using Binance.Net;
89
using Binance.Net.Clients;
910
using Binance.Net.Enums;
1011
using Binance.Net.Objects;
@@ -45,6 +46,13 @@
4546
}
4647
});
4748

49+
if (!klineSub.Success)
50+
{
51+
Console.WriteLine($"Failed to subscribe klines: {klineSub.Error}");
52+
await publicSocket.UnsubscribeAsync(tickerSub.Data);
53+
return;
54+
}
55+
4856
// ---- 2. AUTHENTICATED SOCKET CLIENT — for user data ----
4957
// User data stream pushes order updates, balance changes, position updates.
5058
var authSocket = new BinanceSocketClient(options =>
@@ -70,6 +78,14 @@
7078
Console.WriteLine($"Asset {update.Data.Asset} delta: {update.Data.BalanceDelta}");
7179
});
7280

81+
if (!userSub.Success)
82+
{
83+
Console.WriteLine($"Failed to subscribe user data: {userSub.Error}");
84+
await publicSocket.UnsubscribeAsync(tickerSub.Data);
85+
await publicSocket.UnsubscribeAsync(klineSub.Data);
86+
return;
87+
}
88+
7389
Console.WriteLine("All subscriptions active. Press Enter to teardown...");
7490
Console.ReadLine();
7591

Examples/ai-friendly/04-multi-exchange.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ async Task PrintTicker(ISpotTickerRestClient client, SharedSymbol symbol)
7878
if (!sub.Success)
7979
{
8080
Console.WriteLine($"Subscribe failed: {sub.Error}");
81+
return;
8182
}
8283

8384
Console.WriteLine("Press Enter to exit");
8485
Console.ReadLine();
8586

86-
await binanceTickerSocket.UnsubscribeAsync(sub.Data);
87+
await sub.Data.UnsubscribeAsync();
8788

8889
// Common variations:
8990
// Multi-exchange arbitrage: loop over List<ISpotTickerRestClient>, find max bid / min ask

Examples/ai-friendly/05-error-handling.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
//
55
// Setup: dotnet add package Binance.Net
66

7+
using Binance.Net;
78
using Binance.Net.Clients;
89
using Binance.Net.Enums;
910
using Binance.Net.Objects;
11+
using CryptoExchange.Net.Objects;
1012

1113
var client = new BinanceRestClient(options =>
1214
{
@@ -77,7 +79,9 @@ async Task<WebCallResult<T>> WithRetry<T>(
7779
//
7880
// var symbols = await client.SpotApi.ExchangeData.GetExchangeInfoAsync();
7981
// var symInfo = symbols.Data.Symbols.First(s => s.Name == "BTCUSDT");
80-
// var validQty = ExchangeHelpers.AdjustValueStep(rawQty, symInfo.LotSizeFilter!.StepSize);
82+
// var lotSize = symInfo.LotSizeFilter!;
83+
// var validQty = ExchangeHelpers.AdjustValueStep(
84+
// lotSize.MinQuantity, lotSize.MaxQuantity, lotSize.StepSize, RoundingType.Floor, rawQty);
8185
//
8286
// Code -1022 ("Signature for this request is not valid"):
8387
// API key / secret mismatch, or trying to use Spot key for Futures endpoint.
@@ -88,7 +92,7 @@ async Task<WebCallResult<T>> WithRetry<T>(
8892

8993
// ---- 4. ORDER PLACEMENT WITH FILTER VALIDATION ----
9094
var exchangeInfo = await client.SpotApi.ExchangeData.GetExchangeInfoAsync("BTCUSDT");
91-
if (!exchangeInfo.Success || exchangeInfo.Data.Symbols.Count == 0)
95+
if (!exchangeInfo.Success || exchangeInfo.Data.Symbols.Length == 0)
9296
{
9397
Console.WriteLine("Cannot fetch symbol info — aborting order");
9498
return;
@@ -99,7 +103,12 @@ async Task<WebCallResult<T>> WithRetry<T>(
99103

100104
// Round to allowed step size to avoid -1013 LOT_SIZE error
101105
decimal validQuantity = symbol.LotSizeFilter != null
102-
? CryptoExchange.Net.ExchangeHelpers.AdjustValueStep(rawQuantity, symbol.LotSizeFilter.StepSize)
106+
? CryptoExchange.Net.ExchangeHelpers.AdjustValueStep(
107+
symbol.LotSizeFilter.MinQuantity,
108+
symbol.LotSizeFilter.MaxQuantity,
109+
symbol.LotSizeFilter.StepSize,
110+
RoundingType.Floor,
111+
rawQuantity)
103112
: rawQuantity;
104113

105114
var order = await client.SpotApi.Trading.PlaceOrderAsync(

0 commit comments

Comments
 (0)