question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binance: Exchange Error {"code":-3028,"msg":"Not a valid margin pair."}

See original GitHub issue

Hi ccxt team!

I am getting constant {"code":-3028,"msg":"Not a valid margin pair."} errors from Binance when executing market orders on them even tho I am using the ‘margin’ defaultType on initialization .

  • OS: macOS
  • Programming Language version: node 12.x
  • CCXT version: ccxt@1.43.94
// init binance in margin mode
const binance = new ccxt.binance({
  options: {
    'defaultType': 'margin',
  },
})

// fetch markets, with explicit refresh and explicit type
const allMarkets = await this.exchange.loadMarkets(true,  {type: 'margin'})

// then I filter the markets to only give me margin=true pairs
const marginMarkets =  markets.filter((m) => {
      return m.active && m.margin && m.type === 'margin' && m.info.isMarginTradingAllowed
})

Even tho the filtered marginMarkets now only contains pairs with margin: true I still get the above mentioned error message from the exchange on some pairs.

Here is one of the pairs which are in marginMarkets but should not be as they dont seem to be supported. Also they do not show up in the Binance GET /sapi/v1/margin/allPairs listing.

Notice how it has "isMarginTradingAllowed": true, "margin": true and "type": "margin" set to indicate margin trading is allowed and possible.

// binance.markets["ENJ/BTC"]:

{
  "limits": {
    "amount": {
      "min": 1,
      "max": 90000000
    },
    "price": {
      "min": 1e-8,
      "max": 1000
    },
    "cost": {
      "min": 0.0001
    },
    "market": {
      "min": 0,
      "max": 418478.30902778
    }
  },
  "precision": {
    "base": 8,
    "quote": 8,
    "amount": 0,
    "price": 8
  },
  "tierBased": false,
  "percentage": true,
  "taker": 0.001,
  "maker": 0.001,
  "id": "ENJBTC",
  "lowercaseId": "enjbtc",
  "symbol": "ENJ/BTC",
  "base": "ENJ",
  "quote": "BTC",
  "baseId": "ENJ",
  "quoteId": "BTC",
  "info": {
    "symbol": "ENJBTC",
    "status": "TRADING",
    "baseAsset": "ENJ",
    "baseAssetPrecision": 8,
    "quoteAsset": "BTC",
    "quotePrecision": 8,
    "quoteAssetPrecision": 8,
    "baseCommissionPrecision": 8,
    "quoteCommissionPrecision": 8,
    "orderTypes": ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"],
    "icebergAllowed": true,
    "ocoAllowed": true,
    "quoteOrderQtyMarketAllowed": true,
    "isSpotTradingAllowed": true,
    "isMarginTradingAllowed": true,
    "filters": [{
      "filterType": "PRICE_FILTER",
      "minPrice": "0.00000001",
      "maxPrice": "1000.00000000",
      "tickSize": "0.00000001"
    }, {
      "filterType": "PERCENT_PRICE",
      "multiplierUp": "5",
      "multiplierDown": "0.2",
      "avgPriceMins": 5
    }, {
      "filterType": "LOT_SIZE",
      "minQty": "1.00000000",
      "maxQty": "90000000.00000000",
      "stepSize": "1.00000000"
    }, {
      "filterType": "MIN_NOTIONAL",
      "minNotional": "0.00010000",
      "applyToMarket": true,
      "avgPriceMins": 5
    }, {
      "filterType": "ICEBERG_PARTS",
      "limit": 10
    }, {
      "filterType": "MARKET_LOT_SIZE",
      "minQty": "0.00000000",
      "maxQty": "418478.30902778",
      "stepSize": "0.00000000"
    }, {
      "filterType": "MAX_NUM_ORDERS",
      "maxNumOrders": 200
    }, {
      "filterType": "MAX_NUM_ALGO_ORDERS",
      "maxNumAlgoOrders": 5
    }],
    "permissions": ["SPOT", "MARGIN"]
  },
  "type": "margin",
  "spot": false,
  "margin": true,
  "future": false,
  "delivery": false,
  "active": true
}

Executing a type MARKET trade on this pair results in the error mentioned above. The code works perfectly in all spot markets, so price and amount rounding issues are not the issue.

binance.createOrder(
          order.symbol, //  "ENJ/BTC"
          order.type, // "MARKET"
          order.side, // "buy"
          order.amount, // 5
          undefined, 
          {
             sideEffectType: 'MARGIN_BUY' // enable auto-borrow
          } 
        )

Does this problem arise from binance API delivering wrong results, by CCXT providing wrong data for market pairs or from my approach in getting margin-only markets? (I know, I could use the implicit method for sapi/v1/margin/allPairs but I’d rather use the unified call - which should yield the same data)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
strikeoutcommented, Mar 22, 2021

Small update:

I’ve checked the binance Website and API directly and it seems that, at least the above mentioned pair ENJ/BTC, does in fact allow margin trading, but only on isolated margin. I have not found any indication or differentiator via the API market data endpoint about this tho.

1reaction
kroitorcommented, Mar 22, 2021

@strikeout yes, that is possible, let me think a bit on how we can better unify this across the exchanges, i will be back to you shortly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"code":-3028,"msg":"Not a valid margin pair."
Hi, i'm trying to create margin order but get this error: {“code”:-3028,“msg”:“Not a valid margin pair.”}. I cant find more deeper explanation of...
Read more >
Updates to API Key Permission Rules (2021-07-26) - Binance
If your API Key has whitelisted IP address(es), the "Enable Spot & Margin Trading" permission will not expire. The new rules are valid...
Read more >
Coding a Binance Trading Bot that detects new coins the ...
>> code”:-3028,”msg”:”Not a valid margin pair. — Now im using the method create_order to get the money from SPOT wallet. 2- in line...
Read more >
Binance.US Review 2022 | NextAdvisor with TIME
Trading pairs vary between exchanges depending on the various cryptocurrencies offered. Binance.US Fees. Binance.US has an option to ...
Read more >
Binance Python API – A Step-by-Step Guide - Algo Trading 101
There is also a recommendation and link to it in the Binance API documentation. CCXT is a good option if you plan to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found