- 策略广场
- 定投简单版
定投简单版
Author:
小码哥, Date: 2018-01-04 12:15:06
Tags:
辅助交易
// botvs@620e5a1b33965b615ef40e1d29cd2c44
/*backtest
start: 2017-12-01
end: 2018-01-01
period: 60
mode: 2
*/
function dateFormat(date, format) {
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ?
(o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return format;
}
function main() {
Log(exchange.GetAccount());
//最近一次投资的日期
var lastInvestDate = '';
while (true) {
//每次轮询,间隔时间为60秒
Sleep(60 * 1000);
//如果当前日期和最近一次投资日期相同,说明当天已经投过了,跳过
var date = dateFormat(new Date(), "yyyy-MM-dd");
if (date == lastInvestDate) {
continue;
}
lastInvestDate = date;
Log("日期: " + date);
//获取当前深度
var depth = exchange.GetDepth();
//以买1价挂一个买入单
var buy1price = depth.Bids[0].Price;
exchange.Buy(buy1price, singleInvestAmount / buy1price);
}
}
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6