Skip to content

Commit b1e5615

Browse files
committed
feat: add positional arguments for candles
1 parent d361f7c commit b1e5615

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

python_bitvavo_api/bitvavo.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def createPostfix(options):
3636
def _default(value, fallback):
3737
return value if value is not None else fallback
3838

39+
def _epoch_millis(dt):
40+
return int(dt.timestamp() * 1000)
41+
3942
def asksCompare(a, b):
4043
if(a < b):
4144
return True
@@ -249,9 +252,15 @@ def publicTrades(self, symbol, options=None):
249252
return self.publicRequest((self.base + '/' + symbol + '/trades' + postfix))
250253

251254
# options: limit, start, end
252-
def candles(self, symbol, interval, options=None):
255+
def candles(self, symbol, interval, options=None, limit=None, start=None, end=None):
253256
options = _default(options, {})
254257
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)
255264
postfix = createPostfix(options)
256265
return self.publicRequest((self.base + '/' + symbol + '/candles' + postfix))
257266

python_bitvavo_api/testApi.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
from datetime import datetime, timezone
12
from python_bitvavo_api.bitvavo import Bitvavo
2-
import sys
3-
import signal
43
import time
54
import json
65

@@ -48,10 +47,12 @@ def testREST(bitvavo):
4847
# print(json.dumps(trade, indent=2))
4948

5049
# Timestamp: candle[0], open: candle[1], high: candle[2], low: candle[3], close: candle[4], volume: candle[5]
51-
# response = bitvavo.candles('BTC-EUR', '1h', {})
52-
# for candle in response:
53-
# print(json.dumps(candle, indent=2))
54-
50+
# candles = bitvavo.candles('BTC-EUR', '15m')
51+
# candles = bitvavo.candles('BTC-EUR', '15m', limit=10)
52+
# candles = bitvavo.candles('BTC-EUR', '15m', start=datetime(year=2024, month=1, day=1, hour=0, tzinfo=timezone.utc), end=datetime(year=2024, month=1, day=1, hour=1, tzinfo=timezone.utc))
53+
# for candle in candles:
54+
# print('Timestamp', candle[0], ' open', candle[1], ' high', candle[2], ' low', candle[3], ' close', candle[4], ' volume', candle[5])
55+
5556
# response = bitvavo.tickerPrice({})
5657
# print(json.dumps(response, indent=2))
5758

@@ -115,7 +116,7 @@ def testREST(bitvavo):
115116
# for item in response:
116117
# print(json.dumps(item, indent=2))
117118

118-
# Normally you would define a seperate callback for every function.
119+
# Normally you would define a separate callback for every function.
119120
def callback(response):
120121
print("Callback:", json.dumps(response, indent=2))
121122

@@ -172,4 +173,4 @@ def testWebsockets(bitvavo):
172173
websocket.closeSocket()
173174

174175
if __name__ == '__main__':
175-
main()
176+
main()

0 commit comments

Comments
 (0)