经过测试,目前完成了这个策略。支持多策略,支持全市场,包括股票,etf,可转债
全部的参数
{
"雪球跟单":"跟单原理",
"原理":"比重变大默认买入,变小默认卖出,持股不追加,支持多策略跟单",
"雪球cookie":"cookiesu=241715400714727; device_id=a3ef10a376ef5247ffa076b3f60cda63; smidV2=20240511121735f94708a388b3849549dd32f49888adb60042a1a6f570c88a0; remember=1; xq_is_login=1; u=1342909666; s=cb127hrtpz; bid=f1b5e01be977a7023f9ec859cdf24ad4_lw1xly5z; __utmz=1.1715421398.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); xq_a_token=8d2185ec88fc34490976cbe2eb4caf7d6961e32e; xqat=8d2185ec88fc34490976cbe2eb4caf7d6961e32e; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOjEzNDI5MDk2NjYsImlzcyI6InVjIiwiZXhwIjoxNzE5MTk1Mzc4LCJjdG0iOjE3MTY2MDMzNzgxMjIsImNpZCI6ImQ5ZDBuNEFadXAifQ.Sjy6h4gQ8nX3P1QvfN8d1jaozlDCQ_z4fPU1gnU97hmcEbDlAQE9tZ5_SAB2uVHJgUvmXEKKlHPWhNHnipI404hz5I0AxAXAod1nAAXUu9xyRlpN5HvISph3snFPInKOrDYas6Pf7mtunhHXHvdiCtt0j__P2hOyA0VevN3Mqc34a6NJDh2yftTIXWpDVAI03hHo1izuEuA9Reld-7OX8H_KGfFGbIN0frJFfvR_KiTadHK_hJK4LafSetP71-RC1qgouIcB2Eb4tS_IANZ8G-ETk9Y-6DW2_SwffzEUiCNscRvGmzCMy9XPWA5413QphlGdfbgk2rN7enArOVx3Cw; xq_r_token=d8d877c6634c1dccc7472835539149f69c6f9f70; Hm_lvt_1db88642e346389874251b5a1eded6e3=1716392246,1716473979,1716554527,1716603379; acw_tc=276077ab17166051880926379e31d55708918c25a7b1b7778b05ec078e0cb6; __utma=1.694453535.1715421398.1715524198.1716605549.4; __utmc=1; __utmt=1; .thumbcache_f24b8bbe5a5934237bbc0eda20c1b6e7=yLJiLZESXni8VXn3zlUOJUOfp16pud99AQIv/v5OtCn72W3NDQ3kBY3tY4OxOBlzf3eoH+ByDMs2DcwGjEhdMw%3D%3D; __utmb=1.2.10.1716605549; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1716605925",
"组合名称":["实验"],
"组合id":["ZH3368671"],
"不同策略间隔更新时间":0.05,
"同步持股说明":"同步持股就是买入目前的持股,不然就同步成交",
"资金模式":"雪球",
"资金模式说明":"雪球/自定义",
"雪球资金设置":"设置**********************",
"账户跟单比例":0.5,
"自定义资金设置":"设置————————下面设置分析配置是参考,保持和分析配置里面一样————————————————",
"交易模式":"金额",
"固定交易资金":10000,
"持有金额限制":10000,
"固定交易数量":100,
"持有限制":100,
"持股限制":10,
"下单交易模式":"立马下单",
"下单交易模式说明":"立马下单/通过综合交易模型"
}
雪球cookie直接账户的cookie自己获取
组合id支持多组合,多个组合用逗号隔开比如[1,2,3]
重点在下, 的交易模式
"同步持股说明":"同步持股就是买入目前的持股,不然就同步成交",
"资金模式":"雪球",
"资金模式说明":"雪球/自定义",
"雪球资金设置":"设置**********************",
"账户跟单比例":0.5,
"自定义资金设置":"设置————————下面设置分析配置是参考,保持和分析配置里面一样————————————————",
"交易模式":"金额",
"固定交易资金":10000,
"持有金额限制":10000,
"固定交易数量":100,
"持有限制":100,
"持股限制":10,
"下单交易模式":"立马下单",
"下单交易模式说明":"立马下单/通过综合交易模型"
资金模式 雪球完全按雪球的模式交易,按比例进行调整仓位,这个模式好完全自带匹配账户资金,比如你账户有10万买入1%就是1000,比如你账户有100万,调整1%就是自动匹配账户自己,下面的就自定义资金的,"下单交易模式":"立马下单",直接下单不用排队,速度非常的快,还在直接看源代码快
def start_trader_on(self):
'''
开始下单
'''
with open(r'{}\雪球跟单设置.json'.format(self.path),encoding='utf-8') as f:
com=f.read()
text=json.loads(com)
df=pd.read_excel(r'{}\下单股票池\下单股票池.xlsx'.format(self.path))
try:
del df['Unnamed: 0']
except:
pass
#资金模式
cash_models=text['资金模式']
#下单模式
trader_models=text['下单交易模式']
#自定义资金设置
data_type=text['交易模式']
value=text['固定交易资金']
limit_value=text['持有金额限制']
amount1=text['固定交易数量']
limit_amount=text['持股限制']
if df.shape[0]>0:
df['证券代码']=df['证券代码'].astype(str)
#print(df['证券代码'])
df['证券代码']=df['证券代码'].apply(lambda x: '0'*(6-len(str(x)))+str(x))
if cash_models=='雪球' and trader_models=='通过综合交易模型':
buy_df=df[df['交易方向']=='buy']
if buy_df.shape[0]>0:
buy_df=buy_df[['证券代码','证券名称','自动价格','价格','交易类型','数量','交易状态']]
buy_df.to_excel(r'自定义买入股票\自定义买入股票.xlsx')
else:
print('{} {} 没有买入股票'.format(cash_models,trader_models))
sell_df=df[df['交易方向']=='sell']
if sell_df.shape[0]>0:
sell_df=sell_df[['证券代码','证券名称','自动价格','价格','交易类型','数量','交易状态']]
sell_df.to_excel(r'自定义卖出股票\自定义卖出股票.xlsx')
else:
print('{} {} 没有卖出股票'.format(cash_models,trader_models))
elif cash_models=='自定义' and trader_models=='通过综合交易模型':
buy_df=df[df['交易方向']=='buy']
if buy_df.shape[0]>0:
buy_df=buy_df[['证券代码','证券名称','交易状态']]
buy_df.to_excel(r'买入股票\买入股票.xlsx')
else:
print('{} {} 没有买入股票'.format(cash_models,trader_models))
sell_df=df[df['交易方向']=='sell']
if sell_df.shape[0]>0:
sell_df=sell_df[['证券代码','证券名称','交易状态']]
sell_df.to_excel(r'卖出股票\卖出股票.xlsx')
else:
print('{} {} 没有卖出股票'.format(cash_models,trader_models))
#先卖在买
elif cash_models=='雪球' and trader_models=='立马下单':
sell_df=df[df['交易方向']=='sell']
if sell_df.shape[0]>0:
for stock,amount in zip(sell_df['证券代码'],sell_df['数量']):
try:
price=self.data.get_spot_data(stock=stock)['最新价']
self.trader.sell(security=stock,price=price,amount=amount)
print('{} {} 卖出 股票{} 数量{} 价格{}'.format(cash_models,trader_models,stock,amount,price))
except Exception as e:
print(e)
print(print('{} {} 卖出 股票{} 有问题'.format(cash_models,trader_models,stock)))
else:
print('{} {} 没有卖出股票'.format(cash_models,trader_models))
buy_df=df[df['交易方向']=='buy']
if buy_df.shape[0]>0:
for stock,amount in zip(buy_df['证券代码'],buy_df['数量']):
try:
price=self.data.get_spot_data(stock=stock)['最新价']
self.trader.buy(security=stock,price=price,amount=amount)
print('{} {} 买入 股票{} 数量{} 价格{}'.format(cash_models,trader_models,stock,amount,price))
except Exception as e:
print(e)
print(print('{} {} 买入 股票{} 有问题'.format(cash_models,trader_models,stock)))
else:
print('{} {} 没有买入股票'.format(cash_models,trader_models))
#先卖在买
elif cash_models=='自定义' and trader_models=='立马下单':
sell_df=df[df['交易方向']=='sell']
if sell_df.shape[0]>0:
for stock in sell_df['证券代码'].tolist():
try:
price=self.data.get_spot_data(stock=stock)['最新价']
trader_type,amount,price=self.trader.check_av_target_trader(data_type=data_type,trader_type='sell',
amount=amount1,limit_volume=limit_amount,value=value,limit_value=limit_value,
stock=stock,price=price)
if trader_type=='sell':
self.trader.sell(security=stock,price=price,amount=amount)
print('{} {} 卖出 股票{} 数量{} 价格{}'.format(cash_models,trader_models,stock,amount,price))
else:
print('{} {} 卖出 股票{} 数量{} 价格{} 不可以交易'.format(cash_models,trader_models,stock))
except Exception as e:
print(e)
print(print('{} {} 卖出 股票{} 有问题'.format(cash_models,trader_models,stock)))
else:
print('{} {} 没有卖出股票'.format(cash_models,trader_models))
buy_df=df[df['交易方向']=='buy']
if buy_df.shape[0]>0:
for stock,amount in zip(buy_df['证券代码'],buy_df['数量']):
try:
price=self.data.get_spot_data(stock=stock)['最新价']
trader_type,amount,price=self.trader.check_av_target_trader(data_type=data_type,trader_type='buy',
amount=amount1,limit_volume=limit_amount,value=value,limit_value=limit_value,
stock=stock,price=price)
if trader_type=='buy':
self.trader.buy(security=stock,price=price,amount=amount)
print('{} {} 买入 股票{} 数量{} 价格{}'.format(cash_models,trader_models,stock,amount,price))
else:
print('{} {} 买入 股票{} 数量{} 价格{} 不可以交易'.format(cash_models,trader_models,stock))
except Exception as e:
print(e)
print(print('{} {} 买入 股票{} 有问题'.format(cash_models,trader_models,stock)))
else:
print('{} {} 没有买入股票'.format(cash_models,trader_models))
else:
print('未知的下单模式***********************')
else:
print('没有需要下单的数据**************************')
后面我给完整的教程设置
源代码全部上次了不懂的问我就可以