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.

AttributeError: 'SpotExchange' object has no attribute 'futures_leverage'

See original GitHub issue

Hi,

I have a problem when I run backtest on Spot mode. The problem appear at the very end of the trading session, when we compute stats :

[2021-02-05T00:00:00+00:00]: Terminating strategy...
============================== EXCEPTION TRACEBACK:
  File "/Users/floriancabirol/miniconda3/bin/jesse", line 8, in <module>
    sys.exit(cli())
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/__init__.py", line 329, in backtest
    json=json)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/modes/backtest_mode/__init__.py", line 59, in run
    simulator(candles)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/modes/backtest_mode/__init__.py", line 287, in simulator
    r.strategy._terminate()
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/strategies/Strategy.py", line 897, in _terminate
    round(self.position.pnl_percentage, 2)
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/models/Position.py", line 71, in pnl_percentage
    return self.roi
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/models/Position.py", line 79, in roi
    return self.pnl / self.total_cost * 100
  File "/Users/floriancabirol/miniconda3/lib/python3.7/site-packages/jesse/models/Position.py", line 89, in total_cost
    return self.entry_price * abs(self.qty) / self.exchange.futures_leverage
=========================================================================

My config :


Binance': {
            'fee': 0.001,

            # backtest mode only: accepted are 'spot' and 'futures'
            'type': 'spot',

            # futures mode only
            'settlement_currency': 'USDT',
            # accepted values are: 'cross' and 'isolated'
            'futures_leverage_mode': 'cross',
            # 1x, 2x, 10x, 50x, etc. Enter as integers
            'futures_leverage': 1,

            # used for spot exchange only
            'assets': [
                {'asset': 'USDT', 'balance': 10_000},
                {'asset': 'BTC', 'balance': 0},
            ],
        },

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ThatCheckcommented, Feb 13, 2021

I have found a temporary fix but works only if you are in spot because it disable the leverage on futures.

Go to models/Position.py and replace L89 by :

return self.entry_price * abs(self.qty) / 1

0reactions
cryptocoinservercommented, Mar 8, 2021

Fixed thanks to @discohead

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: module 'concurrent' has no attribute 'futures ...
AttributeError : module 'concurrent' has no attribute 'futures' when I try parallel processing in python 3.6 ; in <module> import ; 17, in...
Read more >
AttributeError: module 'concurrent' has no attribute 'futures' #6
Hi all, I am using Python 3.7.9, I am getting above issue. Here is my code block: `import concurrent.futures import ...
Read more >
Short / Leverage
Shorting is not possible when trading with trading_mode set to spot . To short trade, trading_mode must be set to margin (currently unavailable)...
Read more >
Python AttributeError — What is it and how do you fix it?
AttributeError : '***' object has no attribute '***'What is an AttributeError in Python? What can you do to fix it? When does it...
Read more >
REPORT: A Cost Comparison of Futures & ETFs
Futures : Futures contracts are derivatives and provide leverage. Unlike an ETF, where the full notional amount is paid by the buyer 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