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.

Using future margin

See original GitHub issue
  • OS: Windows 10
  • Programming Language version: Python
  • CCXT version: 1.40.11

Hello, i’m trying to use ccxt to trade on binance future. I have lot of trouble with the doc to understand how it works 😕

So, first i create_market_buy_order, that work well. Then i put my stoploss / takeprofit. The problem is i don’t know if i don’t use correctly the library, or if i don’t use correctly the parameters to create a TAKE_PROFIT.

I have this error:

Traceback (most recent call last): File "main.py", line 93, in <module> buy(binance, crypto, price, r1, s1) File "main.py", line 41, in buy print(exchange.create_order('{}/USDT'.format(crypto), 'STOP', 'sell', size_to_buy, params)) File "/mnt/c/Projects/arbitrage/venv/lib/python3.8/site-packages/ccxt/binance.py", line 1655, in create_order request['price'] = self.price_to_precision(symbol, price) File "/mnt/c/Projects/arbitrage/venv/lib/python3.8/site-packages/ccxt/base/exchange.py", line 1285, in price_to_precision return self.decimal_to_precision(price, ROUND, self.markets[symbol]['precision']['price'], self.precisionMode, self.paddingMode) File "/mnt/c/Projects/arbitrage/venv/lib/python3.8/site-packages/ccxt/base/decimal_to_precision.py", line 55, in decimal_to_precision dec = decimal.Decimal(str(n)) decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]

Here my code

    exchange_class = getattr(ccxt, 'binance')
    binance = exchange_class({
        'apiKey': 'KEY',
        'secret': 'SECRET',
        'timeout': 3000,
        'enableRateLimit': True,
        'options': {
            'defaultType': 'future',  # ←-------------- quotes and 'future'
        },
    })
    
        crypto = 'KSM'
        size_to_buy = 2.8921478159368905
        params = {
        'quantity': size_to_buy,
        'price': float("{:0.0{}f}".format(r1 - (r1 * 10 / 100), 8)),
        'stopPrice': float("{:0.0{}f}".format(r1 - (r1 * 10 / 100), 8)),
        'type': 'TAKE_PROFIT',
    }
    binance.create_order('{}/USDT'.format(crypto), 'TAKE_PROFIT', 'sell', size_to_buy, params)

Can you help me please 😒 ?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kroitorcommented, Feb 3, 2021

@yanis7774 yep, looks like Binance has fixed the default limit to 500 and the max limit to 1500, as documented in their docs. I’ve pushed a fix for that, so if you upgrade to 1.41.53+ you will be able to get up to 1500 candles in a single request or all of them with pagination. Thank you for pointing it out! The new build will arrive in ~20 minutes.

1reaction
yanis7774commented, Feb 3, 2021

@yanis7774 hi! No, afaik Binance has limited the max number of candles to 500 on spot/futures markets.

I still can get more than 500 candles in early version of the lib (1.39.41 e.g.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

All About Margin on Futures Contracts - The Balance
The initial futures margin is the amount of money that you need in order to open a buy or sell on position on...
Read more >
Futures margin: capital requirements - TD Ameritrade
Margin tells traders how much capital may be needed to enter a position, and how much is needed to keep it open. Use...
Read more >
Understanding Margin in Futures Trading - NinjaTrader
Futures margin is the amount of money you must have in your brokerage account to protect both the trader and broker against possible...
Read more >
Margin on futures contracts | Alberta.ca
Summary. Margin money is a deposit to secure a futures position while it is open. Margins must be maintained at the level required...
Read more >
Understanding Futures Margin | Charles Schwab
Learn how changes in futures prices affect margin and your account.
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