Skip to content

Commit e063174

Browse files
committed
BDN Issues - 4.2.0 Release (#32)
* Added the LowPrice property to the SymbolPriceChangeTickerResponse class. * Added BNB pairs and switched symbol name order. * Added feature exchangeInfo API endpoint. * Split classes to own files. * Using OrderType enum in ExchangeInfoSymbol. Added possible new values for OrderType enum, LIMIT_MAKER, STOP_LOSS_LIMIT, TAKE_PROFIT_LIMIT. * Added REPSONSE, FULL, ACK to CreateOrder, and changed rogue doubles for decimals * ExchangeInfoOrderType as new enum. ExchangeInfoFilterType new type of json converter. * Price property changed to decimal instead of double for any precision conversion problems * Error message logging fix * FloatParseHandling for queryStringCreation and Test * Adjusted types, fields * Version change in assembly * Removing Price mandatory guard * Removed private setters. * Removed private from setter. * Expanded the number of available order types. * Access Level of GenerateQueryStringFromData reverted to private * GenerateQueryStringFromData_DecimalConversion deleted from GeneralEndpointTests
1 parent 35c2d07 commit e063174

33 files changed

+523
-72
lines changed

BinanceExchange.API/APIProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private async Task<T> HandleResponse<T>(HttpResponseMessage message, string requ
8282
if (errorObject == null) throw new BinanceException("Unexpected Error whilst handling the response", null);
8383
errorObject.RequestMessage = requestMessage;
8484
var exception = CreateBinanceException(message.StatusCode, errorObject);
85-
_logger.Error($"Error Message Received:", exception);
85+
_logger.Error($"Error Message Received:{errorJson}", exception);
8686
throw exception;
8787
}
8888

BinanceExchange.API/BinanceExchange.API.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net451;net452;net461;</TargetFrameworks>
4-
<Version>4.0.1</Version>
4+
<Version>4.2.0</Version>
55
<Description>The Binance CryptoCurrency exchange C# wrapper of the API. It is built in dotnet core, supports all REST and WebSocket endpoints, has full logging capabilities, a built in Cache for selected endpoints, a Rate limiter and more. Enjoy Binance API data, fast and reliably.</Description>
66
<Title>Binance Cryptocurrency Exchange - C# API in .NET</Title>
77
<PackageId>BinanceDotNet</PackageId>
@@ -14,9 +14,9 @@
1414
<PackageLicenseUrl>https://github.com/glitch100/BinanceDotNet/blob/master/LICENSE</PackageLicenseUrl>
1515
<RepositoryUrl>https://github.com/glitch100/BinanceDotNet</RepositoryUrl>
1616
<PackageIconUrl>https://i.imgur.com/x2YPVe6.png</PackageIconUrl>
17-
<PackageReleaseNotes>Fixed bug around QueryOrder</PackageReleaseNotes>
18-
<AssemblyVersion>4.0.1.0</AssemblyVersion>
19-
<FileVersion>4.0.1.0</FileVersion>
17+
<PackageReleaseNotes>Adjusted fields types, and removed required param, improved order response types, other imrpovements and additions</PackageReleaseNotes>
18+
<AssemblyVersion>4.2.0.0</AssemblyVersion>
19+
<FileVersion>4.2.0.0</FileVersion>
2020
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
2121
</PropertyGroup>
2222
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

BinanceExchange.API/Client/BinanceClient.cs

+26-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
using System.Threading.Tasks;
44
using BinanceExchange.API.Caching;
55
using BinanceExchange.API.Client.Interfaces;
6+
using BinanceExchange.API.Enums;
67
using BinanceExchange.API.Models.Request;
78
using BinanceExchange.API.Models.Response;
9+
using BinanceExchange.API.Models.Response.Abstract;
810
using BinanceExchange.API.Utility;
911
using log4net;
1012

@@ -113,6 +115,16 @@ public async Task<ServerTimeResponse> GetServerTime()
113115
{
114116
return await _apiProcessor.ProcessGetRequest<ServerTimeResponse>(Endpoints.General.ServerTime);
115117
}
118+
119+
/// <summary>
120+
/// Current exchange trading rules and symbol information
121+
/// </summary>
122+
/// <returns><see cref="ExchangeInfoResponse"/></returns>
123+
public async Task<ExchangeInfoResponse> GetExchangeInfo()
124+
{
125+
return await _apiProcessor.ProcessGetRequest<ExchangeInfoResponse>(Endpoints.General.ExchangeInfo);
126+
}
127+
116128
#endregion
117129

118130
#region Market Data
@@ -206,17 +218,26 @@ public async Task<List<SymbolOrderBookResponse>> GetSymbolOrderBookTicker()
206218
/// Creates an order based on the provided request
207219
/// </summary>
208220
/// <param name="request">The <see cref="CreateOrderRequest"/> that is used to define the order</param>
209-
/// <returns></returns>
210-
public async Task<CreateOrderResponse> CreateOrder(CreateOrderRequest request)
221+
/// <returns>This method can return <see cref="AcknowledgeCreateOrderResponse"/>, <see cref="FullCreateOrderResponse"/>
222+
/// or <see cref="ResultCreateOrderResponse"/> based on the provided NewOrderResponseType enum in the request.
223+
/// </returns>
224+
public async Task<BaseCreateOrderResponse> CreateOrder(CreateOrderRequest request)
211225
{
212226
Guard.AgainstNull(request.Symbol);
213227
Guard.AgainstNull(request.Side);
214228
Guard.AgainstNull(request.Type);
215-
Guard.AgainstNull(request.TimeInForce);
216229
Guard.AgainstNull(request.Quantity);
217-
Guard.AgainstNull(request.Price);
218230

219-
return await _apiProcessor.ProcessPostRequest<CreateOrderResponse>(Endpoints.Account.NewOrder(request));
231+
switch (request.NewOrderResponseType)
232+
{
233+
case NewOrderResponseType.Acknowledge:
234+
return await _apiProcessor.ProcessPostRequest<AcknowledgeCreateOrderResponse>(Endpoints.Account.NewOrder(request));
235+
case NewOrderResponseType.Full:
236+
return await _apiProcessor.ProcessPostRequest<FullCreateOrderResponse>(Endpoints.Account.NewOrder(request));
237+
default:
238+
return await _apiProcessor.ProcessPostRequest<ResultCreateOrderResponse>(Endpoints.Account.NewOrder(request));
239+
}
240+
220241
}
221242

222243
/// <summary>
@@ -229,9 +250,7 @@ public async Task<EmptyResponse> CreateTestOrder(CreateOrderRequest request)
229250
Guard.AgainstNull(request.Symbol);
230251
Guard.AgainstNull(request.Side);
231252
Guard.AgainstNull(request.Type);
232-
Guard.AgainstNull(request.TimeInForce);
233253
Guard.AgainstNull(request.Quantity);
234-
Guard.AgainstNull(request.Price);
235254

236255
return await _apiProcessor.ProcessPostRequest<EmptyResponse>(Endpoints.Account.NewOrderTest(request));
237256
}

