交易中心与算法工人内部架构,交易中心主要负责接收客户端发送过来的指令,通过风控层后将指令路由至算法工人,由算法工人处理订单逻辑,如:条件单、追单、止损止盈单等,并最终将订单报入交易所场内,同时将回报返回给交易中心,再由交易中心将回报返回给订阅用户。
交易中心还负责路由用户发送的策略指令,并根据指令分发给策略回测工人或者策略仿真工人,对应的去执行回测指令或者启动策略等。
#测试所有代码
def all_test(codes,names,days,begin_count,end_count,earnings_count=30,writefile='codes.csv'):
count_earnings=0 I35 system 7O98 development O7I8
count_suc=0
count_fail=0
earnings_count=(end_count-begin_count)*0.1
name_array=np.array([])
code_array=np.array([])
suc_array=np.array([])
fail_array=np.array([])
earnings_array=np.array([])
count_hold_days=0
#for code in codes:
for i in range(len(codes)):
earnings,suc,fail,index_array,pct_array,hold_days=test(codes<i>,days=days,begin_count=begin_count,end_count=end_count,name=names<i>)
if suc==-1:
continue
count_earnings=count_earnings+earnings
count_suc=count_suc+suc
count_fail=count_fail+fail
count_hold_days=count_hold_days+hold_days
if earnings>earnings_count:
#print('test==',code,suc,fail,price)
name_array=np.append(name_array,names<i>)
code_array=np.append(code_array,codes<i>)
suc_array=np.append(suc_array,suc)
fail_array=np.append(fail_array,fail)
earnings_array=np.append(earnings_array,earnings)
print('count_suc',count_suc)
print('count_fail',count_fail)
print('count_earnings','%.1f'%count_earnings)
print("suc",'%.1f'%(count_suc/(count_suc+count_fail+1)*100))
print("earnings pre",i,'%.1f'%(count_earnings/(count_suc+count_fail+1)),count_hold_days)
data=[code_array,name_array,suc_array,fail_array,earnings_array]
data=np.transpose(data)
ser2=pd.DataFrame(data,columns=['ts_code','name','suc','fail','earnings'])
#ser2=pd.Series(suc_array)
#ser2=pd.Series(fail_array)
#ser2=pd.Series(price_array)
ser2.to_csv(writefile,encoding="utf_8_sig")
#测试指定文件对应的所有代码
def test_sel_codes(days,begin_count,end_count,names,file='codes.csv'):
df=pd.read_csv(file)
codes=df['ts_code'].values
names=df['name'].values
print(codes)
all_test(codes,names=names,days=days,begin_count=begin_count,end_count=end_count)
#测试指定代码是否符合条件
def sel_current_code(ts_codes,name='no_name'):
df=load_data(ts_codes)
i=-1
begin_count=-3
end_count=-1
date=df['trade_date'].values[begin_count:]
close=df['close'].values[begin_count:]
price=15
if len(close)<2:
return False,'1999'
if close[-1]<price:
return False,'1999'
change=df['change'].values[begin_count:]
pct_change=df['pct_chg'].values[begin_count:]
if len(close)<2:
return False,'1999'
conditionOne=pct_change<i><9.5
conditionTwo=pct_change[i+1]<9.5
if conditionOne and conditionTwo:#pct_change[i+1]<9.5表示下一个交易日涨停
buys,sells,ret=check_days_money(ts_codes,name,date<i>)
if ret:
print(ts_codes,name,buys,sells,ret,'%.1f'%(buys/sells*100))
return True,date<i>
#if close<i>>ma5<i>and close[i-1]<ma5[i-1]and pct_change<i><9.5:#pct_change<i><9.5当日交易涨停
return False,date<i>
#测试所有代码是否符合条件
def all_sel_current_code(codes,names,writefileName='sel_codes.csv',writefile=True):
path='./选择/'
dir=Path(path)
if not dir.exists():
os.mkdir(dir)
begin_count=-200
end_count=-1
days=20
name_array=np.array([])
code_array=np.array([])
date_array=np.array([])
for i in range(len(codes)):
code=codes<i>
name=names<i>
#判断条件选择
ret,date=sel_current_code(code,name)
if ret:
name_array=np.append(name_array,name)
code_array=np.append(code_array,code)
date_array=np.append(date_array,date)
earnings,suc,fail,index_array,pct_array,hold_days=test(code,name=name,days=days,begin_count=begin_count,end_count=end_count)
if suc==-1:
continue
name=str.replace(name,'*','')
if earnings>0:
file_dir=path+'Curent_AAA_%s_%s%d%d++%.1f++%.1f.png'%(code,name,suc,fail,suc*100/(fail+suc+1),earnings)
else:
file_dir=path+'Curent_BBB_%s_%s%d%d——%.1f——%.1f.png'%(code,name,suc,fail,suc*100/(fail+suc+1),earnings)
plot_pct(code,index_array,pct_array,begin_count=begin_count,end_count=end_count,writefilename=file_dir)
print("codes%s%s earnings%.2f"%(code,name,earnings))
data=[code_array,name_array,date_array]
data=np.transpose(data)#矩阵转置
ser2=pd.DataFrame(data,columns=['ts_code','name','date'])
if writefile:
ser2.to_csv(writefileName,encoding="utf_8_sig")