KiteConnect API,在烛台上打勾

时间:2018-10-05 14:23:15

标签: python api pyalgotrade

我想将报价数据存储到烛台中,并且我已经为此编写了代码。发生的是,当我运行代码时,即使我尝试为每个乐器都创建一个对象,但不同乐器的数据却混合在一起。我还在每个步骤检查工具令牌是否相同(我认为这是不必要的),这是我的代码,请让我知道是否有人可以诊断问题出在哪里。

我的班级:`班级公司:

def __init__(self, token):
    self.token = token

    self.open = []
    self.high = []
    self.low = []
    self.close = [] 
    self.ohlc_list = {}
    self.ohlc_list = [self.open,self.high,self.low,self.close]
    self.ohlc = {}
    self.ohlc = [0,0,0,0,True,60,0,];

def calc_ohlc(self, ticks, tf):

    for company_data in ticks:

        if((company_data['timestamp'].minute%tf == 0) and self.ohlc[4]==True):

            if(self.token == company_data['instrument_token']):
                self.ohlc[5] = company_data['timestamp'].minute + (tf-1)

            if(self.token == company_data['instrument_token']):
                self.ohlc[0] = company_data['last_price'];
                self.ohlc[1] = company_data['last_price']; 
                self.ohlc[2] = company_data['last_price']; 
                self.ohlc[3] = company_data['last_price']; 

            if(self.token == company_data['instrument_token']):
                self.ohlc_list[0].append(self.ohlc[0])
                self.ohlc[4]=False

        if(self.ohlc[4]==False):    

            if(company_data['last_price'] > self.ohlc[1]):

                self.ohlc[1] = company_data['last_price']           
                print("NEW HIGH",self.ohlc[1])

            if(company_data['last_price'] < self.ohlc[2]):

                self.ohlc[2] = company_data['last_price']           
                print("NEW HIGH",self.ohlc[2])

        if company_data['timestamp'].minute%self.ohlc[5] == 0 and company_data['timestamp'].second==59 and self.ohlc[4] == False:

            if(self.token == company_data['instrument_token']):
                self.ohlc[3] = company_data['last_price']
            if(self.token == company_data['instrument_token']):
                self.ohlc_list[1].append(self.ohlc[1])
                self.ohlc_list[2].append(self.ohlc[2])
                self.ohlc_list[3].append(self.ohlc[3])  
                self.ohlc[4] = True
            print("TIME", company_data['timestamp'])
            print(self.ohlc_list)

`

并为此创建对象(sym是对象列表):

for i in range(0,(len(trd_tkn1))):

sym.append(Company(trd_tkn1[i]))

以及从API接收报价的部分:

def on_ticks(ws, ticks):

for i in range(0,(len(trd_tkn1))):  
    sym.calc_ohlc(ticks,3)

0 个答案:

没有答案