Skip to content

Commit

Permalink
Update to System.Text.Json (#1398)
Browse files Browse the repository at this point in the history
* Switch from Newtonsoft.Json implementation to System.Text.Json for (de)serialization
* Refactored from old per type enum converter to EnumConverter usage
* Updated CryptoExchange.Net to 7.10.0
* Added SpotApi.Account.GetCommissionRatesAsync endpoint
* Added UsdFuturesApi.Account.GetSymbolConfigurationAsync endpoint
* Added UsdFuturesApi.Account.GetAccountConfigurationAsync endpoint
* Added UsdFuturesApi.Trading.GetPositionsAsync endpoint
* Added PermissionSets property to SpotApi.ExchangeData.GetExchangeInfoAsync symbol response
* Updated UsdFuturesApi.Account.GetBalancesAsync to V3
* Updated UsdFuturesApi.Account.GetAccountInfoAsync to V3
  • Loading branch information
JKorf committed Jul 27, 2024
1 parent 12c4d23 commit ad49a81
Show file tree
Hide file tree
Showing 880 changed files with 7,485 additions and 12,615 deletions.
13 changes: 5 additions & 8 deletions Binance.Net.UnitTests/BinanceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Requests;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -16,10 +15,8 @@
using Binance.Net.Objects.Options;
using NUnit.Framework.Legacy;
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Converters.JsonNet;
using System.Linq.Expressions;
using System.Threading;
using CryptoExchange.Net;
using CryptoExchange.Net.Converters.SystemTextJson;
using System.Text.Json;

namespace Binance.Net.UnitTests
{
Expand All @@ -33,7 +30,7 @@ public async Task GetServerTime_Should_RespondWithServerTimeDateTime(long milise
// arrange
DateTime expected = new DateTime(1970, 1, 1).AddMilliseconds(milisecondsTime);
var time = new BinanceCheckTime() { ServerTime = expected };
var client = TestHelpers.CreateResponseClient(JsonConvert.SerializeObject(time));
var client = TestHelpers.CreateResponseClient(JsonSerializer.Serialize(time));

// act
var result = await client.SpotApi.ExchangeData.GetServerTimeAsync();
Expand Down Expand Up @@ -200,7 +197,7 @@ public void CheckSignatureExample1()
{ "price", "0.1" },
{ "recvWindow", "5000" },
},
DateTimeConverter.ParseFromLong(1499827319559),
DateTimeConverter.ParseFromString("1499827319559"),
true,
false);
}
Expand Down Expand Up @@ -231,7 +228,7 @@ public void CheckSignatureExample2()
{ "price", "0.1" },
{ "recvWindow", "5000" },
},
DateTimeConverter.ParseFromLong(1499827319559),
DateTimeConverter.ParseFromString("1499827319559"),
true,
false);
}
Expand Down
33 changes: 17 additions & 16 deletions Binance.Net.UnitTests/BinanceRestIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Binance.Net.Clients;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Testing;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -87,6 +84,7 @@ public async Task TestSpotAccount()
await RunAndCheckResult(client => client.SpotApi.Account.GetIsolatedMarginFeeDataAsync(default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetTradeFeeAsync(default, default, default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetAccountVipLevelAndStatusAsync(default, default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetCommissionRatesAsync("ETHUSDT", default, default), true);

// Not available without margin account
//await RunAndCheckResult(client => client.SpotApi.Account.GetMarginTransferHistoryAsync(Enums.TransferDirection.RollOut, default, default, default, default, default, default, default), true);
Expand All @@ -109,7 +107,7 @@ public async Task TestSpotExchangeData()
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetServerTimeAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetSystemStatusAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAssetDetailsAsync(5000, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAssetDetailsAsync(5000, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetProductsAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetOrderBookAsync("ETHUSDT", 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetRecentTradesAsync("ETHUSDT", 1, CancellationToken.None), false);
Expand All @@ -125,17 +123,17 @@ public async Task TestSpotExchangeData()
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetPriceAsync("ETHUSDT", CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetPricesAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetBookPriceAsync("ETHUSDT", CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginAssetsAsync(null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginSymbolsAsync(null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginPriceIndexAsync("ETHUSDT", CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetIsolatedMarginSymbolsAsync("ETHUSDT", 5000, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokenInfoAsync(5000, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginAssetsAsync(null, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginSymbolsAsync(null, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginPriceIndexAsync("ETHUSDT", CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetIsolatedMarginSymbolsAsync("ETHUSDT", 5000, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokenInfoAsync(5000, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokensHistoricalKlinesAsync("ETHUP", Enums.KlineInterval.OneHour, null, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetCrossMarginCollateralRatioAsync(null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetFutureHourlyInterestRateAsync(new[] { "ETH" }, false, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetCrossMarginCollateralRatioAsync(null, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetFutureHourlyInterestRateAsync(new[] { "ETH" }, false, null, CancellationToken.None), true);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginDelistScheduleAsync(null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetConvertListAllPairsAsync(null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetDelistScheduleAsync(null, CancellationToken.None), false);
await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetDelistScheduleAsync(null, CancellationToken.None), true);

// Needs more permissions
//await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetConvertQuantityPrecisionPerAssetAsync(null, CancellationToken.None), false);
Expand Down Expand Up @@ -174,14 +172,16 @@ public async Task TestUsdFuturesAccount()
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetIncomeHistoryAsync(default, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetBracketsAsync(default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetPositionAdlQuantileEstimationAsync(default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetAccountInfoAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetAccountInfoAsync(default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetBalancesAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetMultiAssetsModeAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetPositionInformationAsync(default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetTradingStatusAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetUserCommissionRateAsync("ETHUSDT", default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetOrderRateLimitAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetBnbBurnStatusAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetSymbolConfigurationAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Account.GetAccountConfigurationAsync(default), true);
}

[Test]
Expand All @@ -192,7 +192,7 @@ public async Task TestUsdFuturesExchangeData()
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetOrderBookAsync("ETHUSDT", 5, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetRecentTradesAsync("ETHUSDT", 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT", 1, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT", 1, null, CancellationToken.None), true);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetAggregatedTradeHistoryAsync("ETHUSDT", null, null, null, 10, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetFundingInfoAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetFundingRatesAsync("ETHUSDT", null, null, null, CancellationToken.None), false);
Expand Down Expand Up @@ -227,6 +227,7 @@ public async Task TestUsdFuturesTrading()
await RunAndCheckResult(client => client.UsdFuturesApi.Trading.GetUserTradesAsync("ETHUSDT", default, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Trading.GetOpenAlgoOrdersAsync(default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Trading.GetClosedAlgoOrdersAsync(default, default, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.UsdFuturesApi.Trading.GetPositionsAsync(default, default), true);
}

[Test]
Expand All @@ -251,7 +252,7 @@ public async Task TestCoinFuturesExchangeData()
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetOrderBookAsync("ETHUSD_PERP", 5, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetRecentTradesAsync("ETHUSD_PERP", 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSD_PERP", 1, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSD_PERP", 1, null, CancellationToken.None), true);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetAggregatedTradeHistoryAsync("ETHUSD_PERP", null, null, null, 10, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetKlinesAsync("ETHUSD_PERP", Enums.KlineInterval.OneHour, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTickersAsync(null, null, CancellationToken.None), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ POST
true
{
"leverage": 21,
"maxQty": "1000", // maximum quantity of base asset
"maxQty": "1000",
"symbol": "BTCUSD_200925"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ true
{
"assets": [
{
"asset": "BTC", // asset name
"walletBalance": "0.00241969", // total wallet balance
"unrealizedProfit": "0.00000000", // unrealized profit or loss
"marginBalance": "0.00241969", // margin balance
"maintMargin": "0.00000000", // maintenance margin
"initialMargin": "0.00000000", // total intial margin required with the latest mark price
"positionInitialMargin": "0.00000000", // positions margin required with the latest mark price
"openOrderInitialMargin": "0.00000000", // open orders intial margin required with the latest mark price
"maxWithdrawAmount": "0.00241969", // available amount for transfer out
"crossWalletBalance": "0.00241969", // wallet balance for crossed margin
"crossUnPnl": "0.00000000", // total unrealized profit or loss of crossed positions
"availableBalance": "0.00241969", // available margin balance
"updateTime": 1625474304765 //update time
"asset": "BTC",
"walletBalance": "0.00241969",
"unrealizedProfit": "0.00000000",
"marginBalance": "0.00241969",
"maintMargin": "0.00000000",
"initialMargin": "0.00000000",
"positionInitialMargin": "0.00000000",
"openOrderInitialMargin": "0.00000000",
"maxWithdrawAmount": "0.00241969",
"crossWalletBalance": "0.00241969",
"crossUnPnl": "0.00000000",
"availableBalance": "0.00241969",
"updateTime": 1625474304765
}
],
"positions": [
{
"symbol": "BTCUSD_201225",
"positionAmt":"0", // position amount
"positionAmt":"0",
"initialMargin": "0",
"maintMargin": "0",
"unrealizedProfit": "0.00000000",
"positionInitialMargin": "0",
"openOrderInitialMargin": "0",
"leverage": "125",
"isolated": false,
"positionSide": "BOTH", // BOTH means that it is the position of Oneway Mode
"positionSide": "BOTH",
"entryPrice": "0.0",
"breakEvenPrice": "0.0", // breakeven price
"maxQty": "50", // maximum quantity of base asset
"breakEvenPrice": "0.0",
"maxQty": "50",
"updateTime": 0
},
{
Expand All @@ -46,9 +46,9 @@ true
"openOrderInitialMargin": "0",
"leverage": "125",
"isolated": false,
"positionSide": "LONG", // LONG or SHORT means that it is the position of Hedge Mode
"positionSide": "LONG",
"entryPrice": "0.0",
"breakEvenPrice": "0.0", // breakeven price
"breakEvenPrice": "0.0",
"maxQty": "50",
"updateTime": 0
},
Expand All @@ -62,9 +62,9 @@ true
"openOrderInitialMargin": "0",
"leverage": "125",
"isolated": false,
"positionSide": "SHORT", // LONG or SHORT means that it is the position of Hedge Mode
"positionSide": "SHORT",
"entryPrice": "0.0",
"breakEvenPrice": "0.0", // breakeven price
"breakEvenPrice": "0.0",
"maxQty": "50",
"updateTime":1627026881327
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GET
true
[
{
"accountAlias": "SgsR", // unique account code
"accountAlias": "SgsR",
"asset": "BTC",
"balance": "0.00250000",
"withdrawAvailable": "0.00250000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ true
[
{
"symbol": "BTCUSD_PERP",
"notionalCoef": 1.50, //user symbol bracket multiplier, only appears when user's symbol bracket is adjusted
"notionalCoef": 1.50,
"brackets": [
{
"bracket": 1, // bracket level
"initialLeverage": 125, // the maximum leverage
"qtyCap": 50, // upper edge of base asset quantity
"qtylFloor": 0, // lower edge of base asset quantity
"maintMarginRatio": 0.004, // maintenance margin rate
"cum": 0.0 // Auxiliary number for quick calculation
},
"bracket": 1,
"initialLeverage": 125,
"qtyCap": 50,
"qtylFloor": 0,
"maintMarginRatio": 0.004,
"cum": 0.0
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ GET
/dapi/v1/income/asyn
true
{
"avgCostTimestampOfLast30d":7241837, // Average time taken for data download in the past 30 days
"downloadId":"546975389218332672",
"avgCostTimestampOfLast30d":7241837,
"downloadId":"546975389218332672"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ GET
true
{
"downloadId":"545923594199212032",
"status":"completed", // Enum completed processing
"url":"www.binance.com", // The link is mapped to download id
"notified":true, // ignore
"expirationTimestamp":1645009771000, // The link would expire after this timestamp
"isExpired":null,
}
"status":"completed",
"url":"www.binance.com",
"notified":true,
"expirationTimestamp":1645009771000,
"isExpired":null
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ GET
true
[
{
"symbol": "", // trade symbol, if existing
"incomeType": "TRANSFER", // income type
"income": "-0.37500000", // income amount
"asset": "BTC", // income asset
"info":"WITHDRAW", // extra information
"symbol": "",
"incomeType": "TRANSFER",
"income": "-0.37500000",
"asset": "BTC",
"info":"WITHDRAW",
"time": 1570608000000,
"tranId":"9689322392", // transaction id
"tradeId":"" // trade id, if existing
"tranId":"9689322392",
"tradeId":""
},
{
"symbol": "BTCUSD_200925",
Expand Down
Loading

0 comments on commit ad49a81

Please sign in to comment.