资源加载中... loading...

Python简单测试策略

Author: Zero, Date: 2016-08-31 22:27:17
Tags: Python

需要下载最新的托管者, 托管者机器个需要安装python, (Linux自带无需安装)


import time
import talib

def main():
    LogProfitReset()
    LogReset()
    Log("init OK", time.strftime('%Y-%m-%d %X', time.localtime(time.time())))
    Log(a,b,c,d)
    _G("ok", 123)
    Log(GetPid(), _G(), _G("ok"), _G("dummy"))
    Sleep(1000)
    _G(None)
    Log(_G("ok"))

    LogStatus("Time", time.time())
    EnableLog(True)
    SetErrorFilter("net")
    Log(GetLastError())
    Log(GetCommand())
    ticker = exchange.GetTicker()
    Log('ticker buy', ticker.Buy, ticker['Buy']);
    
    r = _C(exchange.GetRecords)
    Log(TA.ATR(r))
    Log(TA.EMA(r, 10))
    # test talib
    Log(str(talib.EMA(r.Close, 10)))

    for e in exchanges:
        Log(e.GetName(), e.GetRate(), e.GetCurrency())
        Log(e.GetAccount())
        Log(_C(e.GetOrders))
        Log(e.GetOrder(10))
        Log(e.CancelOrder(10000))
 
        Log(e.GetUSDCNY())
        #Log(e.GetPosition())
        #Log(e.SetContractType("next_week"))
        Log(e.GetTicker())
        Log('Asks:', len(e.GetDepth().Asks))
        #Log(e.SetMarginLevel(10))
        #Log(e.SetDirection("buy"))
        #Log(e.SetContractType("quarter"))
        #Log(e.GetRecords(PERIOD_M30)[0])
        Log(e.GetRecords()[0])
    x = Chart({
        'title' : { 'text' : 'test chart'},
        'xAxis': { 'type': 'datetime'},
        'series' : [{'name' : 'Buy', 'data' : []}, {'name' : 'Sell', 'data' : []}]
        })
    x.reset()
    Log("策略将每10秒更新一次ticker");
    for i in range(100):
        ts = int(time.time() * 1000)
        ticker = _C(exchange.GetTicker)
        x.add(0, [ts, ticker.Buy])
        x.add(1, [ts, ticker.Sell])
        LogStatus(ticker)
        Sleep(10000)

Related

More

teddy 学习中,策略库里python的太少了,希望学会了以后自己能贡献几个

bb 谢谢零度前辈,100多人复制井然没人顶一个。。 对小白帮助挺大的,很多小技巧都没注意到,比如_C、_G、LogProfitReset()、LogReset()、SetErrorFilter("net")等 很实用的函数。 正好对着学习 用自己的理解注释了下。 https://dn-filebox.qbox.me/005c6fd29fce0abe1e1b04744407db7e3df48d18.png