BinanceExchange.API/Client/Interfaces/IBinanceClient.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using BinanceExchange.API.Models.Request;
44
using BinanceExchange.API.Models.Response;
5+
using BinanceExchange.API.Models.Response.Abstract;
56

67
namespace BinanceExchange.API.Client.Interfaces
78
{
@@ -85,7 +86,7 @@ public interface IBinanceClient
8586
/// </summary>
8687
/// <param name="request">The <see cref="CreateOrderRequest"/> that is used to define the order</param>
8788
/// <returns></returns>
88-
Task<CreateOrderResponse> CreateOrder(CreateOrderRequest request);
89+
Task<BaseCreateOrderResponse> CreateOrder(CreateOrderRequest request);
8990

9091
/// <summary>
9192
/// Queries an order based on the provided request
@@ -149,5 +150,11 @@ public interface IBinanceClient
149150
/// <param name="receiveWindow"></param>
150151
/// <returns></returns>
151152
Task<DepositListResponse> GetDepositHistory(FundHistoryRequest request, int receiveWindow = 5000);
153+
154+
/// <summary>
155+
/// Current exchange trading rules and symbol information
156+
/// </summary>
157+
Task<ExchangeInfoResponse> GetExchangeInfo();
158+
152159
}
153160
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Linq;
6+
using BinanceExchange.API.Models.Response;
7+
using BinanceExchange.API.Models.Response.Error;
8+
using BinanceExchange.API.Enums;
9+
10+
namespace BinanceExchange.API.Converter
11+
{
12+
public class ExchangeInfoSymbolFilterConverter : JsonConverter
13+
{
14+
public override bool CanWrite => false;
15+
16+
public override bool CanConvert(Type objectType) => false;
17+
18+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
19+
{
20+
JObject jObject = JObject.Load(reader);
21+
var value = jObject.ToObject<ExchangeInfoSymbolFilter>();
22+
23+
ExchangeInfoSymbolFilter item = null;
24+
25+
switch (value.FilterType)
26+
{
27+
case ExchangeInfoSymbolFilterType.PriceFilter:
28+
item = new ExchangeInfoSymbolFilterPrice();
29+
break;
30+
case ExchangeInfoSymbolFilterType.LotSize:
31+
item = new ExchangeInfoSymbolFilterLotSize();
32+
break;
33+
case ExchangeInfoSymbolFilterType.MinNotional:
34+
item = new ExchangeInfoSymbolFilterMinNotional();
35+
break;
36+
}
37+
38+
serializer.Populate(jObject.CreateReader(), item);
39+
return item;
40+
}
41+
42+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
43+
{
44+
throw new NotImplementedException();
45+
}
46+
}
47+
}

