就是我剛開始編寫比特幣高頻機器人的源代碼,幾乎沒有改動,參數也是原來的參數。這個版本的程序有許多要改進的地方,但即便如此,它也當時表現除了驚人的盈利能力,在我本金很少時,不加槓桿平均天天盈利在5%左右。固然不管從哪一方面,它都不適應今天的市場。我同時也發了一篇文章在社區,你們能夠看看。函數
這個策略原理極爲簡單,能夠理解爲準高頻的作市策略,各位看了以後可能想打人,這都能賺錢,當時幾乎誰都能寫出來。我開始也沒預料到它能這麼有效,可見心中有想法要趕忙付出實踐,說不必定有意外之喜。在比特幣機器人初興的2014年,寫出賺錢的策略太容易了。spa
策略源碼地址:https://www.fmz.com/strategy/1088code
稍微改了一下,用了平臺的容錯函數_C(),和精度函數_N().blog
function CancelPendingOrders() { var orders = _C(exchange.GetOrders); for (var j = 0; j < orders.length; j++) { exchange.CancelOrder(orders[j].Id, orders[j]);} } //計算將要下單的價格 function GetPrice(Type,depth) { var amountBids=0; var amountAsks=0; //計算買價,獲取累計深度達到預設的價格 if(Type=="Buy"){ for(var i=0;i<20;i++){ amountBids+=depth.Bids[i].Amount; //floatamountbuy就是預設的累計買單深度 if (amountBids>floatamountbuy){ //稍微加0.01,使得訂單排在前面 return depth.Bids[i].Price+0.01;} } } //同理計算賣價 if(Type=="Sell"){ for(var j=0; j<20; j++){ amountAsks+=depth.Asks[j].Amount; if (amountAsks>floatamountsell){ return depth.Asks[j].Price-0.01;} } } //遍歷了所有深度仍未知足需求,就返回一個價格,以避免出現bug return depth.Asks[0].Price } function onTick() { var depth=_C(exchange.GetDepth); var buyPrice = GetPrice("Buy",depth); var sellPrice= GetPrice("Sell",depth); //買賣價差若是小於預設值diffprice,就會掛一個相對更深的價格 if ((sellPrice - buyPrice) <= diffprice){ buyPrice-=10; sellPrice+=10;} //把原有的單子所有撤銷,實際上常常出現新的價格和已掛單價格相同的狀況,此時不須要撤銷 CancelPendingOrders() //獲取帳戶信息,肯定目前帳戶存在多少錢和多少幣 var account=_C(exchange.GetAccount); //可買的比特幣量 var amountBuy = _N((account.Balance / buyPrice-0.1),2); //可賣的比特幣量,注意到沒有倉位的限制,有多少就買賣多少,由於我當時的錢不多 var amountSell = _N((account.Stocks),2); if (amountSell > 0.02) { exchange.Sell(sellPrice,amountSell);} if (amountBuy > 0.02) { exchange.Buy(buyPrice, amountBuy);} //休眠,進入下一輪循環 Sleep(sleeptime); } function main() { while (true) { onTick(); } }