@@ -203,18 +203,17 @@ protected internal override async Task<IEnumerable<ExchangeMarket>> OnGetMarketS
203
203
204
204
protected override async Task < ExchangeTicker > OnGetTickerAsync ( string marketSymbol )
205
205
{
206
- JToken obj = await MakeJsonRequestAsync < JToken > ( "/ticker/24hr?symbol=" + marketSymbol ) ;
206
+ JToken obj = await MakeJsonRequestAsync < JToken > ( "/ticker/24hr?symbol=" + marketSymbol , BaseUrlApi ) ;
207
207
return await ParseTickerAsync ( marketSymbol , obj ) ;
208
208
}
209
209
210
210
protected override async Task < IEnumerable < KeyValuePair < string , ExchangeTicker > > > OnGetTickersAsync ( )
211
211
{
212
212
List < KeyValuePair < string , ExchangeTicker > > tickers = new List < KeyValuePair < string , ExchangeTicker > > ( ) ;
213
- string marketSymbol ;
214
- JToken obj = await MakeJsonRequestAsync < JToken > ( "/ticker/24hr" ) ;
213
+ JToken obj = await MakeJsonRequestAsync < JToken > ( "/ticker/24hr" , BaseUrlApi ) ;
215
214
foreach ( JToken child in obj )
216
215
{
217
- marketSymbol = child [ "symbol" ] . ToStringInvariant ( ) ;
216
+ string marketSymbol = child [ "symbol" ] . ToStringInvariant ( ) ;
218
217
tickers . Add ( new KeyValuePair < string , ExchangeTicker > ( marketSymbol , await ParseTickerAsync ( marketSymbol , child ) ) ) ;
219
218
}
220
219
return tickers ;
@@ -308,7 +307,7 @@ protected override async Task<IWebSocket> OnGetDeltaOrderBookWebSocketAsync(Acti
308
307
309
308
protected override async Task < ExchangeOrderBook > OnGetOrderBookAsync ( string marketSymbol , int maxCount = 100 )
310
309
{
311
- JToken obj = await MakeJsonRequestAsync < JToken > ( "/depth?symbol=" + marketSymbol + " &limit=" + maxCount ) ;
310
+ JToken obj = await MakeJsonRequestAsync < JToken > ( $ "/depth?symbol={ marketSymbol } &limit={ maxCount } " , BaseUrlApi ) ;
312
311
return ExchangeAPIExtensions . ParseOrderBookFromJTokenArrays ( obj , sequence : "lastUpdateId" , maxCount : maxCount ) ;
313
312
}
314
313
@@ -348,21 +347,17 @@ protected override async Task OnGetHistoricalTradesAsync(Func<IEnumerable<Exchan
348
347
349
348
protected override async Task < IEnumerable < ExchangeTrade > > OnGetRecentTradesAsync ( string marketSymbol , int ? limit = null )
350
349
{
351
- List < ExchangeTrade > trades = new List < ExchangeTrade > ( ) ;
352
- //var maxRequestLimit = 1000; //hard coded for now, should add limit as an argument
353
- //https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#compressedaggregate-trades-list
354
- int maxRequestLimit = ( limit == null || limit < 1 || limit > 1000 ) ? 1000 : ( int ) limit ;
355
-
356
- JToken obj = await MakeJsonRequestAsync < JToken > ( $ "/aggTrades?symbol={ marketSymbol } &limit={ maxRequestLimit } ") ;
357
- //JToken obj = await MakeJsonRequestAsync<JToken>("/public/trades/" + marketSymbol + "?limit=" + maxRequestLimit + "?sort=DESC");
358
- if ( obj . HasValues ) { //
359
- foreach ( JToken token in obj ) {
360
- var trade = token . ParseTrade ( "q" , "p" , "m" , "T" , TimestampType . UnixMilliseconds , "a" , "false" ) ;
361
- trades . Add ( trade ) ;
362
- }
350
+ //https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md
351
+ var trades = new List < ExchangeTrade > ( ) ;
352
+ var maxRequestLimit = ( limit == null || limit < 1 || limit > 1000 ) ? 1000 : ( int ) limit ;
353
+
354
+ JToken obj = await MakeJsonRequestAsync < JToken > ( $ "/aggTrades?symbol={ marketSymbol } &limit={ maxRequestLimit } ", BaseUrlApi ) ;
355
+ if ( obj . HasValues )
356
+ {
357
+ trades . AddRange ( obj . Select ( token =>
358
+ token . ParseTrade ( "q" , "p" , "m" , "T" , TimestampType . UnixMilliseconds , "a" , "false" ) ) ) ;
363
359
}
364
360
return trades . AsEnumerable ( ) . Reverse ( ) ; //Descending order (ie newest trades first)
365
- //return trades;
366
361
}
367
362
368
363
public async Task OnGetHistoricalTradesAsync ( Func < IEnumerable < ExchangeTrade > , bool > callback , string marketSymbol , long startId , long ? endId = null )
@@ -462,9 +457,8 @@ public async Task OnGetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bo
462
457
}
463
458
464
459
465
-
466
-
467
- protected override async Task < IEnumerable < MarketCandle > > OnGetCandlesAsync ( string marketSymbol , int periodSeconds , DateTime ? startDate = null , DateTime ? endDate = null , int ? limit = null )
460
+ protected override async Task < IEnumerable < MarketCandle > > OnGetCandlesAsync ( string marketSymbol ,
461
+ int periodSeconds , DateTime ? startDate = null , DateTime ? endDate = null , int ? limit = null )
468
462
{
469
463
/* [
470
464
[
@@ -482,25 +476,25 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(strin
482
476
"17928899.62484339" // Can be ignored
483
477
]] */
484
478
485
- List < MarketCandle > candles = new List < MarketCandle > ( ) ;
486
479
string url = "/klines?symbol=" + marketSymbol ;
487
480
if ( startDate != null )
488
481
{
489
482
url += "&startTime=" + ( long ) startDate . Value . UnixTimestampFromDateTimeMilliseconds ( ) ;
490
- url += "&endTime=" + ( ( endDate == null ? long . MaxValue : ( long ) endDate . Value . UnixTimestampFromDateTimeMilliseconds ( ) ) ) . ToStringInvariant ( ) ;
483
+ url += "&endTime=" +
484
+ ( ( endDate == null ? long . MaxValue : ( long ) endDate . Value . UnixTimestampFromDateTimeMilliseconds ( ) ) )
485
+ . ToStringInvariant ( ) ;
491
486
}
487
+
492
488
if ( limit != null )
493
489
{
494
490
url += "&limit=" + ( limit . Value . ToStringInvariant ( ) ) ;
495
491
}
492
+
496
493
url += "&interval=" + PeriodSecondsToString ( periodSeconds ) ;
497
- JToken obj = await MakeJsonRequestAsync < JToken > ( url ) ;
498
- foreach ( JToken token in obj )
499
- {
500
- candles . Add ( this . ParseCandle ( token , marketSymbol , periodSeconds , 1 , 2 , 3 , 4 , 0 , TimestampType . UnixMilliseconds , 5 , 7 ) ) ;
501
- }
494
+ JToken obj = await MakeJsonRequestAsync < JToken > ( url , BaseUrlApi ) ;
502
495
503
- return candles ;
496
+ return obj . Select ( token => this . ParseCandle ( token , marketSymbol , periodSeconds , 1 , 2 , 3 , 4 , 0 ,
497
+ TimestampType . UnixMilliseconds , 5 , 7 ) ) . ToList ( ) ;
504
498
}
505
499
506
500
protected override async Task < Dictionary < string , decimal > > OnGetAmountsAsync ( )
@@ -582,7 +576,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
582
576
throw new InvalidOperationException ( "Binance single order details request requires symbol" ) ;
583
577
}
584
578
payload [ "symbol" ] = marketSymbol ! ;
585
-
579
+
586
580
if ( isClientOrderId ) // Either orderId or origClientOrderId must be sent.
587
581
payload [ "origClientOrderId" ] = orderId ;
588
582
else
0 commit comments