BinanceExchange.API/Endpoints.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static class Endpoints
1717
Formatting = Formatting.Indented,
1818
ContractResolver = new CamelCasePropertyNamesContractResolver(),
1919
NullValueHandling = NullValueHandling.Ignore,
20+
FloatParseHandling = FloatParseHandling.Decimal
2021
};
2122

2223

@@ -78,6 +79,12 @@ public static class General
7879
/// Test connectivity to the Rest API and get the current server time.
7980
/// </summary>
8081
public static BinanceEndpointData ServerTime => new BinanceEndpointData(new Uri($"{APIPrefix}/{ApiVersion}/time"), EndpointSecurityType.None);
82+
83+
/// <summary>
84+
/// Current exchange trading rules and symbol information.
85+
/// </summary>
86+
public static BinanceEndpointData ExchangeInfo => new BinanceEndpointData(new Uri($"{APIPrefix}/{ApiVersion}/exchangeInfo"), EndpointSecurityType.None);
87+
8188
}
8289

8390
public static class MarketData
@@ -208,7 +215,7 @@ private static string GenerateQueryStringFromData(IRequest request)
208215
throw new Exception("No request data provided - query string can't be created");
209216
}
210217
//TODO: Refactor to not require double JSON loop
211-
var obj = (JObject)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(request, _settings));
218+
var obj = (JObject)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(request, _settings), _settings);
212219

