Skip to content

Development #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Binance.API.Csharp.Client.Domain/Interfaces/IBinanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public interface IBinanceClient
/// <param name="interval">Time interval to retreive.</param>
/// <param name="limit">Limit of records to retrieve.</param>
/// <returns></returns>
Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, int limit = 500);
Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, DateTime? startTime = null, DateTime? endTime = null, int limit = 500);

/// <summary>
/// 24 hour price change statistics.
/// </summary>
/// <param name="symbol">Ticker symbol.</param>
/// <returns></returns>
Task<PriceChangeInfo> GetPriceChange24H(string symbol);
Task<IEnumerable<PriceChangeInfo>> GetPriceChange24H(string symbol);

/// <summary>
/// Latest price for all symbols.
Expand Down
2 changes: 2 additions & 0 deletions Binance.API.Csharp.Client.Models/Market/PriceChangeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Binance.API.Csharp.Client.Models.Market
{
public class PriceChangeInfo
{
[JsonProperty("symbol")]
public string Symbol { get; set; }
[JsonProperty("priceChange")]
public decimal PriceChange { get; set; }
[JsonProperty("priceChangePercent")]
Expand Down
6 changes: 3 additions & 3 deletions Binance.API.Csharp.Client.Test/BinanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Binance.API.Csharp.Client.Test
public class BinanceTest
{
private static ApiClient apiClient = new ApiClient("@YourApiKey", "@YourApiSecret");
private static BinanceClient binanceClient = new BinanceClient(apiClient);
private static BinanceClient binanceClient = new BinanceClient(apiClient,false);

#region General
[TestMethod]
Expand All @@ -35,7 +35,7 @@ public void GetOrderBook()
[TestMethod]
public void GetCandleSticks()
{
var candlestick = binanceClient.GetCandleSticks("ethbtc", TimeInterval.Minutes_15).Result;
var candlestick = binanceClient.GetCandleSticks("ethbtc", TimeInterval.Minutes_15, new System.DateTime(2017,11,24), new System.DateTime(2017, 11, 26)).Result;
}

[TestMethod]
Expand All @@ -47,7 +47,7 @@ public void GetAggregateTrades()
[TestMethod]
public void GetPriceChange24H()
{
var priceChangeInfo = binanceClient.GetPriceChange24H("ethbtc").Result;
var priceChangeInfo = binanceClient.GetPriceChange24H().Result;
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions Binance.API.Csharp.Client/Binance.API.Csharp.Client.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package >
<metadata>
<id>Binance.API.Csharp.Client</id>
<version>1.2.0</version>
<version>1.2.1</version>
<title>Binance.API.Csharp.Client</title>
<authors>Jose Mejia</authors>
<owners>Jose Mejia</owners>
<projectUrl>https://github.com/morpheums/Binance.API.Csharp.Helper</projectUrl>
<iconUrl>https://github.com/morpheums/Binance.API.Csharp.Client/blob/master/Binance.API.Csharp.Client/BinanceLogo.png?raw=true</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>C#.NET client for Binance Exchange API.</description>
<releaseNotes>Fixing issue when calling "LoadTradingRules" method.</releaseNotes>
<releaseNotes>Fixing issue including dependencies dlls.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Criptocurrency Binance API dotnet csharp wrapper</tags>
<dependencies>
Expand Down
26 changes: 14 additions & 12 deletions Binance.API.Csharp.Client/BinanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class BinanceClient : BinanceClientAbstract, IBinanceClient
/// </summary>
/// <param name="apiClient">API client to be used for API calls.</param>
/// <param name="loadTradingRules">Optional parameter to skip loading trading rules.</param>
public BinanceClient(IApiClient apiClient, bool loadTradingRules = true) : base(apiClient)
public BinanceClient(IApiClient apiClient, bool loadTradingRules = false) : base(apiClient)
{
if(loadTradingRules)
if (loadTradingRules)
{
LoadTradingRules();
}
Expand Down Expand Up @@ -164,14 +164,19 @@ public async Task<IEnumerable<AggregateTrade>> GetAggregateTrades(string symbol,
/// <param name="interval">Time interval to retreive.</param>
/// <param name="limit">Limit of records to retrieve.</param>
/// <returns></returns>
public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, int limit = 500)
public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeInterval interval, DateTime? startTime = null, DateTime? endTime = null, int limit = 500)
{
if (string.IsNullOrWhiteSpace(symbol))
{
throw new ArgumentException("symbol cannot be empty. ", "symbol");
}

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

var result = await _apiClient.CallAsync<dynamic>(ApiMethod.GET, EndPoints.Candlesticks, false, args);

var parser = new CustomParser();
var parsedResult = parser.GetParsedCandlestick(result);
Expand All @@ -184,14 +189,11 @@ public async Task<IEnumerable<Candlestick>> GetCandleSticks(string symbol, TimeI
/// </summary>
/// <param name="symbol">Ticker symbol.</param>
/// <returns></returns>
public async Task<PriceChangeInfo> GetPriceChange24H(string symbol)
public async Task<IEnumerable<PriceChangeInfo>> GetPriceChange24H(string symbol = "")
{
if (string.IsNullOrWhiteSpace(symbol))
{
throw new ArgumentException("symbol cannot be empty. ", "symbol");
}
var args = string.IsNullOrWhiteSpace(symbol) ? "" : $"symbol={symbol.ToUpper()}";

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

return result;
}
Expand Down Expand Up @@ -461,8 +463,8 @@ public async Task<DepositHistory> GetDepositHistory(string asset, DepositStatus?

var args = $"asset={asset.ToUpper()}"
+ (status.HasValue ? $"&status={(int)status}" : "")
+ (startTime.HasValue ? $"&startTime={Utilities.GenerateTimeStamp(startTime.Value)}" : "")
+ (endTime.HasValue ? $"&endTime={Utilities.GenerateTimeStamp(endTime.Value)}" : "")
+ (startTime.HasValue ? $"&startTime={startTime.Value.GetUnixTimeStamp()}" : "")
+ (endTime.HasValue ? $"&endTime={endTime.Value.GetUnixTimeStamp()}" : "")
+ $"&recvWindow={recvWindow}";

var result = await _apiClient.CallAsync<DepositHistory>(ApiMethod.POST, EndPoints.DepositHistory, true, args);
Expand Down
10 changes: 10 additions & 0 deletions Binance.API.Csharp.Client/Utils/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@ public static string GetDescription(this Enum value)
.Single(x => x.GetValue(null).Equals(value)),
typeof(DescriptionAttribute)))?.Description ?? value.ToString();
}

/// <summary>
/// Gets a timestamp in milliseconds.
/// </summary>
/// <returns>Timestamp in milliseconds.</returns>
public static string GetUnixTimeStamp(this DateTime baseDateTime)
{
var dtOffset = new DateTimeOffset(baseDateTime);
return dtOffset.ToUnixTimeMilliseconds().ToString();
}
}
}