mnin / coinbase-moneymoney

Fetches balances from Coinbase API and returns them as securities
MIT License
24 stars 4 forks source link

Compare account names instead of currency codes #5

Closed yoyostile closed 3 years ago

yoyostile commented 3 years ago

Hello,

as of late the coinbase extension does not fetch my BTC values anymore. The ContainsAccount method does return true in my case: my primary account has BTC as currency code, but there's also an account called BTC Vault in my full account list. Thus, Moneymoney does not show the current amount of my primary account.

I think this what introduced some commits ago. In order to distinguish between accounts with same currency code, I added the account name.

grafik

I think this only affects users with an activated "Vault" account.

Regards, Johannes

mnin commented 3 years ago

Hey @yoyostile, thanks for your PR, can you share the API responses (anonymised please)?

yoyostile commented 3 years ago

GET https://api.coinbase.com/v2/accounts/primary

{
    "data":
    {
        "id": "some-uuid",
        "name": "BTC Wallet",
        "primary": true,
        "type": "wallet",
        "currency":
        {
            "code": "BTC",
            "name": "Bitcoin",
            "color": "#F7931A",
            "sort_index": 100,
            "exponent": 8,
            "type": "crypto",
            "address_regex": "^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^(bc1([qpzry9x8gf2tvdw0s3jn54khce6mua7l]{39}|[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{59}))$",
            "asset_id": "some-uuid",
            "slug": "bitcoin"
        },
        "balance":
        {
            "amount": "0.123456789",
            "currency": "BTC"
        },
        "created_at": "2010-09-05T10:15:59Z",
        "updated_at": "2021-03-02T15:02:52Z",
        "resource": "account",
        "resource_path": "/v2/accounts/some-uuid",
        "allow_deposits": true,
        "allow_withdrawals": true,
        "native_balance":
        {
            "amount": "12345.67",
            "currency": "EUR"
        }
    }
}

GET https://api.coinbase.com/v2/accounts

{
    "pagination":
    {
        "ending_before": null,
        "starting_after": null,
        "previous_ending_before": null,
        "next_starting_after": "some-uuid",
        "limit": 25,
        "order": "desc",
        "previous_uri": null,
        "next_uri": "/v2/accounts?starting_after=some-uuid"
    },
    "data":
    [
        {
            "id": "some-uuid",
            "name": "NMR Wallet",
            "primary": false,
            "type": "wallet",
            "currency":
            {
                "code": "NMR",
                "name": "Numeraire",
                "color": "#231F20",
                "sort_index": 141,
                "exponent": 8,
                "type": "crypto",
                "address_regex": "^(?:0x)?[0-9a-fA-F]{40}$",
                "asset_id": "some-uuid",
                "slug": "numeraire"
            },
            "balance":
            {
                "amount": "0.00000000",
                "currency": "NMR"
            },
            "created_at": "2021-02-27T09:45:57Z",
            "updated_at": "2021-03-02T15:02:51Z",
            "resource": "account",
            "resource_path": "/v2/accounts/some-uuid",
            "allow_deposits": true,
            "allow_withdrawals": true,
            "native_balance":
            {
                "amount": "0.00",
                "currency": "EUR"
            }
        },
        {...},
        {
            "id": "some-uuid",
            "name": "BTC Vault",
            "primary": false,
            "type": "vault",
            "currency":
            {
                "code": "BTC",
                "name": "Bitcoin",
                "color": "#F7931A",
                "sort_index": 100,
                "exponent": 8,
                "type": "crypto",
                "address_regex": "^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^(bc1([qpzry9x8gf2tvdw0s3jn54khce6mua7l]{39}|[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{59}))$",
                "asset_id": "some-uuid",
                "slug": "bitcoin"
            },
            "balance":
            {
                "amount": "0.00000000",
                "currency": "BTC"
            },
            "created_at": "2010-09-05T10:15:59Z",
            "updated_at": "2017-05-07T12:34:41Z",
            "resource": "account",
            "resource_path": "/v2/accounts/some-uuid",
            "allow_deposits": true,
            "allow_withdrawals": true,
            "native_balance":
            {
                "amount": "0.00",
                "currency": "EUR"
            }
        },
        {
            "id": "some-uuid",
            "name": "ETH Wallet",
            "primary": false,
            "type": "wallet",
            "currency":
            {
                "code": "ETH",
                "name": "Ethereum",
                "color": "#627EEA",
                "sort_index": 102,
                "exponent": 8,
                "type": "crypto",
                "address_regex": "^(?:0x)?[0-9a-fA-F]{40}$",
                "asset_id": "some-uuid",
                "slug": "ethereum"
            },
            "balance":
            {
                "amount": "0.00000000",
                "currency": "ETH"
            },
            "created_at": "2010-09-05T10:15:59Z",
            "updated_at": "2018-03-27T13:06:29Z",
            "resource": "account",
            "resource_path": "/v2/accounts/some-uuid",
            "allow_deposits": true,
            "allow_withdrawals": true,
            "native_balance":
            {
                "amount": "0.00",
                "currency": "EUR"
            }
        }
    ]
}

This is of course a shortened response. "BTC Wallet" is not part of the /accounts response, "BTC Vault" is. Because of the fact that both accounts share the same currency code ContainsAccount is truthy. I guess you can replicate the behavior by creating a "vault" for you currency of choice: https://help.coinbase.com/en/coinbase/getting-started/other/vaults-faq