import decimal
|
import random
|
import time as t
|
import datetime
|
|
import global_util
|
|
|
def get_expire():
|
now = int(t.time())
|
end = int(t.time()) + 60 * 60 * 24
|
local_time = t.strftime("%Y-%m-%d", t.localtime(end))
|
end = int(t.mktime(t.strptime(local_time, "%Y-%m-%d")))
|
expire = end - now
|
# 加随机数,防止一起销毁数据
|
expire += random.randint(0, 60 * 60)
|
return expire
|
|
|
def get_now_date():
|
date = datetime.datetime.now()
|
return date
|
|
|
# 转为价格,四舍五入保留2位小数
|
def to_price(_decimal):
|
return _decimal.quantize(decimal.Decimal("0.00"), decimal.ROUND_HALF_UP)
|
|
|
# 是否为交易时间
|
def is_trade_time():
|
# 测试
|
if global_util.TEST:
|
return True
|
|
relative_timestamp = t.time() % (24 * 60 * 60) + 8 * 60 * 60
|
start1 = 60 * 60 * 9 + 24 * 60;
|
end1 = 60 * 60 * 11 + 35 * 60;
|
start2 = 60 * 60 * 12 + 50 * 60;
|
end2 = 60 * 60 * 15 + 5 * 60;
|
if start1 < relative_timestamp < end1 or start2 < relative_timestamp < end2:
|
return True
|
else:
|
return False
|
|
|
if __name__=="__main__":
|
d1 = decimal.Decimal("0.12")
|
d2 = decimal.Decimal("0.12")
|
if d1==d2:
|
print("123")
|