Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_NeuroInvest-main/NeuroInvest/south_x_change.py
5927 views
1
from config import scanInterval
2
3
from json import loads
4
from requests import get
5
from datetime import datetime
6
from trade_collection import TradeCollection
7
from time import sleep
8
9
class SouthXChange(TradeCollection):
10
def __init__(self, coinName):
11
super().__init__(coinName, self.getData)
12
13
maxScanPeriod = 500 * scanInterval
14
15
def getData(self, start, end, stepInSeconds, history, onUpdateData):
16
for scanStart in range(start, end, self.maxScanPeriod):
17
if not self.__getLimitedData(super().getName(), scanStart, min(scanStart + self.maxScanPeriod, end), stepInSeconds, history):
18
return False
19
20
if onUpdateData is not None:
21
onUpdateData()
22
23
return True
24
25
@staticmethod
26
def __getLimitedData(name, start, end, stepInSeconds, history):
27
try:
28
steps = int((end - start) / stepInSeconds)
29
url = "https://www.southxchange.com/api/history/" + name + "/" + str(start * 1000) + "/" + str(end * 1000) + "/" + str(steps)
30
31
response = get(url=url)
32
result = loads(response.text)
33
34
print("SouthXChange FROM " + str(start) + " TO " + str(end))
35
36
sleep(1)
37
38
for data in result:
39
valueTime = int(datetime.fromisoformat(data["Date"] + "+00:00").timestamp())
40
history[valueTime] = (data["PriceHigh"] + data["PriceLow"]) / 2
41
42
return True
43
except Exception as message:
44
print("SouthXChange ERROR: " + str(message))
45
return False
46
47