Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //float quantity for get rate,
- //isInverse bool, this product is a inverse of standard pair (get from ds_products.is_inverse)
- //spreads array, set of spreads objects (get from ds_products.Spread)
- //return rate float, bid rate of quantity
- function getBidRate(qty, isInverse, spreads) {
- var quoteType = ( isInverse ? 'inv_' : '' ) + 'bid';
- var buckets = (_.sortBy(spreads, function(o) { return o.min; })).reverse();
- var priceObj = _.find(buckets, function(price) {
- if(price.deleted_at) return false;
- return (price.min && qty >= price.min);
- });
- if (priceObj === undefined) { // if not match any range use default
- priceObj = _.find(buckets, function(price) {
- return price.is_default;
- });
- }
- var rate = priceObj[quoteType];
- return rate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement