Strategies KB.ZH
Strategies

冰山委托买入简单版Simple-Iceberg-order-to-buy

小草 · javascript · Tools and Appendix · 2020-03-20 16:24:13

All strategies →

Context terms

No English write-up in the source (no author description).

Read the Chinese version →

Parameters

ParametersDefaultDescription
BUYAMOUNT2amount to buy
BUYSIZE0.1iceberg order size
INTERVAL3orders exist time(second)
Source code (23 lines)
function main(){
    var initAccount = _C(exchange.GetAccount)
    while(true){
        var account = _C(exchange.GetAccount)
        var dealAmount = account.Stocks - initAccount.Stocks
        var ticker = _C(exchange.GetTicker)
        if(BUYAMOUNT - dealAmount > BUYSIZE){
            var id = exchange.Buy(ticker.Sell, BUYSIZE)
            Sleep(INTERVAL*1000)
            if(id){
                exchange.CancelOrder(id) // May cause error log when the order is completed, which is all right.
            }else{
                throw 'buy error'
            }
        }else{
            account = _C(exchange.GetAccount)
            var avgCost = (initAccount.Balance - account.Balance)/(account.Stocks - initAccount.Stocks)
            Log('Iceberg order to buy is done, avg cost is ', avgCost) // including fee cost
            return
        }
        
    }
}