Python Forum
I keep getting the same error over and over again.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I keep getting the same error over and over again.
#1
Hello. I am trying to write a trading algorithm for kraken's crypto exchange. I keep getting an error where it says "result"; here is an example:

I am trying to get the daily close price from kraken but I keep getting an error. Here is the code:

import krakenex
import pandas as pd

# create a Kraken API client
api = krakenex.API()

# set the currency pair and interval
pair = 'XBT/USD'
interval = 1440  # 1440 minutes = 1 day

# make the API request for OHLC data
ohlc_data = api.query_public('OHLC', {'pair': pair, 'interval': interval})

# convert the OHLC data into a pandas dataframe
df = pd.DataFrame(ohlc_data['result'][pair], columns=['time', 'open', 'high', 'low', 'close', 'vwap', 'volume', 'count'])
df['time'] = pd.to_datetime(df['time'], unit='s')
df.set_index('time', inplace=True)

# get the daily close price
daily_close = df['close'].resample('D').last()

# print the most recent daily close price
print(daily_close.iloc[-1])
In the terminal, I am getting this error:


The error I am getting is: line 15, in <module>
    df = pd.DataFrame(ohlc_data['result'][pair], columns=['time', 'open', 'high', 'low', 'close', 'vwap', 'volume', 'count'])
KeyError: 'result'.
I've had this error from several bits of code I have wrote. All with the word result. I am new to programming and I'm using chatgpt to help me. Could anyone give me some feedback please?
Reply


Messages In This Thread
I keep getting the same error over and over again. - by SuchUmami - Apr-19-2023, 12:00 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020