Ejemplo n.º 1
0
def listOfHolidays():
    mydates = pd.date_range(
        '2020-06-05',
        datetime.datetime.today().date().strftime("%Y-%m-%d")).tolist()
    print(mydates)
    myholiday_list = [
        date.date().strftime("%Y-%m-%d") for date in mydates
        if HolidayCheck(date)
    ]
    return myholiday_list
 def all_task_runner(self):
     if HolidayCheck(datetime.strptime(self.date, '%Y-%m-%d').date()):
         logger.info("Holiday. Exiting...")
         sys.exit(0)
     self.get_updated_etf_list()
     for etf in self.etflist:
         self.calculate_arbitrage_for_etf(etf, self.date)
     self.write_etfwhichfailed_tocsv()
     print(self.etflist)
     print(self.etfwhichfailed)
Ejemplo n.º 3
0
def ListOfHolidays():
    mydates = pd.date_range(
        '2020-06-05',
        datetime.today().date().strftime("%Y-%m-%d")).tolist()
    MyholidayList = [
        date.date().strftime("%Y-%m-%d") for date in mydates
        if HolidayCheck(date)
    ]

    return jsonify({'HolidayList': MyholidayList})
Ejemplo n.º 4
0
 def all_task_runner(self):
     dates = ['2021-09-07', '2021-09-08', '2021-09-09', '2021-09-10', '2021-09-13', '2021-09-14']
     for date_ in dates:
         if HolidayCheck(datetime.strptime(date_, '%Y-%m-%d').date()):
             logger.info("Holiday. Moving to next date...")
             continue
         self.date = date_
         self.get_updated_etf_list()
         self.etflist = ['SPY', 'VOO', 'QQQ', 'IVV', 'IJR', 'VO', 'VGT', 'XLK', 'XLF', 'SCHX']
         # self.etflist = ['IJR']
         self.remove_old_trades_quotes_for_the_date_etf()
         for etf in self.etflist:
             start = time.time()
             self.calculate_arbitrage_for_etf(etf, self.date)
             print(f"Time Taken: {time.time() - start} seconds")
         self.write_etfwhichfailed_tocsv()
         print(self.etflist)
    def getMarketConditionsForFullDayData(self, now=None):
        if not now:
            now = datetime.datetime.utcnow()
        currentTime = now.time()
        todaysDate = now.date()
        ifaholiday = HolidayCheck(todaysDate)
        end_dt = None
        if currentTime >= self.UTCStartTime and (not ifaholiday):
            start_dt = now
            start_dt = start_dt.replace(hour=self.StartHour, minute=30, second=0, microsecond=0)
            # start_dt=start_dt - datetime.timedelta(hours=self.daylightSavingAdjutment)
            start_dt = start_dt.replace(tzinfo=tz.gettz('UTC'))
            start_dt = start_dt.astimezone(tz.tzlocal())
        else:
            lastworkinDay = LastWorkingDay(todaysDate - datetime.timedelta(days=1))
            start_dt = lastworkinDay

            start_dt = start_dt.replace(hour=self.StartHour, minute=30, second=0, microsecond=0)
            start_dt = start_dt.replace(tzinfo=tz.gettz('UTC'))
            start_dt = start_dt.astimezone(tz.tzlocal())

            end_dt = lastworkinDay.replace(hour=self.EndHour, minute=00, second=0, microsecond=0)
            end_dt = end_dt.replace(tzinfo=tz.gettz('UTC'))
            end_dt = end_dt.astimezone(tz.tzlocal())

        '''Custom Condition for Older Date Data Display'''
        if now:
            start_dt = now
            start_dt = start_dt.replace(hour=self.StartHour, minute=30, second=0, microsecond=0)
            # start_dt=start_dt - datetime.timedelta(hours=self.daylightSavingAdjutment)
            start_dt = start_dt.replace(tzinfo=tz.gettz('UTC'))
            start_dt = start_dt.astimezone(tz.tzlocal())
            end_dt = now
            end_dt = end_dt.replace(year=now.year, month=now.month, day=now.day, second=0, microsecond=0)
            end_dt = end_dt.replace(tzinfo=tz.gettz('UTC'))
            end_dt = end_dt.astimezone(tz.tzlocal())

        FetchDataForTimeObject = {}
        FetchDataForTimeObject['start_dt'] = int(start_dt.timestamp() * 1000)
        FetchDataForTimeObject['end_dt'] = int(end_dt.timestamp() * 1000) if end_dt else end_dt

        return FetchDataForTimeObject
    def getMarketConditionTime(self, todaysDate=None):
        ''''''
        '''Current UTC datetime'''
        now = datetime.datetime.utcnow()
        '''Current time only'''
        currentTime = now.time()
        '''Current date only'''
        if not todaysDate:
            todaysDate = now.date()
        ifaholiday = HolidayCheck(todaysDate)
        dt = None

        ##########################################################################################

        '''Piyush's Logic'''
        '''Market operating time on a Non-Holiday UTC 13:30:00 (self.UTCStartTime) to 20:00:00 (self.UTCEndTime)'''
        if (currentTime >= self.UTCStartTime) and (currentTime < self.UTCEndTime) and (not ifaholiday):
            dt = datetime.datetime.now().replace(second=0, microsecond=0)
            if todaysDate:
                dt = datetime.datetime.now().replace(year=todaysDate.year, month=todaysDate.month, day=todaysDate.day, second=0, microsecond=0)

        '''Before Market opens same day UTC 4:00:00 (self.DAYendTimeZeroZeo) to 13:30:00 (self.UTCStartTime) OR if it's a holiday'''
        if currentTime > self.DAYendTimeZeroZeo and currentTime < self.UTCStartTime or ifaholiday:
            dt = LastWorkingDay(todaysDate - datetime.timedelta(days=1)).replace(hour=self.EndHour, minute=0, second=0,
                                                                                 microsecond=0)
            dt = dt.replace(tzinfo=tz.gettz('UTC'))
            dt = dt.astimezone(tz.tzlocal())

        '''Here 2 conditions will be used.'''
        '''After market closes same day UTC 20:00:00 (self.UTCEndTime) to 23:59:59 (UTC Date Change Time). On a Non-Holiday.'''
        if currentTime < datetime.time(23, 59, 59) and currentTime > self.UTCEndTime and (not ifaholiday):
            dt = now.replace(hour=self.EndHour, minute=0, second=0, microsecond=0)
            dt = dt.replace(tzinfo=tz.gettz('UTC'))
            dt = dt.astimezone(tz.tzlocal())
        '''After market closes 00:00:00 (UTC New Date Time) to 3:59:59 (self.DAYendTimeZeroZeo). Doesn't matter if it's a holiday.'''
        if currentTime > datetime.time(0, 0) and currentTime < self.DAYendTimeZeroZeo:
            dt = LastWorkingDay(todaysDate - datetime.timedelta(days=1)).replace(hour=self.EndHour, minute=0, second=0,
                                                                                 microsecond=0)
            dt = dt.replace(tzinfo=tz.gettz('UTC'))
            dt = dt.astimezone(tz.tzlocal())

        return int(dt.timestamp() * 1000)