Path: blob/master/ invest-robot-contest_NeuroInvest-main/NeuroInvest/south_x_change.py
5927 views
from config import scanInterval12from json import loads3from requests import get4from datetime import datetime5from trade_collection import TradeCollection6from time import sleep78class SouthXChange(TradeCollection):9def __init__(self, coinName):10super().__init__(coinName, self.getData)1112maxScanPeriod = 500 * scanInterval1314def getData(self, start, end, stepInSeconds, history, onUpdateData):15for scanStart in range(start, end, self.maxScanPeriod):16if not self.__getLimitedData(super().getName(), scanStart, min(scanStart + self.maxScanPeriod, end), stepInSeconds, history):17return False1819if onUpdateData is not None:20onUpdateData()2122return True2324@staticmethod25def __getLimitedData(name, start, end, stepInSeconds, history):26try:27steps = int((end - start) / stepInSeconds)28url = "https://www.southxchange.com/api/history/" + name + "/" + str(start * 1000) + "/" + str(end * 1000) + "/" + str(steps)2930response = get(url=url)31result = loads(response.text)3233print("SouthXChange FROM " + str(start) + " TO " + str(end))3435sleep(1)3637for data in result:38valueTime = int(datetime.fromisoformat(data["Date"] + "+00:00").timestamp())39history[valueTime] = (data["PriceHigh"] + data["PriceLow"]) / 24041return True42except Exception as message:43print("SouthXChange ERROR: " + str(message))44return False454647