階段下注文,買えるか売れるか,プログラムが順番に单の間隔を押して購入または販売の注文数を指定することができます. 購入の場合,最初の单は最も高い価格の注文で,次の单の順番の価格は減少し,販売の注文は最も安い価格の注文で,次の価格が順番に増加します.
function adjustFloat(v) { return Math.floor(parseFloat(v.toFixed(10))*1000)/1000; } function GetAccount(e) { var account; while (!(account = exchange.GetAccount())) { Sleep(Interval); } return account; } function GetTicker() { var ticker; while (!(ticker = exchange.GetTicker())) { Sleep(1000); } return ticker; } function main() { var ticker = GetTicker(); var InitPrice = ticker.Last; if (EnableTrigger) { Log('当前价格: ', InitPrice, InitPrice > TriggerPrice ? '价格跌破' : '价格涨超', TriggerPrice, '时触发阶梯下单'); while (true) { if (InitPrice > TriggerPrice && ticker.Last < TriggerPrice) { Log('当前价格', ticker.Last, '价格跌破 ', TriggerPrice, '元, 开始下单'); break; } else if (InitPrice < TriggerPrice && ticker.Last > TriggerPrice) { Log('当前价格', ticker.Last, '价格涨超 ', TriggerPrice, '元, 开始下单'); break; } ticker = GetTicker(); Sleep(1000); } } var account = GetAccount(); var needMoney = 0; var needStocks = 0; for (var i = 0; i < OrderNum; i++) { needMoney += (StartPrice - (i * PriceDiff)) * Amount; needStocks += Amount; } if (OpType == 0) { if (needMoney > account.Balance) { throw "没有足够的钱下单"; } for (var i = 0; i < OrderNum; i++) { exchange.Buy(adjustFloat(StartPrice - (i * PriceDiff)), Amount); } } else { if (needStocks > account.Stocks) { throw "没有足够的币下单"; } for (var i = 0; i < OrderNum; i++) { exchange.Sell(adjustFloat(StartPrice + (i * PriceDiff)), Amount); } } Log("全部委托完成"); }