コード例 #1
0
 def testIsTimeStampOlderThanSevenDays(self):
     DAYS_BEFORE = -7
     localTimeZone = 'Europe/Zurich'
     dateBefore = arrow.utcnow().shift(days=DAYS_BEFORE).to(localTimeZone)
     self.assertFalse(
         DateTimeUtil.isTimeStampOlderThan(dateBefore.timestamp(),
                                           localTimeZone, abs(DAYS_BEFORE)))
コード例 #2
0
 def testIsTimeStampOlderThanSevenDaysMinusOneSecondAgainsUTCTimwe(self):
     DAYS_BEFORE = -7
     SECOND_AFTER = 1
     localTimeZone = None
     dateBefore = arrow.utcnow().shift(
         days=DAYS_BEFORE, seconds=SECOND_AFTER).to('Europe/Zurich')
     self.assertFalse(
         DateTimeUtil.isTimeStampOlderThan(dateBefore.timestamp(),
                                           localTimeZone, abs(DAYS_BEFORE)))
コード例 #3
0
 def testIsTimeStampOlderThanSevenDaysPlusOneSecond(self):
     DAYS_BEFORE = -7
     SECOND_BEFORE = -1
     localTimeZone = 'Europe/Zurich'
     dateBefore = arrow.utcnow().shift(
         days=DAYS_BEFORE, seconds=SECOND_BEFORE).to('Europe/Zurich')
     self.assertTrue(
         DateTimeUtil.isTimeStampOlderThan(dateBefore.timestamp(),
                                           localTimeZone, abs(DAYS_BEFORE)))
コード例 #4
0
    def getHistoricalPriceAtUTCTimeStamp(self, crypto, unit,
                                         timeStampLocalForHistoMinute, localTz,
                                         timeStampUTCNoHHMMForHistoDay,
                                         exchange):
        '''
        Why do we pass two different time stamp to the method ?
        
        When requesting a minute price the time stamp obtained
        from a local arrow datetime object is used. If we
        request a minute price for 15:18 Zurich time (+00.02)
        time, the minute price returned is the one at UTC 13:18.
        Asking the same price from Mumbay would require to
        ask the price for 20:18 (+00.05).
        
        Now, when asking an histo day price, the returned price
        is a close price. But crypto trade 24 H a day. The "close"
        price time stamp must not be dependant from the location 
        from which the request is sent. Instead, the "close" price
        is the one at the passed date with hour and minute set to 0.
        This date is not a localiszd date, but a UTC localization
        independent date.
        
        When you go on the Cryptocompare site and you search for 
        historical prices, the close price for a given date is
        the same whatever the location of the user is !

        :seqdiag_note Obtainins a minute price if request date < 7 days from now, else a day close price.
        :seqdiag_return ResultData
        '''
        resultData = ResultData()

        resultData.setValue(ResultData.RESULT_KEY_CRYPTO, crypto)
        resultData.setValue(ResultData.RESULT_KEY_UNIT, unit)
        resultData.setValue(ResultData.RESULT_KEY_EXCHANGE, exchange)

        if DateTimeUtil.isTimeStampOlderThan(
                timeStampLocalForHistoMinute,
                localTz,
                dayNumberInt=MINUTE_PRICE_DAY_NUMBER_LIMIT):
            return self._getHistoDayPriceAtUTCTimeStamp(
                crypto, unit, timeStampUTCNoHHMMForHistoDay, exchange,
                resultData)
        else:
            return self._getHistoMinutePriceAtUTCTimeStamp(
                crypto, unit, timeStampLocalForHistoMinute, exchange,
                resultData)