Skip to content

Commit d361f7c

Browse files
committed
feat: make options arguments optional
1 parent 5d676cf commit d361f7c

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

python_bitvavo_api/bitvavo.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def createSignature(timestamp, method, url, body, APISECRET):
2424
return signature
2525

2626
def createPostfix(options):
27+
options = _default(options, {})
2728
params = []
2829
for key in options:
2930
params.append(key + '=' + str(options[key]))
@@ -32,6 +33,9 @@ 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+
3539
def asksCompare(a, b):
3640
if(a < b):
3741
return True
@@ -225,43 +229,44 @@ def time(self):
225229
return self.publicRequest((self.base + '/time'))
226230

227231
# options: market
228-
def markets(self, options):
232+
def markets(self, options=None):
229233
postfix = createPostfix(options)
230234
return self.publicRequest((self.base + '/markets' + postfix))
231235

232236
# options: symbol
233-
def assets(self, options):
237+
def assets(self, options=None):
234238
postfix = createPostfix(options)
235239
return self.publicRequest((self.base + '/assets' + postfix))
236240

237241
# options: depth
238-
def book(self, symbol, options):
242+
def book(self, symbol, options=None):
239243
postfix = createPostfix(options)
240244
return self.publicRequest((self.base + '/' + symbol + '/book' + postfix))
241245

242246
# options: limit, start, end, tradeIdFrom, tradeIdTo
243-
def publicTrades(self, symbol, options):
247+
def publicTrades(self, symbol, options=None):
244248
postfix = createPostfix(options)
245249
return self.publicRequest((self.base + '/' + symbol + '/trades' + postfix))
246250

247251
# options: limit, start, end
248-
def candles(self, symbol, interval, options):
252+
def candles(self, symbol, interval, options=None):
253+
options = _default(options, {})
249254
options['interval'] = interval
250255
postfix = createPostfix(options)
251256
return self.publicRequest((self.base + '/' + symbol + '/candles' + postfix))
252257

253258
# options: market
254-
def tickerPrice(self, options):
259+
def tickerPrice(self, options=None):
255260
postfix = createPostfix(options)
256261
return self.publicRequest((self.base + '/ticker/price' + postfix))
257262

258263
# options: market
259-
def tickerBook(self, options):
264+
def tickerBook(self, options=None):
260265
postfix = createPostfix(options)
261266
return self.publicRequest((self.base + '/ticker/book' + postfix))
262267

263268
# options: market
264-
def ticker24h(self, options):
269+
def ticker24h(self, options=None):
265270
postfix = createPostfix(options)
266271
return self.publicRequest((self.base + '/ticker/24h' + postfix))
267272

@@ -292,23 +297,25 @@ def cancelOrder(self, market, orderId):
292297
return self.privateRequest('/order', postfix, {}, 'DELETE')
293298

294299
# options: limit, start, end, orderIdFrom, orderIdTo
295-
def getOrders(self, market, options):
300+
def getOrders(self, market, options=None):
301+
options = _default(options, {})
296302
options['market'] = market
297303
postfix = createPostfix(options)
298304
return self.privateRequest('/orders', postfix, {}, 'GET')
299305

300306
# options: market
301-
def cancelOrders(self, options):
307+
def cancelOrders(self, options=None):
302308
postfix = createPostfix(options)
303309
return self.privateRequest('/orders', postfix, {}, 'DELETE')
304310

305311
# options: market
306-
def ordersOpen(self, options):
312+
def ordersOpen(self, options=None):
307313
postfix = createPostfix(options)
308314
return self.privateRequest('/ordersOpen', postfix, {}, 'GET')
309315

310316
# options: limit, start, end, tradeIdFrom, tradeIdTo
311-
def trades(self, market, options):
317+
def trades(self, market, options=None):
318+
options = _default(options, {})
312319
options['market'] = market
313320
postfix = createPostfix(options)
314321
return self.privateRequest('/trades', postfix, {}, 'GET')
@@ -317,7 +324,7 @@ def account(self):
317324
return self.privateRequest('/account', '', {}, 'GET')
318325

