binance-us / binance-us-api-docs

Official Documentation for the Binance US APIs and Streams
410 stars 169 forks source 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. #127

Open Codyb2021 opened 1 year ago

Codyb2021 commented 1 year ago
          `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 https://github.com/binance-us/binance-us-api-docs/issues/10#issuecomment-775573190