掘金社区

掘金python sdk是不是有内存泄露Pinned highlighted

gscq 发表在掘金2 2015-10-11 02:57:39

掘金2
655
1
0

把test_backtest_cw_config_ini.py加一个循环

# !/usr/bin/env python
# -*- coding: utf-8 -*-
from gmsdk.api import StrategyBase


class MyStrategy(StrategyBase):
    def __init__(self, *args, **kwargs):
        super(MyStrategy, self).__init__(*args, **kwargs)
        self.oc = True

    def on_bar(self, bar):
        if self.oc:
            self.open_long(bar.exchange, bar.sec_id, 0, 100)
        else:
            self.close_long(bar.exchange, bar.sec_id, 0, 100)
        self.oc = not self.oc


if __name__ == '__main__':
    for i in range(1, 200):
        ret = MyStrategy(config_file='test_backtest.ini').run()
        print(i, 'exit code: ', ret)

用以下配置文件试试:

[strategy]
username=demo@myquant.cn
password=123456
strategy_id=strategy_2
subscribe_symbols=DCE.l1509.bar.60, DCE.l1509.tick
mode=4
td_addr=localhost:8001

[backtest]
start_time=2015-07-02 9:00:00
end_time=2015-07-02 15:30:00
initial_cash=1000000
transaction_ratio=1
commission_ratio=0
slippage_ratio=0

运行一下,内存稳步增长:

评论: 1

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.