예제 #1
0
    def control_in_p(self, bar):
        try:
            for k in self.spread_dict.keys():
                s0 = self.spread_dict[k][0]
                s1 = self.spread_dict[k][1]
                if s0 not in self.got_dict or s1 not in self.got_dict:
                    continue
                if self.got_dict[s0] and self.got_dict[
                        s1] and self.process_dict[k] == False:
                    self.process_dict[k] = True
                    s0 = self.signalDict[s0][0]
                    s1 = self.signalDict[s1][0]

                    bar_s = VtBarData()
                    bar_s.vtSymbol = k
                    bar_s.symbol = k
                    bar_s.exchange = s0.bar.exchange
                    bar_s.date = s0.bar.date
                    bar_s.time = s0.bar.time

                    bar_s.close = s0.bar.close - s1.bar.close
                    bar_s.AskPrice = s0.bar.AskPrice - s1.bar.BidPrice
                    bar_s.BidPrice = s0.bar.BidPrice - s1.bar.AskPrice

                    # print(bar_s.time, bar_s.vtSymbol, bar_s.close, bar_s.AskPrice, bar_s.BidPrice)

                    self.engine.lock.acquire()
                    self.engine.bar_list.append(bar_s)
                    self.engine.lock.release()

        except Exception as e:
            s = traceback.format_exc()
            to_log(s)
예제 #2
0
    def control_in_p(self, bar):
        try:
            for k in self.spread_dict.keys():
                s0 = self.spread_dict[k][0]
                s1 = self.spread_dict[k][1]
                if s0 not in self.got_dict or s1 not in self.got_dict:
                    continue
                if self.got_dict[s0] and self.got_dict[
                        s1] and self.process_dict[k] == False:
                    self.process_dict[k] = True
                    s0 = self.bar_dict[s0]
                    s1 = self.bar_dict[s1]

                    bar_s = VtBarData()
                    bar_s.vtSymbol = k
                    bar_s.symbol = k
                    bar_s.exchange = s0.exchange
                    bar_s.date = s0.date
                    bar_s.time = s0.time

                    bar_s.close = s0.close - s1.close
                    bar_s.AskPrice = s0.AskPrice - s1.BidPrice
                    bar_s.BidPrice = s0.BidPrice - s1.AskPrice

                    # print(bar_s.time, bar_s.vtSymbol, bar_s.close, bar_s.AskPrice, bar_s.BidPrice)
                    df = pd.DataFrame([bar_s.__dict__])
                    cols = [
                        'date', 'time', 'open', 'high', 'low', 'close',
                        'volume'
                    ]
                    df = df[cols]
                    fname = get_dss() + 'fut/bar/min1_' + k + '.csv'
                    if os.path.exists(fname):
                        df.to_csv(fname, index=False, mode='a', header=False)
                    else:
                        df.to_csv(fname, index=False, mode='a')

                    return bar_s
        except Exception as e:
            s = traceback.format_exc()
            to_log(s)

        return None