سادہ فکسڈ پرائس اسٹاپ لاس روبوٹ

Study Trade-aided
تخلیق کی تاریخ: 2018-10-10 15:35:41 آخر میں ترمیم کریں: 2019-07-03 16:41:50
کاپی: 53 کلکس کی تعداد: 4843
3
پر توجہ دیں
1444
پیروکار

ایک سادہ فکسڈ قیمت سٹاپ نقصان روبوٹ آپ کو نقصان کو روکنے میں مدد کرتا ہے۔ یہ ڈیجیٹل کرنسی کی مقدار میں تجارت کرنے کے لئے ایک اچھی ابتدائی حکمت عملی ہے۔

پیرامیٹر:

StopPrice:Fixed price to stop loss

Intervel: Intervel(second) of checking coin price

حکمت عملی کا ماخذ کوڈ
function CancelPendingOrders() {
    var orders = _C(exchange.GetOrders);
    for (var j = 0; j < orders.length; j++) {
        exchange.CancelOrder(orders[j].Id, orders[j]);
    }
}
function StopLoss(){
    var done = false
    while(!done){
        var ticker = _C(exchange.GetTicker)
        account = _C(exchange.GetAccount)
        var price = ticker.Buy
        var amount = account.Stocks
        try{
            if(amount > 0){
                var id = exchange.Sell(price, amount);
                if(id){
                    exchange.CancelOrder(id)
                }
                else{
                    Log('all coins are sold')
                    Log('total coins: ', account.Stocks)
                    done = true
                }
            }
        }catch(err){
            Log('error, stop')
            done = true
        }
        Sleep(1000);
    }
}
function main() {
    Log('robot starts to run')
    CancelPendingOrders()
    var account = _C(exchange.GetAccount)
    Log('total coins: ', account.Stocks);
    while(true){
        var ticker = _C(exchange.GetTicker)
        if(ticker.Last <= StopPrice){
            Log('Last price is:', ticker.Last, 'Stop price is: ', StopPrice)
            Log('the stop price has reached, start to sell')
            StopLoss();
            break;
        }
        Sleep(Intervel*1000)
    }
    Log('robot has stopped')
}