From 32d3e2dfe12a2a95773e0781e14568abfa8b9e41 Mon Sep 17 00:00:00 2001 From: kalzu Date: Fri, 13 Jan 2023 22:26:31 +0200 Subject: [PATCH] Make timestamp to always be INT --- btc_tracker/kraken_fetch.py | 5 +++- btc_tracker/kraken_fetch_client.py | 42 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 btc_tracker/kraken_fetch_client.py diff --git a/btc_tracker/kraken_fetch.py b/btc_tracker/kraken_fetch.py index a4e2652..602d914 100755 --- a/btc_tracker/kraken_fetch.py +++ b/btc_tracker/kraken_fetch.py @@ -173,9 +173,12 @@ def fetch_bitstamp(): bitstamp_data = response.json() ohlc_data = bitstamp_data["data"]["ohlc"] + # the bitstamp api gives timestamp with decimals to show less than second accuracy. + bitstamp_timestamp = int(math.floor(float(ohlc_data[0]["timestamp"]))) + candle_stick_data = { "exchange": "bitstamp", - "timestamp": int(ohlc_data[0]["timestamp"]), + "timestamp": bitstamp_timestamp, "open": float(ohlc_data[0]["open"]), "high": float(ohlc_data[0]["high"]), "low": float(ohlc_data[0]["low"]), diff --git a/btc_tracker/kraken_fetch_client.py b/btc_tracker/kraken_fetch_client.py new file mode 100644 index 0000000..8e1abed --- /dev/null +++ b/btc_tracker/kraken_fetch_client.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +""" +client for kraken_fetch.py +""" +import requests +import ecdsa +import sqlite3 + +config_file = "./kraken_fetch_client.conf" +# Just for testing and early development +private_key = '039e1c137aa296d7af0cd55b468018ad1020949c2731e5141d032b8371490f48' + + +def read_config(): + """ + read $config_file and returns users private key + """ + + return private_key + +def get_server_public_key(url): + """ + fetches the servers public key + """ + rurl = url+'/serverkey' + response = requests.get(rurl) + if response.status_code == 200: # if the fetch was success... + server_public_key = response.content + return server_public_key + # when the fetch was not successfull + print(f"Error fetching data from the server.") + return 'Error' + +def fetch_data_from_the_server(url): + """ + query the kraken_fetch server for new data + """ + # we need to do some time calculations here... + + response = requests.get(url) + + return response