Coinbase: View Transactions
Closed this issue · 4 comments
I'm fairly comfortable working in VBA, but am pretty ignorant when it comes to REST/API type work. Currently trying to modify the code for Coinbase in order to view transactions for a specific wallet/asset_id and no matter what I try I end up either getting a
- 401 HTTP-Unauthorized
- 404 HTTP-Not Found
Any pointers would be much appreciated.
Can you share your code please? And what does the example in the example xlsm do, does that work?
The code in the example Coinbase sheet (ShtCoinbase) works as expected.
For my testing I have created a new Worksheet called CoinTest and have configured the following on it:
- Created a table named "Coin_Test"
- Added a named field/reference scoped to the worksheet called "apikey_coinbase" containing my API key
- Added a named field/reference scoped to the worksheet called "secretkey_coinbase" containing my secret key
I have also copied and modified the code from the original ShtCoinbase to the CoinTest and modified it as such
Sub GetTrans()
Dim JsonResponse As String
Dim Json As Object
'-> normally JSON is returned like {}, a dictionary in VBA,
'-> some functions return JSON is returned like [], a collection in VBA
'-> so to catch both, Dim Json as Object
Dim JsonRes As Dictionary
Dim apiKey As String
Dim secretKey As String
Set Sht = Worksheets("CoinTest")
Set Tb42 = Sht.ListObjects("Coin_Test")
'Put the credentials in a dictionary
apiKey = Sht.Range("apikey_coinbase").Value
secretKey = Sht.Range("secretkey_coinbase").Value
'Put the credentials in a dictionary
Dim Cred As New Dictionary
Cred.Add "apiKey", apiKey
Cred.Add "secretKey", secretKey
Dim Params As New Dictionary
Params.Add "CB-VERSION", "2005-05-05"
JsonResponse = PrivateCoinbase("accounts", "GET", Cred)
strToFile JsonResponse, "TestResponse", "json"
End Sub
The function strToFile
is just something simple I wrote that allows me to "dump" the JsonResponse to a file so I can see the output in Notepad++.
Running the above code as written results in the expected output with all of the account/wallet information in the JSON response as it does on the example ShtCoinbase.
Modifying the second to last line line in the following ways (based on the Coinbase API example) results in the following responses (Note: xxxxx-xx..... is a single hard coded asset/wallet id obtained from the output of the working accounts code)
JsonResponse = PrivateCoinbase("accounts//xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx//transactions", "GET", Cred)
- 401: HTTP-Unauthorized
JsonResponse = PrivateCoinbase("accounts/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/transactions", "GET", Cred)
- 404: HTTP-Not Found
(The above aren't the only two things I have tried, but most have been some variation of the above)
Hi there,
got around to testing it. This works for me:
Dim Params As New Dictionary
Params.Add "CB-VERSION", "2005-05-05"
JsonResponse = PrivateCoinbase("accounts/xxxxxxxxxxxxxxxxxxxxxxxxxxx/transactions", "GET", Cred, Params)
Note: you see that your credentials get added with the Cred parameter. The header CB-VERSION is passed as a Parameter.
Hope that helps. If so, please close the issue.
No response, am closing the issue. Feel free to create a new issue if things don't work.