Betfair how to increase and decrease orders

Please help me, this is very annoying. Not sure why my logic fails every time. I am trying to make Betfair the same step as in my web project. Betfair has its own pricing group which can be found here.

LINK: https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Betfair+Price+Increments

Here is the explanation: if the coefficients are 1.01 and some body wants to increase this coefficient with the html5 number counter, the increment will be 0.01, and if the coefficients are 2, then the increment will be 0.02. the entire list of increments is available at this link. a working example can be found at betfair betslip.

here is my Javascript:

function getIncremantal(fval) {
    var val = parseFloat(fval);
    var step;
    if (val <= 1.99) {
        step = 0.01;
    } else if (val > 2 && val < 3) {
        step = 0.02;
    } else if (val > 3 && val < 4) {
        step = 0.05;
    } else if (val > 4 && val < 6) {
        step = 0.1;
    } else if (val > 6 && val < 10) {
        step = 0.2;
    } else if (val > 10 && val < 19.5) {
        step = 0.5;
    } else if (val >= 20 && val < 30) {
        step = 1;
    } else if (val >= 30 && val < 50) {
        step = 2;
    } else if (val >= 50 && val < 100) {
        step = 5;
    } else if (val >= 100 && val < 1000) {
        step = 10;
    } else if (val > 1000) {
        step = null;
    }
    return step;
}

      

Update: jsFiddle http://jsfiddle.net/71fs0a67/1/

+3


source to share


3 answers


I tried the following which does not use number stepping, but if you use buttons it works. This is an alternative solution, sorry if it's not what you are looking for.

HTML:

<input type="number" min="1.01" max="1000" id="num"/>
<button class="increment">+</button>
<button class="decrement">-</button>

      

JavaScript:

$('.increment').on('click', function() {
    var elem = $('#num');
    var value = parseFloat(elem.val());
    var result = +(value + getIncremantal(value)).toFixed(2);
    elem.val(result);
});

$('.decrement').on('click', function() {
    var elem = $('#num');
    var value = parseFloat(elem.val());
    var result = +(value - getDecremantal(value)).toFixed(2);
    elem.val(result);
});

function getIncremantal(val) {
    var step;
    if (val < 2) {
        step = 0.01;
    } else if (val >= 2 && val < 3) {
        step = 0.02;
    } else if (val >= 3 && val < 4) {
        step = 0.05;
    } else if (val >= 4 && val < 6) {
        step = 0.1;
    } else if (val >= 6 && val < 10) {
        step = 0.2;
    } else if (val >= 10 && val < 20) {
        step = 0.5;
    } else if (val >= 20 && val < 30) {
        step = 1;
    } else if (val >= 30 && val < 50) {
        step = 2;
    } else if (val >= 50 && val < 100) {
        step = 5;
    } else if (val >= 100 && val < 1000) {
        step = 10;
    } else if (val > 1000) {
        step = null;
    }
    return step;
}

function getDecremantal(val) {
    var step;
    if (val <= 2) {
        step = 0.01;
    } else if (val > 2 && val <= 3) {
        step = 0.02;
    } else if (val > 3 && val <= 4) {
        step = 0.05;
    } else if (val > 4 && val <= 6) {
        step = 0.1;
    } else if (val > 6 && val <= 10) {
        step = 0.2;
    } else if (val > 10 && val <= 20) {
        step = 0.5;
    } else if (val > 20 && val <= 30) {
        step = 1;
    } else if (val > 30 && val <= 50) {
        step = 2;
    } else if (val > 50 && val <= 100) {
        step = 5;
    } else if (val > 100 && val <= 1000) {
        step = 10;
    } else if (val > 1000) {
        step = null;
    }
    return step;
}

      



http://jsfiddle.net/71fs0a67/7/

With jquery ui spinner you can do something like this:

$( "#spinner" ).spinner({
    min: 1.01,
    max: 1000,
    step: 0.01,
    spin: function( event, ui ) {
        event.preventDefault();
        event.stopPropagation();
        var value = this.value || ui.value;
        value = parseFloat(value);
        var step;
        if ($(event.currentTarget).hasClass('ui-spinner-up')) {
            step = getIncremantal(value);
            value = +(value + step).toFixed(2);
            $( "#spinner" ).spinner('value', value);
        } else {
            step = getDecremantal(value);
            value = +(value - step).toFixed(2);
            $( "#spinner" ).spinner('value', value);
        }
    }
});

      

http://jsfiddle.net/71fs0a67/9/

+1


source


Your code will return undefined

for integers.



Change all instances val > number

toval >= number

+1


source


Try the following:

function getIncremantal(fval) {
    var val = parseFloat(fval);
    var step;
    if (val < 2) {
        step = 0.01;
    } else if (val >= 2 && val < 3) {
        step = 0.02;
    } else if (val >= 3 && val < 4) {
        step = 0.05;
    } else if (val >= 4 && val < 6) {
        step = 0.1;
    } else if (val >= 6 && val < 10) {
        step = 0.2;
    } else if (val >= 10 && val < 20) {
        step = 0.5;
    } else if (val >= 20 && val < 30) {
        step = 1;
    } else if (val >= 30 && val < 50) {
        step = 2;
    } else if (val >= 50 && val < 100) {
        step = 5;
    } else if (val >= 100 && val < 1000) {
        step = 10;
    } else if (val > 1000) {
        step = null;
    }
    return step;
}

function getDecremantal(fval) {
    var val = parseFloat(fval);
    var step;
    if (val <= 2) {
        step = 0.01;
    } else if (val > 2 && val <= 3) {
        step = 0.02;
    } else if (val > 3 && val <= 4) {
        step = 0.05;
    } else if (val > 4 && val <= 6) {
        step = 0.1;
    } else if (val > 6 && val <= 10) {
        step = 0.2;
    } else if (val > 10 && val <= 20) {
        step = 0.5;
    } else if (val > 20 && val <= 30) {
        step = 1;
    } else if (val > 30 && val <= 50) {
        step = 2;
    } else if (val > 50 && val <= 100) {
        step = 5;
    } else if (val > 100 && val <= 1000) {
        step = 10;
    } else if (val > 1000) {
        step = null;
    }
    return step;
}

      

+1


source







All Articles