Exemplo n.º 1
0
    def worker_1450(self):
        """盘中推送bar"""
        to_log('in TradeEngine.worker_1450')

        for p in self.portfolio_list:
            for vtSymbol in p.vtSymbolList:
                #print(vtSymbol)
                df = None
                i = 0
                while df is None and i < 2:
                    try:
                        i += 1
                        df = ts.get_realtime_quotes(vtSymbol)
                    except Exception as e:
                        print('error get_realtime_quotes')
                        print(e)
                        time.sleep(0.1)

                if df is None:
                    continue

                code = vtSymbol
                df1 = None
                i = 0
                while df1 is None and i < 2:
                    try:
                        i += 1
                        df1 = get_adj_factor(self.dss, code)
                    except Exception as e:
                        print('error adj_factor ' + code)
                        print(e)
                        time.sleep(0.1)
                if df1 is None:
                    continue

                factor = float(df1.at[0, 'adj_factor'])
                d = df.loc[0, :]
                bar = VtBarData()
                bar.vtSymbol = vtSymbol
                bar.symbol = vtSymbol
                bar.open = float(d['open']) * factor
                bar.high = float(d['high']) * factor
                bar.low = float(d['low']) * factor
                bar.close = float(d['price']) * factor
                bar.close_bfq = float(d['price'])
                date = d['date'].split('-')  #去掉字符串中间的'-'
                date = ''.join(date)
                bar.date = date
                bar.time = '00:00:00'
                bar.datetime = datetime.strptime(bar.date + ' ' + bar.time,
                                                 '%Y%m%d %H:%M:%S')
                bar.volume = float(d['volume'])

                p.onBar(bar)

        send_email(self.dss, 'worker_1450处理完毕', '')
Exemplo n.º 2
0
def has_factor(dss):

    r = []
    b1 = Book(dss)
    codes = b1.get_codes()

    for code in codes:
        df = get_adj_factor(dss, code)
        #print(df.head(2))
        if df.at[0, 'adj_factor'] != df.at[1, 'adj_factor']:
            r.append(code)
    return r
Exemplo n.º 3
0
    def worker_1450(self):
        """盘中推送bar"""
        to_log('in TradeEngine.worker_1450')

        for p in self.portfolio_list:
            for vtSymbol in p.vtSymbolList:
                #print(vtSymbol)
                df = None
                i = 0
                while df is None and i < 2:
                    try:
                        i += 1
                        df = ts.get_realtime_quotes(vtSymbol)
                    except Exception as e:
                        print('error get_realtime_quotes')
                        print(e)
                        time.sleep(0.1)

                if df is None:
                    to_log('ignore ' + vtSymbol)
                    continue

                adj_factor = None
                df1 = None
                i = 0
                while df1 is None and i < 2:
                    try:
                        i += 1
                        df1 = get_adj_factor(self.dss, vtSymbol)
                        adj_factor = float(df1.at[0, 'adj_factor'])
                    except Exception as e:
                        print('error adj_factor ' + vtSymbol)
                        print(e)
                        time.sleep(0.1)
                if df1 is None:
                    to_log('ignore ' + vtSymbol)
                    continue

                hfq_factor = get_hfq_factor(self.dss, vtSymbol)
                factor = hfq_factor
                if adj_factor is not None:
                    if abs((adj_factor - hfq_factor) /
                           adj_factor) > 0.01:  # 差异大,今天有除权
                        factor = adj_factor

                d = df.loc[0, :]
                bar = VtBarData()
                bar.vtSymbol = vtSymbol
                bar.symbol = vtSymbol
                bar.open = float(d['open']) * factor
                bar.high = float(d['high']) * factor
                bar.low = float(d['low']) * factor
                bar.close = float(d['price']) * factor
                bar.close_bfq = float(d['price'])
                date = d['date'].split('-')  #去掉字符串中间的'-'
                date = ''.join(date)
                bar.date = date
                bar.time = '00:00:00'
                bar.datetime = datetime.strptime(bar.date + ' ' + bar.time,
                                                 '%Y%m%d %H:%M:%S')
                bar.volume = float(d['volume'])

                #to_log(vtSymbol+' '+d['price']+' * '+str(factor)+' = '+str(bar.close))

                p.onBar(bar)

        send_email(self.dss, 'worker_1450处理完毕', '')
Exemplo n.º 4
0
    def worker_1450(self):
        """盘中推送bar"""
        to_log('in TradeEngine.worker_1450')

        print('begin worker_1450')
        r, dt = self.is_trade_day()
        if r == False:
            return

        self.currentDt = dt
        for vtSymbol in self.vtSymbolList:
            #print(vtSymbol)
            df = None
            i = 0
            while df is None and i < 3:
                try:
                    i += 1
                    df = ts.get_realtime_quotes(vtSymbol)
                except Exception as e:
                    print('error get_realtime_quotes')
                    print(e)
                    time.sleep(1)

            if df is None:
                continue

            code = vtSymbol
            df1 = None
            i = 0
            while df1 is None and i < 3:
                try:
                    i += 1
                    df1 = get_adj_factor(self.dss, code)
                except Exception as e:
                    print('error adj_factor')
                    print(e)
                    time.sleep(1)
            if df1 is None:
                continue

            factor = float(df1.at[0, 'adj_factor'])
            d = df.loc[0, :]
            bar = VtBarData()
            bar.vtSymbol = vtSymbol
            bar.symbol = vtSymbol
            bar.open = float(d['open']) * factor
            bar.high = float(d['high']) * factor
            bar.low = float(d['low']) * factor
            bar.close = float(d['price']) * factor
            bar.close_bfq = float(d['price'])
            date = d['date'].split('-')  #去掉字符串中间的'-'
            date = ''.join(date)
            bar.date = date
            bar.time = '00:00:00'
            bar.datetime = datetime.strptime(bar.date + ' ' + bar.time,
                                             '%Y%m%d %H:%M:%S')
            bar.volume = float(d['volume'])

            barDict = self.dataDict.setdefault(bar.datetime, OrderedDict())
            barDict[bar.vtSymbol] = bar

            self.portfolio.onBar(bar)

        send_email(self.dss, 'worker_1450处理完毕', '')