更新待办任务
This commit is contained in:
parent
92f4d2d02d
commit
195341b70c
@ -11,6 +11,14 @@ import mysql_database
|
|||||||
from EmailTest import send_email, parse_return_email
|
from EmailTest import send_email, parse_return_email
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
'''
|
||||||
|
todo
|
||||||
|
|
||||||
|
1 运行过程框架调整,支持多个turtle同时监测
|
||||||
|
2 增加运行状态写入yaml文件,读取文件恢复状态
|
||||||
|
'''
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BuyState:
|
class BuyState:
|
||||||
trigger_time: float # 触发次数
|
trigger_time: float # 触发次数
|
||||||
@ -620,31 +628,9 @@ class TurtleTrading_OnTime(object):
|
|||||||
Net_return=abs(self.turtle.Capital - available_cash))
|
Net_return=abs(self.turtle.Capital - available_cash))
|
||||||
self.turtle.tradeslog.append(sale_this_time)
|
self.turtle.tradeslog.append(sale_this_time)
|
||||||
|
|
||||||
def run_short_trading_loop(self):
|
def run_short_trading_loop(self, stock_data, etf_data):
|
||||||
while True:
|
|
||||||
# 获取当前时间
|
|
||||||
now = datetime.now().time()
|
now = datetime.now().time()
|
||||||
|
|
||||||
# 判断当前时间是否在交易时段内(9:30-11:30 或 13:00-15:00)
|
|
||||||
is_trading_time = (
|
|
||||||
(now.hour == 9 and now.minute >= 30) or
|
|
||||||
(now.hour == 10 and 0 <= now.minute <= 59) or
|
|
||||||
(now.hour == 11 and now.minute <= 30) or
|
|
||||||
(now.hour == 13 and 0 <= now.minute <= 59) or
|
|
||||||
(now.hour == 14 and 0 <= now.minute <= 59) or
|
|
||||||
(now.hour == 15 and now.minute <= 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# if not is_trading_time:
|
|
||||||
# # 非交易时间,等待 1 分钟后继续循环
|
|
||||||
# time.sleep(60)
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# 获取股票和ETF数据
|
|
||||||
stock_data, etf_data = self.get_stocks_data()
|
|
||||||
|
|
||||||
# 根据类型获取当前价格
|
# 根据类型获取当前价格
|
||||||
if self.turtle.type == "stock":
|
if self.turtle.type == "stock":
|
||||||
self.turtle.PriceNow = float(stock_data.loc[etf_data['代码'] == self.turtle.TradeCode, '最新价'].values[0])
|
self.turtle.PriceNow = float(stock_data.loc[etf_data['代码'] == self.turtle.TradeCode, '最新价'].values[0])
|
||||||
@ -745,7 +731,34 @@ class TurtleTrading_OnTime(object):
|
|||||||
self.turtle.CalPositionSize()
|
self.turtle.CalPositionSize()
|
||||||
|
|
||||||
# 每分钟获取一次数据,判断是否触发条件 9:30-11:30 13:00-15:00
|
# 每分钟获取一次数据,判断是否触发条件 9:30-11:30 13:00-15:00
|
||||||
self.run_short_trading_loop()
|
while True:
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now().time()
|
||||||
|
|
||||||
|
# 判断当前时间是否在交易时段内(9:30-11:30 或 13:00-15:00)
|
||||||
|
is_trading_time = (
|
||||||
|
(now.hour == 9 and now.minute >= 30) or
|
||||||
|
(now.hour == 10 and 0 <= now.minute <= 59) or
|
||||||
|
(now.hour == 11 and now.minute <= 30) or
|
||||||
|
(now.hour == 13 and 0 <= now.minute <= 59) or
|
||||||
|
(now.hour == 14 and 0 <= now.minute <= 59) or
|
||||||
|
(now.hour == 15 and now.minute <= 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if not is_trading_time:
|
||||||
|
# 非交易时间,等待 1 分钟后继续循环
|
||||||
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
|
is_stop_time = (now.hour > 15 and now.minute > 0) #收盘时间
|
||||||
|
if is_stop_time:
|
||||||
|
break
|
||||||
|
|
||||||
|
# 获取股票和ETF数据
|
||||||
|
stock_data, etf_data = self.get_stocks_data()
|
||||||
|
self.run_short_trading_loop(stock_data, etf_data)
|
||||||
# ------------------结束阶段--------------------
|
# ------------------结束阶段--------------------
|
||||||
# 数据库更新当天数据,增加ATR、donchian数据
|
# 数据库更新当天数据,增加ATR、donchian数据
|
||||||
# 直接做个新表
|
# 直接做个新表
|
||||||
@ -754,6 +767,7 @@ class TurtleTrading_OnTime(object):
|
|||||||
time.sleep(16.5*600)
|
time.sleep(16.5*600)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
user_email = "guoyize2209@163.com"
|
user_email = "guoyize2209@163.com"
|
||||||
t = TurtleTrading('513870', "etf", 0.0025, 100000, 200000)
|
t = TurtleTrading('513870', "etf", 0.0025, 100000, 200000)
|
||||||
# t.get_ready(100)
|
# t.get_ready(100)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user