Skip to content

Commit a08f9dc

Browse files
Jose MejiaJose Mejia
authored andcommitted
Adding start time and end time to KandleStick method and changing Price Change method info to get data for all symbols.
1 parent 658fcd5 commit a08f9dc

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

Binance.API.Csharp.Client.Domain/Interfaces/IBinanceClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public interface IBinanceClient
5151
/// <param name="interval">Time interval to retreive.</param>
5252
/// <param name="limit">Limit of records to retrieve.</param>
5353
/// <returns></returns>
54-
Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, int limit = 500);
54+
Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, DateTime? startTime = null, DateTime? endTime = null, int limit = 500);
5555

5656
/// <summary>
5757
/// 24 hour price change statistics.
5858
/// </summary>
5959
/// <param name="symbol">Ticker symbol.</param>
6060
/// <returns></returns>
61-
Task<PriceChangeInfo> GetPriceChange24H(string symbol);
61+
Task<IEnumerable<PriceChangeInfo>> GetPriceChange24H(string symbol);
6262

6363
/// <summary>
6464
/// Latest price for all symbols.

Binance.API.Csharp.Client.Models/Market/PriceChangeInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Binance.API.Csharp.Client.Models.Market
44
{
55
public class PriceChangeInfo
66
{
7+
[JsonProperty("symbol")]
8+
public string Symbol { get; set; }
79
[JsonProperty("priceChange")]
810
public decimal PriceChange { get; set; }
911
[JsonProperty("priceChangePercent")]

Binance.API.Csharp.Client.Test/BinanceTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Binance.API.Csharp.Client.Test
99
public class BinanceTest
1010
{
1111
private static ApiClient apiClient = new ApiClient("@YourApiKey", "@YourApiSecret");
12-
private static BinanceClient binanceClient = new BinanceClient(apiClient);
12+
private static BinanceClient binanceClient = new BinanceClient(apiClient,false);
1313

1414
#region General
1515
[TestMethod]
@@ -35,7 +35,7 @@ public void GetOrderBook()
3535
[TestMethod]
3636
public void GetCandleSticks()
3737
{
38-
var candlestick = binanceClient.GetCandleSticks("ethbtc", TimeInterval.Minutes_15).Result;
38+
var candlestick = binanceClient.GetCandleSticks("ethbtc", TimeInterval.Minutes_15, new System.DateTime(2017,11,24), new System.DateTime(2017, 11, 26)).Result;
3939
}
4040

4141
[TestMethod]
@@ -47,7 +47,7 @@ public void GetAggregateTrades()
4747
[TestMethod]
4848
public void GetPriceChange24H()
4949
{
50-
var priceChangeInfo = binanceClient.GetPriceChange24H("ethbtc").Result;
50+
var priceChangeInfo = binanceClient.GetPriceChange24H().Result;
5151
}
5252

5353
[TestMethod]

Binance.API.Csharp.Client/BinanceClient.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class BinanceClient : BinanceClientAbstract, IBinanceClient
2222
/// </summary>
2323
/// <param name="apiClient">API client to be used for API calls.</param>
2424
/// <param name="loadTradingRules">Optional parameter to skip loading trading rules.</param>
25-
public BinanceClient(IApiClient apiClient, bool loadTradingRules = true) : base(apiClient)
25+
public BinanceClient(IApiClient apiClient, bool loadTradingRules = false) : base(apiClient)
2626
{
27-
if(loadTradingRules)
27+
if (loadTradingRules)
2828
{
2929
LoadTradingRules();
3030
}
@@ -164,14 +164,19 @@ public async Task<IEnumerable<AggregateTrade>> GetAggregateTrades(string symbol,
164164
/// <param name="interval">Time interval to retreive.</param>
165165
/// <param name="limit">Limit of records to retrieve.</param>
166166
/// <returns></returns>
167-
public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, int limit = 500)
167+
public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, DateTime? startTime = null, DateTime? endTime = null, int limit = 500)
168168
{
169169
if (string.IsNullOrWhiteSpace(symbol))
170170
{
171171
throw new ArgumentException("symbol cannot be empty. ", "symbol");
172172
}
173173

174-
var result = await _apiClient.CallAsync<dynamic>(ApiMethod.GET, EndPoints.Candlesticks, false, $"symbol={symbol.ToUpper()}&interval={interval.GetDescription()}&limit={limit}");
174+
var args = $"symbol={symbol.ToUpper()}&interval={interval.GetDescription()}"
175+
+ (startTime .HasValue ? $"&startTime={startTime.Value.GetUnixTimeStamp()}" : "")
176+
+ (endTime.HasValue ? $"&endTime={endTime.Value.GetUnixTimeStamp()}" : "")
177+
+ $"&limit={limit}";
178+
179+
var result = await _apiClient.CallAsync<dynamic>(ApiMethod.GET, EndPoints.Candlesticks, false, args);
175180

176181
var parser = new CustomParser();
177182
var parsedResult = parser.GetParsedCandlestick(result);
@@ -184,14 +189,11 @@ public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeI
184189
/// </summary>
185190
/// <param name="symbol">Ticker symbol.</param>
186191
/// <returns></returns>
187-
public async Task<PriceChangeInfo> GetPriceChange24H(string symbol)
192+
public async Task<IEnumerable<PriceChangeInfo>> GetPriceChange24H(string symbol = "")
188193
{
189-
if (string.IsNullOrWhiteSpace(symbol))
190-
{
191-
throw new ArgumentException("symbol cannot be empty. ", "symbol");
192-
}
194+
var args = string.IsNullOrWhiteSpace(symbol) ? "" : $"symbol={symbol.ToUpper()}";
193195

194-
var result = await _apiClient.CallAsync<PriceChangeInfo>(ApiMethod.GET, EndPoints.TickerPriceChange24H, false, $"symbol={symbol.ToUpper()}");
196+
var result = await _apiClient.CallAsync<IEnumerable< PriceChangeInfo>>(ApiMethod.GET, EndPoints.TickerPriceChange24H, false, args);
195197

196198
return result;
197199
}
@@ -461,8 +463,8 @@ public async Task<DepositHistory> GetDepositHistory(string asset, DepositStatus?
461463

462464
var args = $"asset={asset.ToUpper()}"
463465
+ (status.HasValue ? $"&status={(int)status}" : "")
464-
+ (startTime.HasValue ? $"&startTime={Utilities.GenerateTimeStamp(startTime.Value)}" : "")
465-
+ (endTime.HasValue ? $"&endTime={Utilities.GenerateTimeStamp(endTime.Value)}" : "")
466+
+ (startTime.HasValue ? $"&startTime={startTime.Value.GetUnixTimeStamp()}" : "")
467+
+ (endTime.HasValue ? $"&endTime={endTime.Value.GetUnixTimeStamp()}" : "")
466468
+ $"&recvWindow={recvWindow}";
467469

468470
var result = await _apiClient.CallAsync<DepositHistory>(ApiMethod.POST, EndPoints.DepositHistory, true, args);

Binance.API.Csharp.Client/Utils/ExtensionMethods.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,15 @@ public static string GetDescription(this Enum value)
2222
.Single(x => x.GetValue(null).Equals(value)),
2323
typeof(DescriptionAttribute)))?.Description ?? value.ToString();
2424
}
25+
26+
/// <summary>
27+
/// Gets a timestamp in milliseconds.
28+
/// </summary>
29+
/// <returns>Timestamp in milliseconds.</returns>
30+
public static string GetUnixTimeStamp(this DateTime baseDateTime)
31+
{
32+
var dtOffset = new DateTimeOffset(baseDateTime);
33+
return dtOffset.ToUnixTimeMilliseconds().ToString();
34+
}
2535
}
2636
}

0 commit comments

Comments
 (0)