Beispiel #1
0
 def get_nr_of_hour_distance_from_server(self):
     nowdt = datetime.now()
     dateutil = DateUtil()
     nowmillis = dateutil.unix_time_millis(nowdt)
     server_time = self.get_server_time()['serverTime']
     diff = (nowmillis - server_time) / 1000 / 3600
     diff = round(diff)
     return diff
Beispiel #2
0
    def get_last_n_hour_by_specific_hour_by_coin(self, coin, specific_hour,
                                                 n_hours):
        coinname = coin.name
        coinnameupper = coinname.upper()
        offset_from_server = self.get_nr_of_hour_distance_from_server()
        #once you have to substract the offset from server
        targethour = specific_hour + timedelta(hours=-1 * offset_from_server)

        #twice you have to substract because the server end time means until the next hour. >:)
        targethour = targethour + timedelta(hours=-1)
        date_util = DateUtil()
        start_time = round(date_util.unix_time_millis(targethour))

        apiurl='https://api.binance.com/api/v1/klines?symbol='+coinnameupper+'BTC&endTime='+str(start_time)+\
               '&interval=1h&limit='+str(n_hours)

        print("calling: " + apiurl)
        response = requests.get(apiurl)
        return response.json()