예제 #1
0
 def __init__(self, mqueue, identifiers, start_time, end_time, frequency,
              timezone):
     PollingThread.__init__(self)
     self.__queue = mqueue
     self.__start_time = get_today_time(start_time)
     self.__end_time = get_today_time(end_time)
     self.__timezone = timezone
     self.__frequency = frequency
     self.__identifiers = identifiers
     self.__subscriber = Subscriber()
     self.__next_call_time = localnow(self.__timezone)
     self.__last_response_time = localnow(self.__timezone)
예제 #2
0
 def doCall(self):
     bar_dict = {}
     for identifier in self.__identifiers:
         quote_ret, quote_data = self.__subscriber.get_quote_data(
             identifier)
         order_ret, order_data = self.__subscriber.get_order_book_data(
             identifier)
         if 0 == order_ret and 0 == quote_ret:
             quote_data = quote_data[[
                 'data_date', 'data_time', 'open_price', 'high_price',
                 'low_price', 'last_price', 'prev_close_price', 'volume',
                 'turnover'
             ]]
             quote_data = quote_data.rename(
                 columns={
                     "data_date": "date",
                     "data_time": "time",
                     "open_price": "open",
                     "high_price": "high",
                     "low_price": "low",
                     "last_price": "close",
                     "prev_close_price": "preclose",
                     "turnover": "amount"
                 })
             res = self.build_bar(quote_data.to_dict(), order_data)
             if res is not None: bar_dict[identifier] = res
     if len(bar_dict) > 0:
         bars = bar.Ticks(bar_dict)
         self.__queue.put((GetBarThread.ON_BARS, bars))
     if localnow(self.__timezone) >= self.__end_time:
         self.stop()
예제 #3
0
 def eof(self):
     if localnow(self.__timezone) >= self.__end_time:
         self.stop()
     return self.__stop
예제 #4
0
 def getNextCallDateTime(self):
     self.__next_call_time = max(localnow(self.__timezone),
                                 self.__next_call_time + self.__frequency)
     return self.__next_call_time
예제 #5
0
 def getCurrentDateTime(self):
     return localnow(self.__timezone)
예제 #6
0
 def wait(self):
     next_call_time = self.getNextCallDateTime()
     begin_time = localnow(self.__timezone)
     while not self.stopped and localnow(self.__timezone) < next_call_time:
         time.sleep((next_call_time - begin_time).seconds)