Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONDecodeError: Expecting value #103

Closed
alitekdemir opened this issue Jan 18, 2022 · 2 comments
Closed

JSONDecodeError: Expecting value #103

alitekdemir opened this issue Jan 18, 2022 · 2 comments

Comments

@alitekdemir
Copy link

Description

I'm trying the RSI code in colab and desktop pc, but I'm getting this error.

#RSI KODLARI
import blankly


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) # appends to the deque of historical prices
    rsi = blankly.indicators.rsi(state.variables['history'])
    if rsi[-1] < 30 and not state.variables['owns_position']:
        buy = int(state.interface.cash / price)
        state.interface.market_order(symbol, side='buy', size=buy)
        state.variables['owns_position'] = True
    elif rsi[-1] > 70 and state.variables['owns_position']:
        curr_value = int(state.interface.account[state.base_asset].available)
        state.interface.market_order(symbol, side='sell', size=curr_value)
        state.variables['owns_position'] = False

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')['close']
    state.variables['owns_position'] = False

if __name__ == "__main__":
    exchange = blankly.Binance(portfolio_name="ATD Binance")
    strategy = blankly.Strategy(exchange)
    strategy.add_price_event(price_event, symbol='ETH-BUSD', resolution='15m', init=init)

    # Start the strategy. This will begin each of the price event ticks
    # strategy.start()
    # Or backtest using this
    results = strategy.backtest(to='1y', initial_values={'BUSD': 1000})
    print(results)

Error (if applicable)

JSONDecodeError: Expecting value: line 10 column 5 (char 364)

blankly-rsi

@EmersonDove
Copy link
Member

If I were to guess I think your backtest.json file has invalid syntax.

Try copying and pasting the backtest.json into here: https://jsonformatter.org/json-parser

@alitekdemir
Copy link
Author

yes you are right.

    "assets": [
      [ "BTC-USDT", 1483218000, 1642335680, 300.0 ],
      [ "BTC-USDT", 1483218000, 1642335680, 900.0 ],
      [ "BTC-USDT", 1483218000, 1642335680, 1800.0 ],
      [ "BTC-USDT", 1483218000, 1642335680, 3600.0 ],
      [ "BTC-USDT", 1483218000, 1642335680, 14400.0 ],
      [ "BTC-USDT", 1483218000, 1642335680, 86400.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 300.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 900.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 1800.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 3600.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 14400.0 ],
      [ "ETH-USDT", 1483218000, 1642335680, 86400.0 ], < this is my fault, i added this last comma with copy paste
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants