Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with Bitfinex connection #11

Closed
balin77 opened this issue Jan 11, 2018 · 4 comments
Closed

Problems with Bitfinex connection #11

balin77 opened this issue Jan 11, 2018 · 4 comments

Comments

@balin77
Copy link

balin77 commented Jan 11, 2018

Hey krijnsent,

as I use Bitfinex as exchange amongst others, I have tried to make the connection myself, using your code as example. The Public query works fine, but the Private query doesnt even receive an answer. I suppose its because of the very strange hash of the payload. I followed these two examples to write the vba code:

python code: https://gist.github.com/jordanbaucke/5812039
vb.net code: http://www.vbforums.com/showthread.php?777193-Need-some-help-getting-my-code-to-work-with-the-Bitfinex-API

I tried to implement the vb.net code, but its functions is just too different as that i could adapt it.

my code looks like this (maybe you can see my mistake):

`Sub TestBitfinex()

Dim apikey As String
Dim secretkey As String
Dim Coins As Worksheet
Set Coins = Worksheets("Coins")

apikey = Coins.Range("apikey_bitfinex")
secretkey = Coins.Range("secretkey_bitfinex")

Debug.Print PublicBitfinex("symbols", "")
'["btcusd","ltcusd","ltcbtc","ethusd","ethbtc","etcbtc","etcusd","rrtusd"...
Debug.Print PublicBitfinex("pubticker", "ltcbtc")
'{"mid":"0.0171145","bid":"0.017113","ask":"0.017116","last_price":"0.017105","low":"0.01666","high":"0.01721","volume":"85227.17880718","timestamp":"1515663208.679153"}
Exit Sub

'Unix time period:
t1 = DateToUnixTime("1/1/2014")
t2 = DateToUnixTime("1/1/2018")

'To pass method options: (I couldnt test this yet, because it doesnt work without method options either)

'Dim Dictionary As New Scripting.Dictionary
'Set Dictionary = New Dictionary
'Dim Options As New Collection

'Dictionary(MethodOption1) = "XYZ"
'Dictionary(MethodOption2) = "XYZ"
'Options.Add Dictionary

Debug.Print PrivateBitfinex("account_infos", apikey, secretkey)

End Sub

Function PublicBitfinex(Method As String, Optional MethodOptions As String) As String

'This works
'https://api.bitfinex.com
Dim Url As String
ApiSite = "https://api.bitfinex.com"
urlPath = "/v1/" & "/" & Method & "/" & MethodOptions
Url = ApiSite & urlPath
Debug.Print Url

PublicBitfinex = GetDataFromURL(Url, "GET")

End Function
Function PrivateBitfinex(Method As String, apikey As String, secretkey As String, Optional MethodOptions As Collection)
Dim NonceUnique As String
NonceUnique = DateDiff("s", "1/1/1970", Now)

'see the general Bitfinex documentation here: https://bitfinex.readme.io/v1/docs/rest-general

Dim PayloadDict As Scripting.Dictionary
Set PayloadDict = New Dictionary

'the payload has to look like this: payload = parameters-object -> JSON encode -> base64
'see the authenticated endpoints documentation here: https://bitfinex.readme.io/v1/docs/rest-auth
PayloadDict("request") = "/api/v1/" & Method
PayloadDict("nonce") = NonceUnique
If Not MethodOptions Is Nothing Then
Set PayloadDict("options") = MethodOptions
End If

Dim Json As String
Json = ConvertToJson(PayloadDict)
payload = Base64Encode(Json)
'Debug.Print Json
'Debug.Print Payload

'signature = HMAC-SHA384(payload, api-secret).digest('hex')
ApiSite = "https://api.bitfinex.com"
Signature = ComputeHash_C("SHA384", payload, secretkey, "STRHEX")
Debug.Print Signature
Debug.Print apikey

Url = ApiSite & "/" & Method
HTTPMethod = "POST"

' Instantiate a WinHttpRequest object and open it
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open HTTPMethod, Url, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "X-BFX-APIKEY", apikey
objHTTP.setRequestHeader "X-BFX-PAYLOAD", payload
objHTTP.setRequestHeader "X-BFX-SIGNATURE", Signature
objHTTP.Send get_url

objHTTP.WaitForResponse
PrivateBitfinex = objHTTP.ResponseText
Set objHTTP = Nothing

Debug.Print PrivateBitfinex

End Function`

@krijnsent
Copy link
Owner

Thanks for your feedback. It's currently not possible to make a Bitfinex account, but I did change your code a bit so I get the same results as the PHP api connector. There are only some minor changes, but hopefully this works. If it does work, please close this issue :)

@balin77
Copy link
Author

balin77 commented Jan 12, 2018

Hey man! Thanks a lot. It works.

I was two days trying to get it working and even tried to learn python to find the mistake. For sure, I m gonna spend you some coffee.

If youd like, I will send you my Excel Workbook as soon as everything is done. Maybe you can use it as an example to connect all your working Exchanges to a coin database.

@balin77 balin77 closed this as completed Jan 12, 2018
@rexii2300
Copy link

@balin77 love to see your Excel workbook soon. No point spending hours myself when you are already into getting this to work :)

@krijnsent
Copy link
Owner

Hi @balin77 , glad it works, am curious to see what you've made!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants