I'm trying to write a request for an api to pull a csv for trade histories. I'm having an issue when it gets to the actual request and I'm not sure whether its a client issue, something to do with the libraries, or the way I'm making the request itself. The API is hosted on dYdX's servers and there are a few dependencies -I've follow most of the docs (https://docs.dydx.exchange/).
Here are the imports:
from dydx3 import Client
from dydx3 import constants
from dydx3 import epoch_seconds_to_iso
from os import path
import ciso8601
import datetime
import pprint
import subprocess
import sys
import time
import json
and here is the client initialization and request:
client2 = Client(
host = _api_host,
network_id = _network_id,
api_key_credentials = {
'key': _api_key,
'secret': _api_secret,
'passphrase': _api_passphrase
}
)
get_account_result2 = client2.private.get_account(
ethereum_address = _eth_address
)
account2 = get_account_result2['account']
It keeps crashing on the line with account2 = get_account_result2['account'], TypeError: 'Response' object is not subscriptable. I've run it through Windows and Linux (Ubuntu) Python 3. I feel like it's a syntax thing with the json? Is there something I'm missing?
You are trying to access the ‘account’ value of that Response object as if it’s a dictionary object (subscriptable) but it is not. The good news is it likely has a method to show you the response in json, text or dictionary from.
To see which methods or attributes the Response object has try:
dir(get_account_result2)
If there is a "json" method in that list, you might want to try:
get_account_result2.json()[‘account’]
If there is an "account" attribute (not callable) or method (callable) respectively, you could also try:
get_account_result2.account or get_account_result2.account()
I dont have a dydx account so I cannot verify if any of this works.