class GetBarThread(PollingThread):
    # Events
    ON_BARS = 1

    def __init__(self, queue, identifiers, frequency):
        super(GetBarThread, self).__init__()

        self.__queue = queue
        self.__identifiers = identifiers
        self.__frequency = frequency
        self.__nextBarStart = None
        self.__nextBarClose = None

        self._ticksDf = {}
        self.__lock = Lock()

        for identifier in self.__identifiers:
            self._ticksDf[identifier] = DataFrame(
                columns=['time', 'price', 'volume', 'amount'])

        self._ctpMdApi = CTPMdApi(self.__identifiers, self._ticksDf,
                                  self.__lock, logger)
        #self._ctpMdApi.login("tcp://222.66.97.241:41213", '9017811', '123456', '7070')
        self._ctpMdApi.login("tcp://180.168.212.228:41213", "simnow申请",
                             "simnow申请", "9999")
        #self._ctpMdApi.login("tcp://211.144.195.163:34505", "", "", "")

        self.__updateNextBarClose()

    def __updateNextBarClose(self):
        self.__nextBarStart = resamplebase.build_range(
            utcnow(), self.__frequency).getBeginning()
        self.__nextBarClose = resamplebase.build_range(
            utcnow(), self.__frequency).getEnding()

    def getNextCallDateTime(self):
        return self.__nextBarClose

    def doCall(self):
        startDateTime = to_market_datetime(self.__nextBarStart)
        endDateTime = to_market_datetime(self.__nextBarClose)
        self.__updateNextBarClose()
        barDict = dict()

        for identifier in self.__identifiers:
            try:
                period_bar = self._build_bar(identifier, startDateTime,
                                             endDateTime)
                if period_bar:
                    barDict[identifier] = period_bar

            except Exception, e:
                logger.error(e)

        if len(barDict):
            bars = bar.Bars(barDict)
            self.__queue.put((GetBarThread.ON_BARS, bars))
Example #2
0
class GetBarThread(PollingThread):
    # Events
    ON_BARS = 1

    def __init__(self, queue, identifiers, frequency):
        super(GetBarThread, self).__init__()

        self.__queue = queue
        self.__identifiers = identifiers
        self.__frequency = frequency
        self.__nextBarStart = None
        self.__nextBarClose = None

        self._ticksDf = {}
        self.__lock = Lock()

        for identifier in self.__identifiers:
            self._ticksDf[identifier] = DataFrame(columns=["time", "price", "volume", "amount"])

        self._ctpMdApi = CTPMdApi(self.__identifiers, self._ticksDf, self.__lock, logger)
        # self._ctpMdApi.login("tcp://222.66.97.241:41213", '9017811', '123456', '7070')
        self._ctpMdApi.login("tcp://180.168.212.228:41213", "simnow申请", "simnow申请", "9999")
        # self._ctpMdApi.login("tcp://211.144.195.163:34505", "", "", "")

        self.__updateNextBarClose()

    def __updateNextBarClose(self):
        self.__nextBarStart = resamplebase.build_range(utcnow(), self.__frequency).getBeginning()
        self.__nextBarClose = resamplebase.build_range(utcnow(), self.__frequency).getEnding()

    def getNextCallDateTime(self):
        return self.__nextBarClose

    def doCall(self):
        startDateTime = to_market_datetime(self.__nextBarStart)
        endDateTime = to_market_datetime(self.__nextBarClose)
        self.__updateNextBarClose()
        barDict = dict()

        for identifier in self.__identifiers:
            try:
                period_bar = self._build_bar(identifier, startDateTime, endDateTime)
                if period_bar:
                    barDict[identifier] = period_bar

            except Exception, e:
                logger.error(e)

        if len(barDict):
            bars = bar.Bars(barDict)
            self.__queue.put((GetBarThread.ON_BARS, bars))
    def __init__(self, queue, identifiers, frequency):
        super(GetBarThread, self).__init__()

        self.__queue = queue
        self.__identifiers = identifiers
        self.__frequency = frequency
        self.__nextBarStart = None
        self.__nextBarClose = None

        self._ticksDf = {}
        self.__lock = Lock()

        for identifier in self.__identifiers:
            self._ticksDf[identifier] = DataFrame(
                columns=['time', 'price', 'volume', 'amount'])

        self._ctpMdApi = CTPMdApi(self.__identifiers, self._ticksDf,
                                  self.__lock, logger)
        #self._ctpMdApi.login("tcp://222.66.97.241:41213", '9017811', '123456', '7070')
        self._ctpMdApi.login("tcp://180.168.212.228:41213", "simnow申请",
                             "simnow申请", "9999")
        #self._ctpMdApi.login("tcp://211.144.195.163:34505", "", "", "")

        self.__updateNextBarClose()
Example #4
0
    def __init__(self, queue, identifiers, frequency):
        super(GetBarThread, self).__init__()

        self.__queue = queue
        self.__identifiers = identifiers
        self.__frequency = frequency
        self.__nextBarStart = None
        self.__nextBarClose = None

        self._ticksDf = {}
        self.__lock = Lock()

        for identifier in self.__identifiers:
            self._ticksDf[identifier] = DataFrame(columns=["time", "price", "volume", "amount"])

        self._ctpMdApi = CTPMdApi(self.__identifiers, self._ticksDf, self.__lock, logger)
        # self._ctpMdApi.login("tcp://222.66.97.241:41213", '9017811', '123456', '7070')
        self._ctpMdApi.login("tcp://180.168.212.228:41213", "simnow申请", "simnow申请", "9999")
        # self._ctpMdApi.login("tcp://211.144.195.163:34505", "", "", "")

        self.__updateNextBarClose()