This commit is contained in:
botvs
2016-10-17 18:27:03 +08:00
parent 91877631be
commit b43494f563
4 changed files with 0 additions and 152 deletions
-73
View File
@@ -1,73 +0,0 @@
'''
策略出处: https://www.botvs.com/strategy/22600
策略名称: Python API测试
策略作者: iamjayson
策略描述:
需要下载最新的托管者, 托管者机器个需要安装python, (Linux自带无需安装)
参数 默认值 描述
---- ------- -------------------
a 1.2 number
b 你好hello str
c true bool
d 0 select: abc|def|xxx
'''
import time
import talib
def main():
_G("ok", 123)
_G(None)
Log(_G("ok"))
EnableLog(True)
SetErrorFilter("net")
LogStatus('这是一个普通的状态提示');
ticker = exchange.GetTicker()
Log('ticker buy', ticker.Buy, ticker['Buy']);
r = exchange.GetRecords()
Log(len(r))
Log(r[0])
Log(r[-1])
Log(TA.Highest(r, 10, 'High'))
Log(TA.Lowest(r, 10, 'Low'))
for e in exchanges:
Log(e.GetName(), e.GetRate(), e.GetCurrency(), e.GetFee())
Log(e.GetAccount())
Log(_C(e.GetOrders))
Log(e.GetOrder(10))
Log(e.CancelOrder(10000))
Log(e.IO("api", "userinfo"))
Log(e.IO("api", "order_info", "symbol=btc_usd&order_id=3"))
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)
-3
View File
@@ -4,16 +4,13 @@
> 开源策略列表
- [Python API测试](https://www.botvs.com/strategy/22600)
- [Python 机器学习之 SVM 预测买卖](https://www.botvs.com/strategy/21370)
- [这是为什么,请看first_bar 为什么后面的first_bar 变了](https://www.botvs.com/strategy/16309)
- [顺势_高频_交易_测试3](https://www.botvs.com/strategy/22183)
- [Python API 测试](https://www.botvs.com/strategy/21365)
- [均线策略(python版)](https://www.botvs.com/strategy/21157)
- [python版现货数字货币交易类库](https://www.botvs.com/strategy/21104)
- [顺势_高频_交易_测试2——失败](https://www.botvs.com/strategy/21938)
- [顺势_高频_交易_测试1](https://www.botvs.com/strategy/21742)
- [均线策略改版(python版) (复制)](https://www.botvs.com/strategy/21890)
- [CTP商品期货多品种海龟交易策略](https://www.botvs.com/strategy/17289)
- [各大平台API可用率统计](https://www.botvs.com/strategy/4404)
- [Dual Thrust 商品期货](https://www.botvs.com/strategy/13011)
@@ -1,48 +0,0 @@
'''
策略出处: https://www.botvs.com/strategy/21890
策略名称: 均线策略改版(python版) (复制)
策略作者: sy10001
策略描述:
均线策略(python版)教学性质,实盘慎用。
参数 默认值 描述
-------------- ----- ------
FastPeriod 3 入市快线周期
SlowPeriod 20 入市慢线周期
EnterPeriod 3 入市观察期
ExitFastPeriod 3 离市快线周期
ExitSlowPeriod 16 离市慢线周期
ExitPeriod true 离市观察期
PositionRatio 0.8 仓位比例
Interval 10 轮询周期
'''
import types
def main():
STATE_IDLE = -1
state = STATE_IDLE
initAccount = ext.GetAccount()
Log(initAccount)
while True:
if state == STATE_IDLE :
n = ext.Cross(FastPeriod,SlowPeriod) # 指标交叉函数
if abs(n) >= EnterPeriod :
opAmount = _N(initAccount.Stocks * PositionRatio,3)
Dict = ext.Buy(opAmount) if n > -0.04 else ext.Sell(opAmount)
if Dict :
opAmount = Dict['amount']
state = PD_LONG if n >-0.04 else PD_SHORT
Log("开仓详情",Dict,"交叉周期",n)
else:
n = ext.Cross(ExitFastPeriod,ExitSlowPeriod) # 指标交叉函数
if abs(n) >= ExitPeriod and ((state == PD_LONG and n < 0) or (state == PD_SHORT and n > 0)) :
nowAccount = ext.GetAccount()
Dict2 = ext.Sell(nowAccount.Stocks - initAccount.Stocks) if state == PD_LONG else ext.Buy(initAccount.Stocks - nowAccount.Stocks)
state = STATE_IDLE
nowAccount = ext.GetAccount()
LogProfit(nowAccount.Balance - initAccount.Balance,'钱:',nowAccount.Balance,'币:',nowAccount.Stocks,'平仓详情:',Dict2,'交叉周期:',n)
Sleep(Interval * 1000)
@@ -1,28 +0,0 @@
/*
策略出处: https://www.botvs.com/strategy/16309
策略名称: 这是为什么,请看first_bar 为什么后面的first_bar 变了
策略作者: 青铜战国级机器人
策略描述:
xxx
*/
/* 非常感谢满意沟通的解决方案,对于GetRecords 得到的数据类型来说,数组中的元素依然是类似字典
元素,是可变对象,slice只是进行了浅拷贝,数组中的元素是索引,而回测是最后一条bar是修改而来,所以造成first_bar也改变了,
加上deepCopy 能够解决这个问题*/
function deepCopy(Ele) {
return JSON.parse(JSON.stringify(Ele));
}
function main(){
var records, fist_bar, sec_bar;
records = exchange.GetRecords();
first_bar = deepCopy(records.slice(-1)[0]);
Log("first_bar:", first_bar);
Sleep(10000);
records = exchange.GetRecords();
sec_bar = deepCopy(records.slice(-1)[0]);
Log("sec_bar:", sec_bar);
Log("first_bar:", first_bar);
}