Simple Iceberg order to buy (Copy)

Author: The grass, Date: 2020-03-20 16:37:02
Tags: StudyTrade-aidedIceberg

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

Iceberg order buy, split the order into small M buy, avoid market shock, is a good simple introduction to Bitcoin quantitative trading learning strategy The plug-in can be started at the touch of a button on the transaction terminal, without charging a fee, and facilitates manual transactions.https://www.fmz.com/digest-topic/5051


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)
            return 'Iceberg order to buy is done, avg cost is '+avgCost
        }
        
    }
}

Related

More