vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 81
声望: 10

redis的安装设置就不说了大家自己找下教程
直接上代码

import redis
import zlib
import pickle
redis_client =redis.Redis("localhost",12580)
@lru_cache(maxsize=10)
def load_bar_data(
    symbol: str,
    exchange: Exchange,
    interval: Interval,
    start: datetime,
    end: datetime
):
    """bar数据redis序列化存取"""
    file_name = f"{symbol}_{exchange.value}_{start.date()}_{end.date()}_bar"
    redis_data = redis_client.hget(file_name, file_name)
    if not redis_data:
        bar_data = database_manager.load_bar_data( symbol, exchange, interval, start, end )
        redis_client.hset(file_name, file_name, zlib.compress(pickle.dumps(bar_data), 5))        
    else:
        bar_data = pickle.loads(zlib.decompress(redis_data))
    return bar_data


@lru_cache(maxsize=10)
def load_tick_data(
    symbol: str,
    exchange: Exchange,
    start: datetime,
    end: datetime
):
    """tick数据redis序列化存取"""
    file_name = f"{symbol}_{exchange.value}_{start.date()}_{end.date()}_tick"
    redis_data = redis_client.hget(file_name, file_name)
    if not redis_data:
        tick_data = database_manager.load_tick_data( symbol, exchange, start, end )
        redis_client.hset(file_name, file_name, zlib.compress(pickle.dumps(tick_data), 5))        
    else:
        tick_data = pickle.loads(zlib.decompress(redis_data))
    return tick_data
Member
avatar
加入于:
帖子: 81
声望: 10

😁😁😁我算错了,redis和pickle回测速度相差不到1秒,标题好像改不了......

Member
avatar
加入于:
帖子: 81
声望: 10

推荐大家用pickle本地持久化,这贴让它沉了吧

Administrator
avatar
加入于:
帖子: 1919
声望: 86

哈哈哈哈,正宗标题党

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3