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.

{"code":-2015,"msg":"Invalid API-key, IP Getting with private_post_order_oco (but ID works with everything else)

See original GitHub issue
  • OS: Linux (Ubuntu)
  • Programming Language version: Python 3.7
  • CCXT version:

Hi, I am working with the Binance TESTNET. I have used this same ID to create LIMIT and MARKET orders with no issue - but - when I try to create an OCO order, I get permission errors.

What am I doing wrong?

TIA

    def futures_open_oco_order ( self, in_symbol : str  = '' , in_side : str = '',  in_amount : float = 0,
            in_stop_price : float = 0, in_limit_price : float = 0, in_last_chance_price : float = 0 ):


[... snip ...]
            # get the IDs together before going any further
            server_params  = {}
            mainLocalID    = t_tradeid.get_unique_id( self.client_id )
            mainXChangeID  = t_tradeid.generate_xchange_id( mainLocalID )
            server_params['newClientOrderId'] = mainXChangeID

            response = self.exchange.fapiPrivate_get_positionside_dual()

            if not (response['dualSidePosition']):
                response = self.exchange.fapiPrivatePostPositionSideDual ({'dualSidePosition':'true'})

            # now set up the account so that it is ISOLATED
            try:
                response = self.exchange.fapiPrivate_post_margintype({ 'symbol': market['id'],
                    'marginType': 'ISOLATED',  })

            except ccxt.ExchangeError as f: # issue similar to the -4046 one above
                 if ( f.args[0].find("-4046") == -1 ): #
                    raise  # (otherwise CONTINUE processing)

[... snip ...]
            # set up variables to be passed in
            symbol  = market['id']

[... snip...]
            retval = self.exchange.private_post_order_oco({
                'symbol': symbol,
                'side': side,
                'quantity': self.exchange.amount_to_precision(symbol, amount),
                'price': self.exchange.currency_to_precision( quote_currency, abs(float( in_last_chance_price ))),
                'stopPrice': self.exchange.currency_to_precision( quote_currency, abs(float(in_stop_price))),
                'stopLimitPrice': self.exchange.currency_to_precision( quote_currency, abs(float( in_limit_price ))),
                'positionSide': self.position_side[side],
                'listClientOrderId' : mainXChangeID,
                'limitClientOrderId': mainXChangeID + '-L',
                'stopClientOrderId' : mainXChangeID + '-S',
            })

[ ... snip ...]

The error I am getting is as follows:

error binance {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}

The ID works with the LIMIT and MARKET order creation functionalities fine.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
2pdcommented, Dec 7, 2020

Binance support OCO orders on :

  • SPOT: yes for production and testnet
  • Futures: No for production or testnet
0reactions
kroitorcommented, Dec 6, 2020

@cadmufasa

My understanding is that the Testnet does not support Margins at this time - correct? Will try this on the SPOT exchange

Yes, that’s correct, however, I’d still recommend to confirm this with Binance’s API support channel on Telegram, so that you have the info first-hand.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binance Future api : APIError(code=-2015): Invalid API-key, IP ...
In my code, I have a "client" variable: client = Client(config.API_KEY, config.API_SECRET, tld='us'). and, here's the thing:.
Read more >
why do I see this error "Invalid API-key, IP, or permissions for ...
This is a common issue and many asked from API users. The reason is just as said from error message: API key is...
Read more >
Binance Futures Invalid API-key, IP, or permissions for action
Hi, I am trying to connect to the Futures servers on Binance (and access the contents in the Futures Wallet) I had created...
Read more >
Your Google API Key is not valid for this request - WordPress.org
Hello! Just trying to setup this plugin, and I'm getting the message “Error: Your Google API Key is not valid for this request...
Read more >
Can't sync binance without ip : r/CoinStats - Reddit
Hi all When i try to sync a binance account to Coinstats, i have the following error message : "Invalid API-key, IP, or...
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