This commit is contained in:
root
2016-04-19 23:58:28 +08:00
parent 1de21789c0
commit 7198c1cfd3
4 changed files with 29 additions and 33 deletions
+2 -2
View File
@@ -4,6 +4,8 @@
> 开源策略列表
- [商品期货交易类库](https://www.botvs.com/strategy/12961)
- [各大平台API可用率统计](https://www.botvs.com/strategy/4404)
- [窜天猴 - 移动止损版](https://www.botvs.com/strategy/13594)
- [窜天猴 多空较量 爆破版](https://www.botvs.com/strategy/13597)
- [均线策略 30 行打造一个正向收益系统](https://www.botvs.com/strategy/12348)
@@ -11,13 +13,11 @@
- [Dual Thrust 商品期货](https://www.botvs.com/strategy/13011)
- [平台价格指标监控1.1](https://www.botvs.com/strategy/12442)
- [数字货币交易类库](https://www.botvs.com/strategy/10989)
- [商品期货交易类库](https://www.botvs.com/strategy/12961)
- [高精度回测](https://www.botvs.com/strategy/11575)
- [从第三方网站获取K线](https://www.botvs.com/strategy/12977)
- [函数自动容错模板](https://www.botvs.com/strategy/11609)
- [Dual Thrust OKCoin 期货](https://www.botvs.com/strategy/12101)
- [差价监控](https://www.botvs.com/strategy/1340)
- [各大平台API可用率统计](https://www.botvs.com/strategy/4404)
- [RSI_now_sb_ok](https://www.botvs.com/strategy/11604)
- [自定义K线周期转换](https://www.botvs.com/strategy/11216)
- [模板库使用例子](https://www.botvs.com/strategy/10991)
+11 -18
View File
@@ -13,19 +13,6 @@ Interval 10 检测频率(秒)
TickCount 200 采样数量
*/
function _N(v, precision) {
if (typeof(precision) != 'number') {
precision = 4;
}
var d = parseFloat(v.toFixed(Math.max(10, precision+5)));
s = d.toString().split(".");
if (s.length < 2 || s[1].length <= precision) {
return d;
}
var b = Math.pow(10, precision);
return Math.floor(d*b)/b;
}
function _D(t) {
if (typeof(t) == 'undefined') {
@@ -77,6 +64,7 @@ function ExchangeManager(e, idx) {
} else {
this.Last = _N(ticker.Last, 3);
}
this.ticker = ticker;
this.tickerChanged = true;
};
@@ -84,6 +72,7 @@ function ExchangeManager(e, idx) {
if (ticker) {
this.tickerChanged = _N(ticker.Last, 3) != this.Last;
this.Last = _N(ticker.Last, 3);
this.ticker = ticker;
}
arr.push(ticker);
if (arr.length > TickCount) {
@@ -169,11 +158,13 @@ function EnsureCall(method) {
function main() {
if (typeof(SetFailover) === 'function') {
SetFailover(true);
Log('SetFailover OK');
}
var keys = [];
var table = {
type: 'table',
title: '行情信息',
cols: ['交易所', '买一', '卖一', '最后成交价', '最高', '最低', '交易量'],
rows: []
};
var es = [];
for (var i = 0; i < exchanges.length; i++) {
var m = new ExchangeManager(exchanges[i], i);
@@ -238,8 +229,10 @@ function main() {
if (es[i].tickerChanged) {
chart.add([1, es[i].Last, es[i].idx]);
}
var ticker = es[i].ticker;
table.rows[i] = [es[i].GetLabel(), ticker.Buy, ticker.Sell, ticker.Last + '#ff0000', ticker.High, ticker.Low, ticker.Volume];
}
LogStatus("最后更新于: " + _D());
LogStatus('最后更新于: ' + _D() +'\n`' + JSON.stringify(table) + '`');
Sleep(Interval*1000);
}
}
+12 -13
View File
@@ -4,17 +4,17 @@
策略作者: Zero
策略描述:
商品期货交易类库
```
function main() {
var p = $.NewPositionManager();
p.OpenShort("MA609", 1);
Sleep(60000 * 10);
p.Cover("MA609");
LogProfit(p.Profit());
}
```
商品期货交易类库
```
function main() {
var p = $.NewPositionManager();
p.OpenShort("MA609", 1);
Sleep(60000 * 10);
p.Cover("MA609");
LogProfit(p.Profit());
}
```
`不断完善中...`
@@ -24,7 +24,6 @@ Interval 500 失败重试间隔(毫秒)
SlidePrice 0.1 下单滑价(元)
*/
function GetPosition(e, contractType, direction) {
var allCost = 0;
var allAmount = 0;
@@ -68,7 +67,7 @@ function Open(e, contractType, direction, opAmount) {
if (isFirst) {
isFirst = false;
} else {
positionNow = GetPosition(contractType, direction);
positionNow = GetPosition(e, contractType, direction);
if (positionNow) {
needOpen = opAmount - (positionNow.Amount - initAmount);
}
+4
View File
@@ -48,6 +48,10 @@ function main() {
}
} else {
var ticker = exchange.GetTicker();
if (!ticker) {
Sleep(Interval*1000);
continue;
}
var dynamicProfit = 0;
var shouldCover = false;
var enableTS = false;