The resource loading... loading...

I ask the gods about the trade classification statistics.

Author: xaifer48, Created: 2022-08-18 12:56:23, Updated: 2022-08-20 16:07:39

Dear friends, I want to separate the transaction volume in a cycle K into two types of buy/sell, for example, a K-string diagram of a 1-minute cycle, which shows the corresponding volume of transactions in each of the two types of buy/sell. My idea is that when there is no new K-line production, the trade data is obtained and aggregated, and then after the new K-line is generated, the cumulative trade data is classified statistically, the parameters of the number are rearranged, and entered the next cycle. However, a problem arises when using real-time retesting, one is that the statistically calculated transaction data does not match the transaction data of the actual each K-line records[-2][Volume array], the difference is large, the statistically calculated buy-to-let transaction plus the sell-to-order transaction is larger than the transaction volume shown by the records[-2][Volume array]. The code is as follows, it has been around me for two days. Please tell me if there is a problem with logic or if the retest itself will have this problem. If there is a problem with logic, please indicate in detail, thank you.

def GetRecords(self):
if self.LastBarTime == self.BarTime:
    trades = _C(exchange.GetTrades)
    if trades :
        for i in range (len(trades)):
            if trades[i] not in self.trades:
                 self.trades.append(trades[i])
if self.LastBarTime != self.BarTime: #新K线 
    if self.trades :
        for i in range (len(self.trades)):
            if self.trades[i]["Type"] == 0 : #买单
                self.trade_buy.append(self.trades[i])
            if self.trades[i]["Type"] == 1 : #卖单
                self.trade_sell.append(self.trades[i])
        if self.trade_buy:
            for i in range (len(self.trade_buy)):
                self.totlebuyamount += self.trade_buy[0-i]["Amount"]
        if self.trade_sell:
            for i in range (len(self.trade_sell)):
                self.totlesellamount += self.trade_sell[0-i]["Amount"]
        Log("总成交量",self.totlebuyamount+self.totolesellamoun,"买单成交量",self.totlebuyamount,"卖单成交量",self.totolesellamount) 
        self.trades = []
        self.trade_buy = []
        self.trade_sell = []
        self.totlebuyamount = 0
        self.totlesellamount  = 0

More

Inventors quantify - small dreamsThe order flow to be retested is simulated.

xaifer48Thank you.

Inventors quantify - small dreamsThe digital currency market is based on order flow data, trades data, etc.

xaifer48Dreams, is there a problem with the logic of writing code this way? I looked it up http://www.fmz.cn/strategy/291843、https://www.quantinfo.com/Article/View/2334.html both articles are tick data, not trade, or is it to use tick data to make a good class?