Administrator
2023-08-03 aabf5f98ad26e467645033c2cc80f5ff7e678aa2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
股票数据工具
"""
 
# 股票代码相关的参数
import decimal
import time
 
from code_attribute import gpcode_manager
from db import mysql_data, redis_manager
from db.redis_manager import RedisUtils
from utils import tool
 
_redisManager = redis_manager.RedisManager(0)
 
 
# 代码对应的价格是否正确
def is_same_code_with_price(code, price):
    if code == '600066':
        print('进入调试')
    # 昨日收盘价
    price_close = gpcode_manager.get_price_pre_cache(code)
    max_price = tool.to_price(decimal.Decimal(str(price_close)) * decimal.Decimal("1.1"))
    min_price = tool.to_price(decimal.Decimal(str(price_close)) * decimal.Decimal("0.9"))
    if min_price <= decimal.Decimal(str(price)) <= max_price:
        return True
    return False
 
 
# 自由流通股本工具类
class ZYLTGBUtil:
    @classmethod
    def save(cls, code, val, unit):
        redis = _redisManager.getRedis()
        RedisUtils.setex(redis,"zyltgb-{}".format(code), tool.get_expire(),
                    round(float(val) * 100000000) if int(unit) == 0 else round(
                        float(val) * 10000))
 
    @classmethod
    def get(cls, code):
        redis = _redisManager.getRedis()
        val = RedisUtils.get(redis, "zyltgb-{}".format(code))
        if val is not None:
            return int(val)
        return None
 
    @classmethod
    def save_list(self, datasList):
        # 保存自由流通市值
        mysqldb = mysql_data.Mysqldb()
        for data in datasList:
            # 保存
            _dict = {"_id": data["code"], "zyltgb": data["zyltgb"], "zyltgb_unit": data["zyltgb_unit"],
                     "update_time": int(round(time.time() * 1000))}
            if float(data["zyltgb"]) > 0:
                # 保存10天
                ZYLTGBUtil.save(data["code"], data["zyltgb"], data["zyltgb_unit"])
                result = mysqldb.select_one("select * from ths_zylt where _id='{}'".format(data["code"]))
                if result is None:
                    mysqldb.execute(
                        "insert into ths_zylt(_id,zyltgb,zyltgb_unit,update_time) values ('{}','{}',{},{})".format(
                            data["code"], data["zyltgb"], data["zyltgb_unit"], round(time.time() * 1000)))
                else:
                    mysqldb.execute(
                        "update ths_zylt set zyltgb='{}',zyltgb_unit={},update_time={} where _id='{}'".format(
                            data["zyltgb"], data["zyltgb_unit"], round(time.time() * 1000), data["code"]))
 
 
if __name__ == "__main__":
    redis = _redisManager.getRedis()
    keys = RedisUtils.keys(redis, "zyltgb-*")
    for key in keys:
        RedisUtils.delete(redis, key)