Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion hotbit/reverseApi.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -181,12 +207,55 @@ 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 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
return resp

def customHTTP(self, url, whatToSend):
resp = self.session.post(url, json=whatToSend).text
return resp
return resp