blankly-finance / blankly

🚀 💸 Easily build, backtest and deploy your algo in just a few lines of code. Trade stocks, cryptos, and forex across exchanges w/ one package.
https://package.blankly.finance
GNU Lesser General Public License v3.0
2.14k stars 269 forks source link

Binance futures backtest error #198

Closed ndthanh2605 closed 2 years ago

ndthanh2605 commented 2 years ago

Description

When I test Binance futures strategy using your examples (https://github.com/blankly-finance/blankly/tree/main/examples), all 3 examples yeild error and cannot run.

settings.json

{
    "settings": {
        "use_sandbox_websockets": true,
        "websocket_buffer_size": 10000,
        "test_connectivity_on_auth": true,
        "auto_truncate": false,
        "global_shorting": false,
        "coinbase_pro": {
            "cash": "USD"
        },
        "binance": {
            "cash": "USDT",
            "binance_tld": "com"
        },
        "binance_futures": {
            "cash": "USDT",
            "margin_type": "USDT-M"
        },
        ...
    }
}

backtest.json (if applicable)

{
    "price_data": {
        "assets": []
    },
    "settings": {
        "use_price": "close",
        "smooth_prices": false,
        "GUI_output": true,
        "show_tickers_with_zero_delta": false,
        "save_initial_account_value": true,
        "show_progress_during_backtest": true,
        "cache_location": "./price_caches",
        "continuous_caching": true,
        "resample_account_value_for_metrics": "1d",
        "quote_account_value_in": "USDT",
        "ignore_user_exceptions": true,
        "risk_free_return_rate": 0.0,
        "benchmark_symbol": null
    }
}

Error (if applicable)

Traceback (most recent call last):
  File "c:/Users/Saban4.0/Documents/blankly/futures_bot.py", line 66, in <module>
    results = strategy.backtest(to='1w', initial_values={'USDT': 10000})
  File "C:\Users\Saban4.0\AppData\Local\Programs\Python\Python38\lib\site-packages\blankly\frameworks\strategy\strategy.py", line 320, in backtest
    res = self.model.backtest(args={}, initial_values=initial_values, settings_path=settings_path, kwargs=kwargs)
  File "C:\Users\Saban4.0\AppData\Local\Programs\Python\Python38\lib\site-packages\blankly\frameworks\model\model.py", line 61, in backtest
    backtest = self.__backtester.run(args,
  File "C:\Users\Saban4.0\AppData\Local\Programs\Python\Python38\lib\site-packages\blankly\exchanges\interfaces\paper_trade\backtest_controller.py", line 812, in run
    self.add_custom_events(FundingRateEventReader(symbol, self.user_start, self.user_stop, self.interface))
  File "C:\Users\Saban4.0\AppData\Local\Programs\Python\Python38\lib\site-packages\blankly\data\data_reader.py", line 236, in __init__
    super().__init__('__blankly__funding_rate', history)
  File "C:\Users\Saban4.0\AppData\Local\Programs\Python\Python38\lib\site-packages\blankly\data\data_reader.py", line 211, in __init__
    time, data = zip(*events.items())
ValueError: not enough values to unpack (expected 2, got 0)

Platform Info

EmersonDove commented 2 years ago

@qmatias

EmersonDove commented 2 years ago

Can you try updating your blankly pip install blankly --upgrade. @qmatias reminded me that this is because of a bug that was resolved in v1.18.12

ndthanh2605 commented 2 years ago

thanks so much, the bug is resolved

ndthanh2605 commented 2 years ago

Can you try updating your blankly pip install blankly --upgrade. @qmatias reminded me that this is because of a bug that was resolved in v1.18.12

Could I ask you another question? I checked the price event for futures market data but I found it was wrong, it's the price of spot market. How can I fix it?

Thank you.

EmersonDove commented 2 years ago

Are you sure its the same as spot? In our futures exchanges we are using the mark price directly from the exchange.

ndthanh2605 commented 2 years ago

Yes, I use the FuturesStrategyState to get & print the last price in history here: time 1662739200 ( 2022-09-09 23:00:00 ) price: O 21266.76 H 21403.05 L 21143.53 C 21295.52 You can check the price in binance website ( binance_futures and binace_spot ) bn_spot bn_futu