功能实现:开盘前将所有持仓标的挂跌停出。
一键清仓
python代码如下;
1.实现四舍五入,5进位,不要忽略前一位是偶数就不进的bug
def round_up(n, m):
n = str(n)
if len(n) - n.index(".") - 1 == m + 1:
n += "1"
return round(float(n), m)
if __name__ == "__main__":
print(round_up(0.125, 2))
2.获取持仓信息,并完成下单
def round_up(n, m):
n = str(n)
if len(n) - n.index(".") - 1 == m + 1:
n += "1"
return round(float(n), m)
def test_sell(code,price,amount):
dlg.type_keys('{F2}').type_keys(code).type_keys('{ENTER}').type_keys(price).type_keys('{ENTER}').type_keys(amount).type_keys('{ENTER}')
def position_0():
#获取资金持仓
today_total_assets = user.position
for i in range(len(today_total_assets)):
code = today_total_assets[i]['证券代码']
amount = today_total_assets[i]['可申赎数量']
if amount==0:
continue
price = today_total_assets[i]['市价']
price_down = round_up((price*0.9), 2)
print(str(code)+' '+str(price_down)+' '+str(amount))
#1.etrader下单
user.sell(code,price = price_down,amount =amount)
#2.修改的xiadan
test_sell(code=code, price=price_down, amount=amount)
#登录自动交易模块
if __name__ == "__main__":
#1.初始化
#1.1 同花顺客户端初始化
user = easytrader.use('universal_client') # 同花顺客户端
user.prepare(user='', password='', comm_password='', exe_path='C:\同花顺软件\同花顺\xiadan.exe')
#下单初始化
app = Application("uia").connect(title_re = "网上股票交易系统5.0") # 按照窗口句柄链接 handle
dlg = app.window(title_re = "网上股票交易系统5.0")
#一键清仓
print(time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time())))
position_0()
print(time.strftime('%Y.%m.%d %H:%M:%S ',time.localtime(time.time())))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)