Loading ...

Buy then Sell (ping-pong strategy)

Author: 小草, Date: 2018-10-11 15:31:49
Tags: Study Trade-aided

如题,可设定买入价格,买入成功后自动挂卖出价格卖出,


function CancelPendingOrders() {
    var orders = _C(exchange.GetOrders);
    for (var j = 0; j < orders.length; j++) {
        exchange.CancelOrder(orders[j].Id, orders[j]);
    }
}
function main() {
    Log('robot starts to run')
    if(BUYPRICE >= SELLPRICE){
        throw 'check buy and sell price'
    }
    CancelPendingOrders()
    var account = _C(exchange.GetAccount)
    var init_account = account
    Log('account: ', account.Balance);
    if(account.Balance > BUYPRICE*BUYAMOUNT){
        exchange.Buy(BUYPRICE, BUYAMOUNT);
    }else{
        throw 'account balances is not enough'
    }
    while(true){
        account = _C(exchange.GetAccount)
        if(account.Stocks >= init_account.Stocks + 0.01){
            exchange.Sell(SELLPRICE, account.Stocks - init_account.Stocks)
        }
        Sleep(Intervel*1000)
    }
}


Related

More