Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIN_NOTIONAL is one of several values that define a minimum quantity required in an order for any given crypto. In addition to it, you will need to ensure your order quantity is equal or greater than LOT_SIZE. Finally, your order must be within the LOT_SIZE => stepSize value. Ex: given that stepSize = 1, your order quantity must be a whole number. #127

Open
Codyb2021 opened this issue Jun 17, 2023 · 0 comments

Comments

@Codyb2021
Copy link

          `MIN_NOTIONAL` is one of several values that define a minimum quantity required in an order for any given crypto. In addition to it, you will need to ensure your order quantity is equal or greater than `LOT_SIZE`. Finally, your order must be within the `LOT_SIZE => stepSize` value. Ex: given that `stepSize = 1`, your order quantity must be a whole number. 

These values can be found in the "filters" array returned by the GET /api/v3/exchangeInfo endpoint.

If you'd rather understand what I'm saying as code, here is a full ruby example that I quickly threw together:

      symbol = 'ADABTC'
      info = Binance::Api.exchange_info!( # GET /api/v3/exchangeInfo
        api_key: user.binance_api_token,
        api_secret_key: user.binance_api_secret,
      )[:symbols].find { |e| e[:symbol] == symbol }
      raise Binance::Api::Error.new "#{symbol} not found in exchange info" if info.nil?
      min_lot_size = -> do
        filter = info[:filters].find { |f| f[:filterType] == "LOT_SIZE" }
        raise Binance::Api::Error.new "LOT_SIZE not found in exchange info for #{symbol}" if filter.nil?
        filter[:minQty].to_d
      end
      min_notional = -> do
        filter = info[:filters].find { |f| f[:filterType] == "MIN_NOTIONAL" }
        raise Binance::Api::Error.new "MIN_NOTIONAL not found in exchange info for #{symbol}" if filter.nil?
        filter[:minNotional].to_d
      end
      step_size = -> do
        filter = info[:filters].find { |f| f[:filterType] == "LOT_SIZE" }
        raise Binance::Api::Error.new "LOT_SIZE not found in exchange info for #{symbol}" if filter.nil?
        filter[:stepSize].to_d
      end
      quantity = [
        (min_notional.call / current_price.to_d) + step_size.call - ((min_notional.call / current_price.to_d) % step_size.call),
        min_lot_size.call,
      ].max

The result of this code is a quantity variable that represents the absolute minimum quantity required for an order to succeed. Hope this helps!

Disclaimer: I'm the author of binance-ruby.

Originally posted by @0xjmp in #10 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant