1 Star 0 Fork 16

johnxu88/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
timehandle.py 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2017-12-18 15:46 . no commit message
#coding=utf-8
import datetime
import time
from threading import Timer
class MyTimer:
#count==-1 无限次
def __init__(self, sec, count, fun, *args, **kwargs):
self._tm = sec
self._fn = fun
self.count = count
self.args = args
self.kwargs = kwargs
self.isStart = True
def _do_func(self):
if self._fn:
self._fn(self.args, self.kwargs)
self._do_start()
def _do_start(self):
if self.isStart:
if self.count > 0:
self.count -= 1
if self.count == 0:
self.isStart = False
self._timer = Timer(self._tm, self._do_func)
self._timer.start()
else:
print("the timer is stoped!")
def start(self):
self.isStart = True
self._do_start()
def stop(self):
try:
self.isStart = False
self._timer.cancel()
print("the timer is stoped!")
except:
pass
def join(self):
self._timer.join()
def dayCount(newdf, olddf):
newday = str(newdf.iloc[0]['date'])
oldday = str(olddf.iloc[0]['date'])
d1 = datetime.datetime.strptime(newday, "%Y-%m-%d").date()
d2 = datetime.datetime.strptime(oldday, "%Y-%m-%d").date()
if d1 <= d2:
return 0
daycount = (d1 - d2).days
cnt = 0
mc = min(daycount, len(newdf.index))
for i in xrange(0, mc):
if str(newdf.iloc[i]['date']) == oldday :
break
cnt = cnt + 1
return cnt
def is_same_week(date1, date2):
d1 = datetime.datetime.strptime(date1, "%Y-%m-%d").date()
d2 = datetime.datetime.strptime(date2, "%Y-%m-%d").date()
daycount = (d1 - d2).days
if daycount == 0:
return True
if daycount > 4:
return False
for i in xrange(1, daycount+1):
date = d1 - datetime.timedelta(days=i)
if is_weekend(date):
return False
return True
def is_weekend(date):
return date.weekday() in [5,6]
def is_not_tradetime(date):
t = date.time()
opentime = datetime.time(9,30,0)
endtime = datetime.time(15,0,0)
if t < opentime or t > endtime:
return True
return False
def now():
return datetime.datetime.now()
def timestamp():
now = datetime.datetime.now()
ans_time = int(time.mktime(now.timetuple()))
return ans_time
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/johnxu88/traderStock-gui.git
[email protected]:johnxu88/traderStock-gui.git
johnxu88
traderStock-gui
traderStock-gui
master

搜索帮助