成交事件

def OnTradeDeal(context, AccountName, trade) :
if trade.stgyflag == 1 : # 是本策略

# 卖开 if trade.bstype.BuySellFlag == '1' and trade.bstype.OffsetFlag == '0' : # 成交量累计 g.sum_vol_SK += trade.volume # 价量乘积之和 g.temp_SK += trade.volume * trade.price # 成交均价 if g.sum_vol_SK > 0 : g.SK_price_wma = g.temp_SK / g.sum_vol_SK print('g.sum_vol_SK = {} , g.SK_price_wma = {}'.format(g.sum_vol_SK, round(g.SK_price_wma, 4))) # 买平 if trade.bstype.BuySellFlag == '0' and trade.bstype.OffsetFlag == '1' : # 成交量累计 g.sum_vol_BP += trade.volume # 价量乘积之和 g.temp_BP += trade.volume * trade.price # 成交均价 if g.sum_vol_BP > 0 : g.BP_price_wma = g.temp_BP / g.sum_vol_BP print('g.sum_vol_BP = {} , g.BP_price_wma = {}'.format(g.sum_vol_BP, round(g.BP_price_wma, 4)))