ViewBlock / binance-api-node

:chart: A complete and heavily tested wrapper with typings for the Binance API.
654 stars 495 forks source link

Add proper types for futuresExchangeInfo #649

Open valentiniljaz opened 8 months ago

valentiniljaz commented 8 months ago

Exchange info for Futures API uses different structure then the API for Spot. PR contains new types for ExchangeInfo that reflect the actual state of the API.

Source of truth for the change is:

bennycode commented 8 months ago

@valentiniljaz thank you very much for making this PR 🙇‍♂️ Can you also change MIN_NOTIONAL = 'MIN_NOTIONAL' into MIN_NOTIONAL = 'NOTIONAL' as per our discovery (see https://github.com/ViewBlock/binance-api-node/pull/643#issuecomment-1752898623)?

valentiniljaz commented 8 months ago

@valentiniljaz thank you very much for making this PR 🙇‍♂️ Can you also change MIN_NOTIONAL = 'MIN_NOTIONAL' into MIN_NOTIONAL = 'NOTIONAL' as per our discovery (see #643 (comment))?

Both filters: SPOT and FUTURES are still called "MIN_NOTIONAL". Only the property for Futures Symbol Filter is changed to "notional". That's why I would not change MIN_NOTIONAL => NOTIONAL. Or did you have something else in mind?

bennycode commented 8 months ago

@valentiniljaz If I call this.client.exchangeInfo() then I am getting returned products with a NOTIONAL filter type instead of a MIN_NOTIONAL type. Is it the same for you?

Example:

{
  "allowedSelfTradePreventionModes": [
    "NONE",
    "EXPIRE_TAKER",
    "EXPIRE_MAKER",
    "EXPIRE_BOTH"
  ],
  "allowTrailingStop": true,
  "baseAsset": "ETH",
  "baseAssetPrecision": 8,
  "baseCommissionPrecision": 8,
  "cancelReplaceAllowed": true,
  "defaultSelfTradePreventionMode": "NONE",
  "filters": [
    {
      "filterType": "PRICE_FILTER",
      "maxPrice": "922327.00000000",
      "minPrice": "0.00001000",
      "tickSize": "0.00001000"
    },
    {
      "filterType": "LOT_SIZE",
      "maxQty": "100000.00000000",
      "minQty": "0.00010000",
      "stepSize": "0.00010000"
    },
    {
      "filterType": "ICEBERG_PARTS",
      "limit": 10
    },
    {
      "filterType": "MARKET_LOT_SIZE",
      "maxQty": "2829.36596416",
      "minQty": "0.00000000",
      "stepSize": "0.00000000"
    },
    {
      "filterType": "TRAILING_DELTA",
      "maxTrailingAboveDelta": 2000,
      "maxTrailingBelowDelta": 2000,
      "minTrailingAboveDelta": 10,
      "minTrailingBelowDelta": 10
    },
    {
      "askMultiplierDown": "0.2",
      "askMultiplierUp": "5",
      "avgPriceMins": 5,
      "bidMultiplierDown": "0.2",
      "bidMultiplierUp": "5",
      "filterType": "PERCENT_PRICE_BY_SIDE"
    },
    {
      "applyMaxToMarket": false,
      "applyMinToMarket": true,
      "avgPriceMins": 5,
      "filterType": "NOTIONAL",
      "maxNotional": "9000000.00000000",
      "minNotional": "0.00010000"
    },
    {
      "filterType": "MAX_NUM_ORDERS",
      "maxNumOrders": 200
    },
    {
      "filterType": "MAX_NUM_ALGO_ORDERS",
      "maxNumAlgoOrders": 5
    }
  ],
  "icebergAllowed": true,
  "isMarginTradingAllowed": true,
  "isSpotTradingAllowed": true,
  "ocoAllowed": true,
  "orderTypes": [
    "LIMIT",
    "LIMIT_MAKER",
    "MARKET",
    "STOP_LOSS_LIMIT",
    "TAKE_PROFIT_LIMIT"
  ],
  "permissions": [
    "SPOT",
    "MARGIN",
    "TRD_GRP_004",
    "TRD_GRP_005",
    "TRD_GRP_006",
    "TRD_GRP_008",
    "TRD_GRP_009",
    "TRD_GRP_010",
    "TRD_GRP_011",
    "TRD_GRP_012",
    "TRD_GRP_013",
    "TRD_GRP_014",
    "TRD_GRP_015",
    "TRD_GRP_016",
    "TRD_GRP_017",
    "TRD_GRP_018",
    "TRD_GRP_019",
    "TRD_GRP_020",
    "TRD_GRP_021",
    "TRD_GRP_022",
    "TRD_GRP_023"
  ],
  "quoteAsset": "BTC",
  "quoteAssetPrecision": 8,
  "quoteCommissionPrecision": 8,
  "quoteOrderQtyMarketAllowed": true,
  "quotePrecision": 8,
  "status": "TRADING",
  "symbol": "ETHBTC"
}
valentiniljaz commented 8 months ago

@bennycode Referring to the official docs https://binance-docs.github.io/apidocs/spot/en/#filters

There are two distinct filters: MIN_NOTIONAL and NOTIONAL. As of this moment "binance-api-node" does not provide types for filter NOTIONAL.

With additional investigation there appears to be more missing types for Symbol Filters: PERCENT_PRICE_BY_SIDE ICEBERG_PARTS MAX_NUM_ICEBERG_ORDERS MAX_POSITION TRAILING_DELTA and NOTIONAL

and for Exchange Filter: EXCHANGE_MAX_NUM_ICEBERG_ORDERS

I think it's better to prepare new PR just for these filters. What do you think?

valentiniljaz commented 8 months ago

I have edited the PR and added the missing filters for Spot. I've also decoupled Futures filters from Spot.

Take a look and let me know if there's anything else that I can do