Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //float quantity for get rate,
  2. //isInverse bool, this product is a inverse of standard pair (get from ds_products.is_inverse)
  3. //spreads array, set of spreads objects (get from ds_products.Spread)
  4. //return rate float, bid rate of quantity
  5. function getBidRate(qty, isInverse, spreads) {
  6. var quoteType = ( isInverse ? 'inv_' : '' ) + 'bid';
  7. var buckets = (_.sortBy(spreads, function(o) { return o.min; })).reverse();
  8. var priceObj = _.find(buckets, function(price) {
  9. if(price.deleted_at) return false;
  10. return (price.min && qty >= price.min);
  11. });
  12. if (priceObj === undefined) { // if not match any range use default
  13. priceObj = _.find(buckets, function(price) {
  14. return price.is_default;
  15. });
  16. }
  17. var rate = priceObj[quoteType];
  18. return rate;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement