@@ -24,6 +24,7 @@ def createSignature(timestamp, method, url, body, APISECRET):
2424 return signature
2525
2626def createPostfix (options ):
27+ options = _default (options , {})
2728 params = []
2829 for key in options :
2930 params .append (key + '=' + str (options [key ]))
@@ -32,6 +33,12 @@ def createPostfix(options):
3233 postfix = '?' + postfix
3334 return postfix
3435
36+ def _default (value , fallback ):
37+ return value if value is not None else fallback
38+
39+ def _epoch_millis (dt ):
40+ return int (dt .timestamp () * 1000 )
41+
3542def asksCompare (a , b ):
3643 if (a < b ):
3744 return True
@@ -225,43 +232,50 @@ def time(self):
225232 return self .publicRequest ((self .base + '/time' ))
226233
227234 # options: market
228- def markets (self , options ):
235+ def markets (self , options = None ):
229236 postfix = createPostfix (options )
230237 return self .publicRequest ((self .base + '/markets' + postfix ))
231238
232239 # options: symbol
233- def assets (self , options ):
240+ def assets (self , options = None ):
234241 postfix = createPostfix (options )
235242 return self .publicRequest ((self .base + '/assets' + postfix ))
236243
237244 # options: depth
238- def book (self , symbol , options ):
245+ def book (self , symbol , options = None ):
239246 postfix = createPostfix (options )
240247 return self .publicRequest ((self .base + '/' + symbol + '/book' + postfix ))
241248
242249 # options: limit, start, end, tradeIdFrom, tradeIdTo
243- def publicTrades (self , symbol , options ):
250+ def publicTrades (self , symbol , options = None ):
244251 postfix = createPostfix (options )
245252 return self .publicRequest ((self .base + '/' + symbol + '/trades' + postfix ))
246253
247254 # options: limit, start, end
248- def candles (self , symbol , interval , options ):
255+ def candles (self , symbol , interval , options = None , limit = None , start = None , end = None ):
256+ options = _default (options , {})
249257 options ['interval' ] = interval
258+ if limit is not None :
259+ options ['limit' ] = limit
260+ if start is not None :
261+ options ['start' ] = _epoch_millis (start )
262+ if end is not None :
263+ options ['end' ] = _epoch_millis (end )
250264 postfix = createPostfix (options )
251265 return self .publicRequest ((self .base + '/' + symbol + '/candles' + postfix ))
252266
253267 # options: market
254- def tickerPrice (self , options ):
268+ def tickerPrice (self , options = None ):
255269 postfix = createPostfix (options )
256270 return self .publicRequest ((self .base + '/ticker/price' + postfix ))
257271
258272 # options: market
259- def tickerBook (self , options ):
273+ def tickerBook (self , options = None ):
260274 postfix = createPostfix (options )
261275 return self .publicRequest ((self .base + '/ticker/book' + postfix ))
262276
263277 # options: market
264- def ticker24h (self , options ):
278+ def ticker24h (self , options = None ):
265279 postfix = createPostfix (options )
266280 return self .publicRequest ((self .base + '/ticker/24h' + postfix ))
267281
@@ -292,23 +306,25 @@ def cancelOrder(self, market, orderId):
292306 return self .privateRequest ('/order' , postfix , {}, 'DELETE' )
293307
294308 # options: limit, start, end, orderIdFrom, orderIdTo
295- def getOrders (self , market , options ):
309+ def getOrders (self , market , options = None ):
310+ options = _default (options , {})
296311 options ['market' ] = market
297312 postfix = createPostfix (options )
298313 return self .privateRequest ('/orders' , postfix , {}, 'GET' )
299314
300315 # options: market
301- def cancelOrders (self , options ):
316+ def cancelOrders (self , options = None ):
302317 postfix = createPostfix (options )
303318 return self .privateRequest ('/orders' , postfix , {}, 'DELETE' )
304319
305320 # options: market
306- def ordersOpen (self , options ):
321+ def ordersOpen (self , options = None ):
307322 postfix = createPostfix (options )
308323 return self .privateRequest ('/ordersOpen' , postfix , {}, 'GET' )
309324
310325 # options: limit, start, end, tradeIdFrom, tradeIdTo
311- def trades (self , market , options ):
326+ def trades (self , market , options = None ):
327+ options = _default (options , {})
312328 options ['market' ] = market
313329 postfix = createPostfix (options )
314330 return self .privateRequest ('/trades' , postfix , {}, 'GET' )
@@ -317,7 +333,7 @@ def account(self):
317333 return self .privateRequest ('/account' , '' , {}, 'GET' )
318334
319335 # options: symbol
320- def balance (self , options ):
336+ def balance (self , options = None ):
321337 postfix = createPostfix (options )
322338 return self .privateRequest ('/balance' , postfix , {}, 'GET' )
323339
@@ -333,12 +349,12 @@ def withdrawAssets(self, symbol, amount, address, body):
333349 return self .privateRequest ('/withdrawal' , '' , body , 'POST' )
334350
335351 # options: symbol, limit, start, end
336- def depositHistory (self , options ):
352+ def depositHistory (self , options = None ):
337353 postfix = createPostfix (options )
338354 return self .privateRequest ('/depositHistory' , postfix , {}, 'GET' )
339355
340356 # options: symbol, limit, start, end
341- def withdrawalHistory (self , options ):
357+ def withdrawalHistory (self , options = None ):
342358 postfix = createPostfix (options )
343359 return self .privateRequest ('/withdrawalHistory' , postfix , {}, 'GET' )
344360
0 commit comments