solo icon indicating copy to clipboard operation
solo copied to clipboard

api.getAccountBalances AccountNotFoundError (400)

Open aaronmboyd opened this issue 4 years ago • 7 comments

Solo api.getAccountBalances facade to the API does not work, always returns 400.

Using the example account from the documentation, the following works and returns an empty account:

curl https://api.dydx.exchange/v1/accounts/0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5
{
    "owner": "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
    "accountUuids": [],
    "accounts": []
}

Using solo, for example:

const account : ApiAccount = await solo.api.getAccountBalances(
    {accountOwner:"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5", accountNumber: "0"});

Always fails with

{"response":{"data":{"errors":[{"name":"AccountNotFoundError"}]},"status":400,"statusText":"Bad Request"}}

I have tried using accountNumber: new BigNumber("0") which also fails, have also tried using my own account which does have some balances, and also returns a full JSON response simply hitting the API directly.

aaronmboyd avatar Jan 16 '21 18:01 aaronmboyd

Further inspection of the code shows the axios call as: ${this.endpoint}/v1/accounts/${accountOwner}?number=${numberStr}

Trying this directly with Postman and adding in the number query parameter replicates the error.

What is this number meant to be? It defaults to zero if not provided, but even zero just returns a "AccountNotFoundError" / 400.

aaronmboyd avatar Jan 16 '21 18:01 aaronmboyd

Hello, I also encountered the same problem, have you solved it? How was it resolved?

wzzYtu avatar Mar 16 '21 08:03 wzzYtu

@wzzYtu I got around it by not using the solo SDK and calling the API directly: /v1/accounts/<address> and then retrieving balances from the balances object.

aaronmboyd avatar Mar 16 '21 15:03 aaronmboyd

Is it convenient to show the relevant code?

wzzYtu avatar Mar 17 '21 10:03 wzzYtu

This method is available on the mainnet. How should I obtain the mainnet of the fork?

wzzYtu avatar Mar 18 '21 09:03 wzzYtu

Is it convenient to show the relevant code?

Here's the approximate code I used to get the account without going through the solo SDK:

    const TIMEOUT = 10000;
    const HEADERS = {
      "Content-Type": "application/json;charset=utf-8",
      Accept: "*/*",
    };
    const HOST = "https://api.dydx.exchange";

    const instance = axios.create({
      baseURL: HOST,
      timeout: TIMEOUT,
      headers: HEADERS,
    });

    const response = await instance.get(
      HOST + "/v1/accounts/" + wallet.address
    );
    const account = response.data;
    return account;

aaronmboyd avatar Mar 18 '21 16:03 aaronmboyd

ok, thanks

wzzYtu avatar Mar 19 '21 08:03 wzzYtu