krijnsent / crypto_vba

An Excel/VBA project to communicate with various cryptocurrency exchanges APIs
MIT License
155 stars 54 forks source link

Coinbase: View Transactions #72

Closed ForrestHerman closed 3 years ago

ForrestHerman commented 3 years ago

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

Any pointers would be much appreciated.

krijnsent commented 3 years ago

Can you share your code please? And what does the example in the example xlsm do, does that work?

ForrestHerman commented 3 years ago

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:

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)

(The above aren't the only two things I have tried, but most have been some variation of the above)

krijnsent commented 3 years ago

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.

krijnsent commented 3 years ago

No response, am closing the issue. Feel free to create a new issue if things don't work.