319326
# options: symbol
320-
def balance(self, options):
327+
def balance(self, options=None):
321328
postfix = createPostfix(options)
322329
return self.privateRequest('/balance', postfix, {}, 'GET')
323330

@@ -333,12 +340,12 @@ def withdrawAssets(self, symbol, amount, address, body):
333340
return self.privateRequest('/withdrawal', '', body, 'POST')
334341

335342
# options: symbol, limit, start, end
336-
def depositHistory(self, options):
343+
def depositHistory(self, options=None):
337344
postfix = createPostfix(options)
338345
return self.privateRequest('/depositHistory', postfix, {}, 'GET')
339346

340347
# options: symbol, limit, start, end
341-
def withdrawalHistory(self, options):
348+
def withdrawalHistory(self, options=None):
342349
postfix = createPostfix(options)
343350
return self.privateRequest('/withdrawalHistory', postfix, {}, 'GET')
344351

python_bitvavo_api/testApi.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ def testREST(bitvavo):
3232
response = bitvavo.time()
3333
print(response)
3434

35-
# response = bitvavo.markets({})
35+
# response = bitvavo.markets()
3636
# for market in response:
3737
# print(json.dumps(market, indent=2))
3838

39-
# response = bitvavo.assets({})
39+
# response = bitvavo.assets()
4040
# for asset in response:
4141
# print(json.dumps(asset, indent=2))
4242

43-
# response = bitvavo.book('BTC-EUR', {})
43+
# response = bitvavo.book('BTC-EUR')
4444
# print(json.dumps(response, indent=2))
4545

46-
# response = bitvavo.publicTrades('BTC-EUR', {})
46+
# response = bitvavo.publicTrades('BTC-EUR')
4747
# for trade in response:
4848
# print(json.dumps(trade, indent=2))
4949

@@ -78,26 +78,26 @@ def testREST(bitvavo):
7878
# response = bitvavo.cancelOrder('BTC-EUR', 'dd055772-0f02-493c-a049-f4356fa0d221')
7979
# print(json.dumps(response, indent=2))
8080

81-
# response = bitvavo.getOrders('BTC-EUR', {})
81+
# response = bitvavo.getOrders('BTC-EUR')
8282
# for item in response:
8383
# print(json.dumps(item, indent=2))
8484

8585
# response = bitvavo.cancelOrders({ 'market': 'BTC-EUR' })
8686
# for item in response:
8787
# print(json.dumps(item, indent=2))
8888

89-
# response = bitvavo.ordersOpen({})
89+
# response = bitvavo.ordersOpen()
9090
# for item in response:
9191
# print(json.dumps(item, indent=2))
9292

93-
# response = bitvavo.trades('BTC-EUR', {})
93+
# response = bitvavo.trades('BTC-EUR')
9494
# for item in response:
9595
# print(json.dumps(item, indent=2))
9696

9797
# response = bitvavo.account()
9898
# print(json.dumps(response, indent=2))
9999

100-
# response = bitvavo.balance({})
100+
# response = bitvavo.balance()
101101
# for item in response:
102102
# print(json.dumps(item, indent=2))
103103

@@ -107,11 +107,11 @@ def testREST(bitvavo):
107107
# response = bitvavo.withdrawAssets('BTC', '1', 'BitcoinAddress', {})
108108
# print(json.dumps(response, indent=2))
109109

110-
# response = bitvavo.depositHistory({})
110+
# response = bitvavo.depositHistory()
111111
# for item in response:
112112
# print(json.dumps(item, indent=2))
113113

114-
# response = bitvavo.withdrawalHistory({})
114+
# response = bitvavo.withdrawalHistory()
115115
# for item in response:
116116
# print(json.dumps(item, indent=2))
117117

0 commit comments

Comments
 (0)