From e80fba566d160e276586f86b23fba1974a12851f Mon Sep 17 00:00:00 2001 From: TitoDra <36330524+TitoDra@users.noreply.github.com> Date: Wed, 25 May 2022 14:18:54 +0200 Subject: [PATCH 1/2] kline query Get past data market with Ws date format : "22/05/2022 19:41:00" --- hotbit/reverseApi.py | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/hotbit/reverseApi.py b/hotbit/reverseApi.py index a4334f0..19b1356 100644 --- a/hotbit/reverseApi.py +++ b/hotbit/reverseApi.py @@ -1,12 +1,38 @@ import requests import requestsWS from decimal import * +from datetime import datetime +import time + +DT_FORMAT = "%d/%m/%Y %H:%M:%S" def round_down(value, decimals): # https://stackoverflow.com/questions/41383787/round-down-to-2-decimal-in-python with localcontext() as ctx: ctx.rounding = ROUND_DOWN return round(value, decimals) +def check_date_format(date_str): + try: + datetime.strptime(date_str, DT_FORMAT) + except ValueError: + print("This is the incorrect date string format. It should be DD-MM-YYYY") + return False + else: + return True + +def date_str_to_timestamp(date_str=None): + if isinstance(date_str, str): + print("date : ", date_str) + is_valid = check_date_format(date_str) + timestamp = time.mktime( + datetime.strptime(date_str, DT_FORMAT).timetuple() + ) + + return { + "is_valid": is_valid, + "timestamp": timestamp + } + class Hotbit: def __init__(self, auth): self.session = requests.Session() @@ -181,6 +207,33 @@ def order(self, price, amount, market, side, type="LIMIT", hide=False, use_disco } resp = self.session.post("https://www.hotbit.pro/v1/order/create?platform=web", headers=self.defaultHeaders, data=payload) return resp.json() + + def klineQuery(self, market, start, end, interval=60): + market = market.replace("/", "") + time_start_dict = date_str_to_timestamp(start) + time_end_dict = date_str_to_timestamp(end) + + timestamp_start = int(time_start_dict.get("timestamp")) + timestamp_end = int(time_end_dict.get("timestamp")) + + payload = { + "method": "kline.query", + "params": [ + market, + timestamp_start, + timestamp_end, + interval + ], + "id": 100 + } + + resp = self.sessionWS.post( + 'wss://ws.hotbit.io/', + json=payload, + encryption="gzip", + identifiers={"id": 100} + ) + return resp.json() def customWS(self, whatToSend): @@ -189,4 +242,4 @@ def customWS(self, whatToSend): def customHTTP(self, url, whatToSend): resp = self.session.post(url, json=whatToSend).text - return resp \ No newline at end of file + return resp From dcde994c8c45a40cea4b9b84967775ca6fe2a8ff Mon Sep 17 00:00:00 2001 From: jona799t <70392256+jona799t@users.noreply.github.com> Date: Sun, 21 Aug 2022 20:45:08 +0200 Subject: [PATCH 2/2] Merge pull request #6 from TitoDra/patch-2 + resolved conflicts --- hotbit/reverseApi.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hotbit/reverseApi.py b/hotbit/reverseApi.py index 19b1356..01198a3 100644 --- a/hotbit/reverseApi.py +++ b/hotbit/reverseApi.py @@ -234,7 +234,23 @@ def klineQuery(self, market, start, end, interval=60): identifiers={"id": 100} ) return resp.json() + + def priceQuery(self, market): + market = market.replace("/", "") + + payload = { + "method":"price.query", + "params":[market], + "id":100 + } + resp = self.sessionWS.post( + 'wss://ws.hotbit.io/', + json=payload, + encryption="gzip", + identifiers={"id": 100} + ) + return resp.json() def customWS(self, whatToSend): resp = self.sessionWS.post('wss://ws.hotbit.io/', json=whatToSend, encryption="gzip").text