Exemple #1
0
    def get_last_price(self, code, log=False):

        data = self.market_trades[code][-1]

        if log:
            local_time = int2datetime(data.nActionDay, data.nLocalTime)
            market_time = int2datetime(data.nActionDay, data.nTime)
            self.logger.debug('local_time: {}, market_time: {}'.format(
                abs(local_time - self.now).seconds,
                abs(market_time - self.now).seconds))

        return data.nPrice / 10000
Exemple #2
0
    def on_market_trade(self, data):

        if data.nPrice > 0:
            self.market_trades[data.szCode].append(data)

        return
        if not data.szCode == '002230':
            return

        if len(self.market_trades[data.szCode]) < 1:
            return

        self.cur_period = int2datetime(n_date=data.nActionDay,
                                       n_time=data.nTime)
        self.market_quantity += data.nVolume

        if self.cur_period - self.ordering_start >= self.ordering_interval:
            price = self.get_last_price(data.szCode)
            units = int(self.market_quantity * self.ordering_ratio / 100)

            self.ordering_start = self.cur_period
            self.market_quantiy = 0

            quantity = min(units * 100, self.ordering_quota)
            if quantity > 0:
                self.buy(data.szCode, price, quantity)
                self.ordering_quota -= quantity
                self.logger.info('分批报单 quantiy={}'.format(quantity))

                if self.ordering_quota <= 0:
                    self.logger.warning('报单全部完成')
Exemple #3
0
    def on_data(self, data):

        if not isinstance(data, str):
            self._queue.put(data)
            self._store.write_points([{
                'measurement':
                'market_tick',
                'fields':
                message2dict(data),
                'time':
                int2datetime(data.nActionDay, data.nLocalTime)
            }])