213220
return String.Join("&", obj.Children()
214221
.Cast<JProperty>()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace BinanceExchange.API.Enums
4+
{
5+
public enum ExchangeInfoOrderType
6+
{
7+
[EnumMember(Value = "LIMIT")]
8+
Limit,
9+
[EnumMember(Value = "MARKET")]
10+
Market,
11+
[EnumMember(Value = "LIMIT_MAKER")]
12+
LimitMaker,
13+
[EnumMember(Value = "STOP_LOSS_LIMIT")]
14+
StopLossLimit,
15+
[EnumMember(Value = "TAKE_PROFIT_LIMIT")]
16+
TakeProfitLimit
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Converters;
3+
using System.Runtime.Serialization;
4+
5+
namespace BinanceExchange.API.Enums
6+
{
7+
public enum ExchangeInfoSymbolFilterType
8+
{
9+
[EnumMember(Value = "PRICE_FILTER")]
10+
PriceFilter,
11+
[EnumMember(Value = "LOT_SIZE")]
12+
LotSize,
13+
[EnumMember(Value = "MIN_NOTIONAL")]
14+
MinNotional
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace BinanceExchange.API.Enums
4+
{
5+
public enum NewOrderResponseType
6+
{
7+
[EnumMember(Value = "RESULT")]
8+
Result,
9+
[EnumMember(Value = "ACK")]
10+
Acknowledge,
11+
[EnumMember(Value = "FULL")]
12+
Full,
13+
}
14+
}

BinanceExchange.API/Enums/OrderType.cs

+10
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@ public enum OrderType
88
Limit,
99
[EnumMember(Value = "MARKET")]
1010
Market,
11+
[EnumMember(Value = "STOP_LOSS")]
12+
StopLoss,
13+
[EnumMember(Value = "STOP_LOSS_LIMIT")]
14+
StopLossLimit,
15+
[EnumMember(Value = "TAKE_PROFIT")]
16+
TakeProfit,
17+
[EnumMember(Value = "TAKE_PROFIT_LIMIT")]
18+
TakeProfitLimit,
19+
[EnumMember(Value = "LIMIT_MAKER")]
20+
LimitMaker,
1121
}
1222
}

BinanceExchange.API/Market/TradingPairSymbols.cs

+37-19
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,43 @@ public static class USDTPairs
2323
/// </summary>
2424
public static class BNBPairs
2525
{
26-
public static readonly string BNB_BTC = "BNBBTC";
27-
public static readonly string BNB_ETH = "BNBETH";
28-
public static readonly string BNB_VEN = "BNBVEN";
29-
public static readonly string BNB_POWR = "BNBPOWR";
30-
public static readonly string BNB_RCN = "BNBRCN";
31-
public static readonly string BNB_NULS = "BNBNULS";
32-
public static readonly string BNB_DLT = "BNBDLT";
33-
public static readonly string BNB_WTC = "BNBWTC";
34-
public static readonly string BNB_AMB = "BNBAMB";
35-
public static readonly string BNB_BCC = "BNBBCC";
36-
public static readonly string BNB_BAT = "BNBBAT";
37-
public static readonly string BNB_BCPT = "BNBBCPT";
38-
public static readonly string BNB_NEO = "BNBNEO";
39-
public static readonly string BNB_QSP = "BNBQSP";
40-
public static readonly string BNB_BTS = "BNBBTS";
41-
public static readonly string BNB_XZC = "BNBXZC";
42-
public static readonly string BNB_LSK = "BNBLSK";
43-
public static readonly string BNB_IOTA = "BNBIOTA";
44-
public static readonly string BNB_ADX = "BNBADX";
26+
public static readonly string ADX_BNB = "ADXBNB";
27+
public static readonly string AION_BNB = "AION_BNB";
28+
public static readonly string AMB_BNB = "AMBBNB";
29+
public static readonly string APPC_BNB = "APPCBNB";
30+
public static readonly string BAT_BNB = "BATBNB";
31+
public static readonly string BCC_BNB = "BCCBNB";
32+
public static readonly string BCPT_BNB = "BCPTBNB";
33+
public static readonly string BRD_BNB = "BRDBNB";
34+
public static readonly string BTS_BNB = "BTSBNB";
35+
public static readonly string CMT_BNB = "CMTBNB";
36+
public static readonly string CND_BNB = "CNDBNB";
37+
public static readonly string DLT_BNB = "DLTBNB";
38+
public static readonly string ETH_BNB = "ETHBNB";
39+
public static readonly string GTO_BNB = "GTOBNB";
40+
public static readonly string ICX_BNB = "ICXBNB";
41+
public static readonly string IOTA_BNB = "IOTABNB";
42+
public static readonly string LSK_BNB = "LSKBNB";
43+
public static readonly string LTC_BNB = "LTCBNB";
44+
public static readonly string MCO_BNB = "MCOBNB";
45+
public static readonly string NAV_BNB = "NAVBNB";
46+
public static readonly string NEBL_BNB = "NEBLBNB";
47+
public static readonly string NEO_BNB = "NEOBNB";
48+
public static readonly string NULS_BNB = "NULSBNB";
49+
public static readonly string OST_BNB = "OSTBNB";
50+
public static readonly string POWR_BNB = "POWRBNB";
51+
public static readonly string QSP_BNB = "QSPBNB";
52+
public static readonly string RCN_BNB = "RCNBNB";
53+
public static readonly string RDN_BNB = "RDNBNB";
54+
public static readonly string RLC_BNB = "RLCBNB";
55+
public static readonly string TRIG_BNB = "TRIGBNB";
56+
public static readonly string VEN_BNB = "VENBNB";
57+
public static readonly string WABI_BNB = "WABIBNB";
58+
public static readonly string WAVES_BNB = "WAVESBNB";
59+
public static readonly string WTC_BNB = "WTCBNB";
60+
public static readonly string XLM_BNB = "XLM_BNB";
61+
public static readonly string XZC_BNB = "XZCBNB";
62+
public static readonly string YOYO_BNB = "YOYOBNB";
4563
}
4664

4765
/// <summary>

BinanceExchange.API/Models/Request/CreateOrderRequest.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class CreateOrderRequest: IRequest
3131
public decimal Quantity { get; set; }
3232

3333
[DataMember(Order = 6)]
34-
public double Price { get; set; }
34+
public decimal? Price { get; set; }
3535

3636
[DataMember(Order = 7)]
3737
public string NewClientOrderId { get; set; }
@@ -42,5 +42,10 @@ public class CreateOrderRequest: IRequest
4242
[DataMember(Order = 9)]
4343
[JsonProperty("icebergQty")]
4444
public decimal? IcebergQuantity { get; set; }
45+
46+
[DataMember(Order = 10)]
47+
[JsonProperty("newOrderRespType")]
48+
[JsonConverter(typeof(StringEnumConverter))]
49+
public NewOrderResponseType NewOrderResponseType { get; set; }
4550
}
4651
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using BinanceExchange.API.Converter;
4+
using BinanceExchange.API.Models.Request.Interfaces;
5+
using Newtonsoft.Json;
6+
7+
namespace BinanceExchange.API.Models.Request
8+
{
9+
/// <summary>
10+
/// Request object used to retrieve exchange information
11+
/// </summary>
12+
[DataContract]
13+
public class ExchangeInfo : IRequest
14+
{
15+
}
16+
}

0 commit comments

Comments
 (0)