Administrator
2022-09-20 5ae8b19fdc000fc719f3ad45fa5f7462fdbffbdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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")