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.03k stars 261 forks source link

AttributeError: 'NoneType' object has no attribute 'get' when deploying on Binance #179

Closed ZILECAO closed 1 year ago

ZILECAO commented 2 years ago

Description

Tried running % blankly deploy but received an AttributeError: 'NoneType' object has no attribute 'get'. Can anyone help me debug this issue? Tried trading ETH-USDT and the backtest worked fine.

settings.json

{
    "settings": {
        "use_sandbox_websockets": false,
        "websocket_buffer_size": 10000,
        "test_connectivity_on_auth": true,
        "auto_truncate": false,
        "coinbase_pro": {
            "cash": "USD"
        },
        "binance": {
            "cash": "USDT",
            "binance_tld": "us"
        },
        "binance_futures": {
            "cash": "USDT",
            "margin_type": "USDT-M"
        },
        "alpaca": {
            "websocket_stream": "iex",
            "cash": "USD",
            "enable_shorting": true,
            "use_yfinance": false
        },
        "oanda": {
            "cash": "USD"
        },
        "okx": {
            "cash": "USDT"
        },
        "keyless": {
            "cash": "USD"
        },
        "kucoin": {
            "cash": "USDT"
        },
        "ftx": {
            "cash": "USD",
            "ftx_tld": "us"
        },
        "ftx_futures": {
            "cash": "USD",
            "ftx_tld": "us"
        }
    }
}
settings.json here

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
    }
}
backtest.json here

Error (if applicable)

[ BLANKL] Uploading modelInvalid Response: <Response [500]>
✘ An error occurred. Traceback:
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/blankly/deployment/new_cli.py", line 523, in main
    args.func(args)
  File "/opt/homebrew/lib/python3.9/site-packages/blankly/deployment/new_cli.py", line 442, in blankly_deploy
    if response.get('status', None) == 'success':
AttributeError: 'NoneType' object has no attribute 'get'
Error here

Platform Info

Additional context Here is the bot.py script, I changed a few of the variable values:

import blankly
from blankly import StrategyState

def price_event(price, symbol, state: blankly.StrategyState):
    """ This function will give an updated price every 15 seconds from our definition below """
    state.variables.history.append(price)

    rsi = blankly.indicators.rsi(state.variables.history)
    current_position = state.interface.account[state.base_asset].available

    if rsi[-1] < 30 and not current_position:
        # Dollar cost average buy
        buy = blankly.trunc(state.interface.cash / price, state.variables.precision)
        state.interface.market_order(symbol, side='buy', size=buy)

    elif rsi[-1] > 70 and current_position:
        # Sell our position
        state.interface.market_order(symbol, side='sell', size=current_position)

def init(symbol, state: blankly.StrategyState):
    # Download price data to give context to the algo
    state.variables.history = state.interface.history(symbol, to=150, return_as='deque',
                                                      resolution=state.resolution)['close']

    # Get the max precision for this symbol from the API
    increment = next(product['base_increment']
                     for product in state.interface.get_products()
                     if product['symbol'] == symbol)
    state.variables.precision = blankly.utils.increment_to_precision(increment)

if __name__ == "__main__":
    # Authenticate Binance strategy
    exchange = blankly.Binance()

    # Use our strategy helper on Binance
    strategy = blankly.Strategy(exchange)

    # Run the price event function every time we check for a new price - by default that is 15 seconds
    strategy.add_price_event(price_event, symbol='ETH-USDT', resolution='30m', init=init)

    # Start our strategy, or run a backtest if this script is run locally.
    if blankly.is_deployed:
        strategy.start()
    else:
        strategy.backtest(to='7d', initial_values={'USDT': 30})
EmersonDove commented 2 years ago

Hey try it again. This was a server error that we just fixed.