@@ -15,8 +15,8 @@ import zip from 'lodash.zipobject'
1515import stringHash from 'string-hash' ;
1616import async from 'async' ;
1717
18- import { Interval , PositionRisk , Order , FuturesOrder , PositionSide , WorkingType , OrderType , OrderStatus , TimeInForce , Callback , IConstructorArgs , OrderSide , FundingRate , CancelOrder , AggregatedTrade , Trade , MyTrade , WithdrawHistoryResponse , DepositHistoryResponse , DepositAddress , WithdrawResponse , Candle , FuturesCancelAllOpenOrder , OrderBook , Ticker , FuturesUserTrade , Account , FuturesAccountInfo , FuturesBalance } from './types'
19- export { Interval , PositionRisk , Order , FuturesOrder , PositionSide , WorkingType , OrderType , OrderStatus , TimeInForce , Callback , IConstructorArgs } from './types'
18+ import { Interval , PositionRisk , Order , FuturesOrder , PositionSide , WorkingType , OrderType , OrderStatus , TimeInForce , Callback , IConstructorArgs , OrderSide , FundingRate , CancelOrder , AggregatedTrade , Trade , MyTrade , WithdrawHistoryResponse , DepositHistoryResponse , DepositAddress , WithdrawResponse , Candle , FuturesCancelAllOpenOrder , OrderBook , Ticker , FuturesUserTrade , Account , FuturesAccountInfo , FuturesBalance , QueryOrder } from './types'
19+ // export {Interval, PositionRisk, Order, FuturesOrder, PositionSide, WorkingType, OrderType, OrderStatus, TimeInForce, Callback, IConstructorArgs} from './types'
2020
2121export interface Dictionary < T > {
2222 [ key : string ] : T ;
@@ -111,8 +111,9 @@ export default class Binance {
111111 }
112112
113113 options ( opt = { } , callback : any = false ) : Binance {
114- // return await this.setOptions(opt, callback); // keep this method for backwards compatibility
115- this . assignOptions ( opt , callback ) ;
114+ // // return await this.setOptions(opt, callback); // keep this method for backwards compatibility
115+ // this.assignOptions(opt, callback);
116+ this . setOptions ( opt , callback ) ;
116117 return this ;
117118 }
118119
@@ -160,6 +161,7 @@ export default class Binance {
160161 if ( this . Options . useServerTime ) {
161162
162163 const res = await this . publicRequest ( this . getSpotUrl ( ) + 'v3/time' ) ;
164+ console . log ( res )
163165 this . info . timeOffset = res . serverTime - new Date ( ) . getTime ( ) ;
164166
165167 }
@@ -268,7 +270,7 @@ export default class Binance {
268270 reqOptions . body = urlBody ;
269271 } else {
270272 if ( opt . qs ) {
271- opt . url += '?' + this . makeQueryString ( opt . qs ) ;
273+ // opt.url += '?' + this.makeQueryString(opt.qs);
272274 }
273275 }
274276 const response = await fetch ( opt . url , reqOptions )
@@ -315,7 +317,8 @@ export default class Binance {
315317 }
316318
317319 async publicRequest ( url : string , data : Dict = { } , method = 'GET' ) {
318- let opt = this . reqObj ( url , data , method ) ;
320+ const query = this . makeQueryString ( data ) ;
321+ const opt = this . reqObj ( url + ( query ? '?' + query : '' ) , data , method ) ;
319322 const res = await this . proxyRequest ( opt ) ;
320323 return res ;
321324 } ;
@@ -344,6 +347,10 @@ export default class Binance {
344347 timeout : this . Options . recvWindow ,
345348 followAllRedirects : true
346349 } ;
350+ query = this . makeQueryString ( data ) ;
351+ if ( flags . method === 'GET' ) {
352+ opt . url = `${ baseURL } ${ url } ?${ query } ` ;
353+ }
347354 if ( flags . type === 'SIGNED' || flags . type === 'TRADE' || flags . type === 'USER_DATA' ) {
348355 data . timestamp = new Date ( ) . getTime ( ) ;
349356 if ( this . info . timeOffset ) {
@@ -690,7 +697,7 @@ export default class Binance {
690697* @param {string } symbol - the symbol to get
691698* @return {promise or undefined } - omitting the callback returns a promise
692699*/
693- async openOrders ( symbol ?: string , params : Dict = { } ) {
700+ async openOrders ( symbol ?: string , params : Dict = { } ) : Promise < QueryOrder [ ] > {
694701 const parameters = symbol ? { symbol : symbol } : { } ;
695702 return await this . signedRequest ( this . getSpotUrl ( ) + 'v3/openOrders' , this . extend ( parameters , params ) ) ;
696703 }
@@ -736,7 +743,7 @@ export default class Binance {
736743 * @param {object } options - additional options
737744 * @return {promise or undefined } - omitting the callback returns a promise
738745 */
739- async allOrders ( symbol : string , params : Dict = { } ) {
746+ async allOrders ( symbol : string , params : Dict = { } ) : Promise < QueryOrder [ ] > {
740747 let parameters = this . extend ( { symbol } , params ) ;
741748 return await this . signedRequest ( this . getSpotUrl ( ) + 'v3/allOrders' , parameters ) ;
742749 }
@@ -2746,6 +2753,9 @@ export default class Binance {
27462753
27472754 parseOrderBook ( data ) : OrderBook {
27482755 const { lastUpdateId, bids, asks } = data ;
2756+ if ( ! bids || ! asks ) {
2757+ return data ;
2758+ }
27492759 const orderBook : OrderBook = {
27502760 lastUpdateId,
27512761 bids : bids . map ( b => zip ( [ 'price' , 'quantity' ] , b ) ) ,
@@ -3394,7 +3404,7 @@ export default class Binance {
33943404 }
33953405
33963406 /**
3397- * Get trades for a given symbol
3407+ * Get private trades for a given symbol
33983408 * @see https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api/account-endpoints#account-trade-list-user_data
33993409 * @param {string } symbol - the symbol
34003410 * @param {object } options - additional options
@@ -3405,6 +3415,19 @@ export default class Binance {
34053415 return await this . signedRequest ( this . getSpotUrl ( ) + 'v3/myTrades' , parameters ) ;
34063416 }
34073417
3418+ /**
3419+ * Get private trades for a given symbol
3420+ * @see https://developers.binance.com/docs/binance-spot-api-docs/testnet/rest-api/account-endpoints#account-trade-list-user_data
3421+ * @param {string } symbol - the symbol
3422+ * @param {object } options - additional options
3423+ * @return {promise or undefined } - omitting the callback returns a promise
3424+ */
3425+ async myTrades ( symbol : string , params : Dict = { } ) : Promise < MyTrade [ ] > {
3426+ const parameters = this . extend ( { symbol : symbol } , params ) ;
3427+ return await this . signedRequest ( this . getSpotUrl ( ) + 'v3/myTrades' , parameters ) ;
3428+ }
3429+
3430+
34083431 /**
34093432 * Tell api to use the server time to offset time indexes
34103433 * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time
@@ -4076,26 +4099,26 @@ export default class Binance {
40764099 return await this . futuresRequest ( 'v1/openInterest' , { symbol } , { base : this . getDapiUrl ( ) } ) . then ( r => r . openInterest ) ;
40774100 }
40784101
4079- async deliveryCandles ( symbol : string , interval = "30m" , params : Dict = { } ) : Promise < Candle [ ] > {
4102+ async deliveryCandles ( symbol : string , interval : Interval = "30m" , params : Dict = { } ) : Promise < Candle [ ] > {
40804103 params . symbol = symbol ;
40814104 params . interval = interval ;
40824105 return await this . futuresRequest ( 'v1/klines' , params , { base : this . getDapiUrl ( ) } ) ;
40834106 }
40844107
4085- async deliveryContinuousKlines ( pair : string , contractType = "CURRENT_QUARTER" , interval = "30m" , params : Dict = { } ) {
4108+ async deliveryContinuousKlines ( pair : string , contractType = "CURRENT_QUARTER" , interval : Interval = "30m" , params : Dict = { } ) {
40864109 params . pair = pair ;
40874110 params . interval = interval ;
40884111 params . contractType = contractType ;
40894112 return await this . futuresRequest ( 'v1/continuousKlines' , params , { base : this . getDapiUrl ( ) } ) ;
40904113 }
40914114
4092- async deliveryIndexKlines ( pair : string , interval = "30m" , params : Dict = { } ) {
4115+ async deliveryIndexKlines ( pair : string , interval : Interval = "30m" , params : Dict = { } ) {
40934116 params . pair = pair ;
40944117 params . interval = interval ;
40954118 return await this . futuresRequest ( 'v1/indexPriceKlines' , params , { base : this . getDapiUrl ( ) } ) ;
40964119 }
40974120
4098- async deliveryMarkPriceKlines ( symbol : string , interval = "30m" , params : Dict = { } ) {
4121+ async deliveryMarkPriceKlines ( symbol : string , interval : Interval = "30m" , params : Dict = { } ) {
40994122 params . symbol = symbol ;
41004123 params . interval = interval ;
41014124 return await this . futuresRequest ( 'v1/markPriceKlines' , params , { base : this . getDapiUrl ( ) } ) ;
@@ -4278,6 +4301,7 @@ export default class Binance {
42784301
42794302 /**
42804303 * Creates an order
4304+ * @see https://developers.binance.com/docs/margin_trading/trade/Margin-Account-New-Order
42814305 * @param {string } side - BUY or SELL
42824306 * @param {string } symbol - the symbol to buy
42834307 * @param {numeric } quantity - the quantity required
@@ -4747,7 +4771,7 @@ export default class Binance {
47474771 }
47484772
47494773 let handleFuturesKlineStream = kline => {
4750- let symbol = kline . s , interval = kline . k . i ;
4774+ let symbol = kline . s , interval : Interval = kline . k . i ;
47514775 if ( ! this . futuresMeta [ symbol ] [ interval ] . timestamp ) {
47524776 if ( typeof ( this . futuresKlineQueue [ symbol ] [ interval ] ) !== 'undefined' && kline !== null ) {
47534777 this . futuresKlineQueue [ symbol ] [ interval ] . push ( kline ) ;
@@ -4974,7 +4998,7 @@ export default class Binance {
49744998 }
49754999
49765000 let handleDeliveryKlineStream = kline => {
4977- let symbol = kline . s , interval = kline . k . i ;
5001+ let symbol = kline . s , interval : Interval = kline . k . i ;
49785002 if ( ! this . deliveryMeta [ symbol ] [ interval ] . timestamp ) {
49795003 if ( typeof ( this . deliveryKlineQueue [ symbol ] [ interval ] ) !== 'undefined' && kline !== null ) {
49805004 this . deliveryKlineQueue [ symbol ] [ interval ] . push ( kline ) ;
@@ -5467,7 +5491,7 @@ export default class Binance {
54675491 }
54685492
54695493 let handleKlineStreamData = kline => {
5470- let symbol = kline . s , interval = kline . k . i ;
5494+ let symbol = kline . s , interval : Interval = kline . k . i ;
54715495 if ( ! this . info [ symbol ] [ interval ] . timestamp ) {
54725496 if ( typeof ( this . klineQueue [ symbol ] [ interval ] ) !== 'undefined' && kline !== null ) {
54735497 this . klineQueue [ symbol ] [ interval ] . push ( kline ) ;
0 commit comments