bitvavo / python-bitvavo-api

Python wrapper for the Bitvavo API
https://pypi.org/project/python-bitvavo-api/
ISC License
38 stars 23 forks source link

Error code 304 - Python API #29

Open WesleyK01 opened 2 years ago

WesleyK01 commented 2 years ago

Hello,

I am new to Python and I am following the guide. However, when I want to see my account with Python I get the error 304 ?

The code as of now is: "from python_bitvavo_api.bitvavo import Bitvavo bitvavo = Bitvavo({ 'APIKEY': '', 'APISECRET': '', 'RESTURL': 'https://api.bitvavo.com/v2', 'WSURL': 'wss://ws.bitvavo.com/v2/', 'TIME': 'bitvavo.time()', 'ACCESSWINDOW': 10000, 'DEBUGGING': False })

response = bitvavo.account() print(response)"

NostraDavid commented 2 years ago

Have you tried settings 'DEBUGGING' to True and see what it produces? I have no idea what 304 means (I'm just a user too) - can you provide the error text that comes with the number?

PS: I don't think 'TIME' does anything :)

NostraDavid commented 2 years ago

Found something about error codes: https://github.com/ccxt/ccxt/blob/6afab37de15feb9c44d82505adf375fc03e2108b/python/ccxt/bitvavo.py

It's probably AuthenticationError - did you set the correct API key and Secret? If I set my own the code works just fine.

NostraDavid commented 2 years ago

OK, since the time I commented on this, I've had a LOT more experience with the API and have gotten a ton of 304 errors. Turns out it's NOT an AuthenticationError. It's a mismatch between your local clock and the server's clock

You can run this bit to see the difference - it's 5000ms for me (quite a bit, I know!)

from time import time
from urllib.request import urlopen
import json

def time_ms() -> int:
    return int(time() * 1000)

def calculate_lag():
    url = "https://api.bitvavo.com/v2/time"
    result = json.loads(urlopen(url).read())
    server_time = result["time"]
    local_time = time_ms()
    time_delta_ms = result["time"] - local_time
    print(f"server_time: {server_time}")
    print(f"local_time: {local_time}")
    print(f"difference: {time_delta_ms}")

So yeah, it's not you - it's your system clock.

PS: Make sure your Windows clock is synced in your date and time settings Note: mine is synced, yet the diff is still 5000ms, so don't freak out too much :)