Loading ...

Simple Iceberg order to sell

Author: botvsing, Date: 2018-10-13 11:22:03
Tags: Study Trade-aided Iceberg

Very simple, just for learn. Code is best annotation.

冰山委托卖出,将订单分成小笔卖出,避免冲击市场,是很好的简单入门比特币量化交易的学习策略


function main(){
    var initAccount = _C(exchange.GetAccount)
    if (initAccount.Stocks < SELLAMOUNT){
        throw 'check your account amount to sell'
    }
    while(true){
        var account = _C(exchange.GetAccount)
        var dealAmount =  initAccount.Stocks - account.Stocks
        var ticker = _C(exchange.GetTicker)
        if(SELLAMOUNT - dealAmount > SELLSIZE){
            var id = exchange.Sell(ticker.Buy, SELLSIZE)
            Sleep(INTERVAL*1000)
            if(id){
                exchange.CancelOrder(id) // May cause error log when the order is completed, which is all right.
            }else{
                throw 'sell error'
            }
        }else{
            account = _C(exchange.GetAccount)
            var avgCost = (account.Balance - initAccount.Balance)/(initAccount.Stocks - account.Stocks)
            Log('Iceberg order to sell is done, avg price is ', avgCost) // including fee cost
            return
        }
    }
}

Related

More

botvsing 新手入门的选择,程序化交易不仅是完成完整的策略,这样的类似冰山委托的小功能也可以