Hallo zusammen,
seit gut 14 Tagen suche ich mir in allen möglichen Foren meine Information zusammen
Das Thema "Bot" ist hier nicht ganz so erwünscht. Aber das ist eine offizielle Schnittstelle von Poloniex und deshalb trage ich mein Problem hier vor.
Ich bin auch schon weit gekommen. Den Fehler der falschen Keys konnte ich bereits lösen ... Dank einem Post in einem polnischen Forum (da gehts auch um AutoIt - und nein, ich kann kein polnisch ... Dr Google sei Dank).
Seit 2 Tagen ist aber Stillstand...
Ich möchte mich bei der API von Poloniex anmelden und eine Abfrage platzieren. Anmeldung funktioniert. Ich bekomme den Fehler "{"error":"Invalid command."}"
Mein Problem:
Die Doku der API besagt, daß ich ein ""nonce" POST parameter", ein immer aufwärts zählenden Counter mit geben muß. (https://poloniex.com/support/api/)
---------
All calls to the trading API are sent via HTTP POST to https://poloniex.com/tradingApi and must contain the following headers:
- Key - Your API key.
- Sign - The query's POST data signed by your key's "secret" according to the HMAC-SHA512 method.
Additionally, all queries must include a "nonce" POST parameter. The nonce parameter is an integer which must always be greater than the previous nonce used.
------------
Ich habe nun schon viele viele Varianten getestet .... leider ohne Erfolg. Hier erst mal mein TestModul ... eine einfache Abfrage der Balance.
Die Key's sind unscharf ...teilweise ge-x-selt. Kann ich aber, wenn nötig reinstellen, da es ein Test-Acc ist. Wird später gelöscht/deaktiviert.
Spoiler anzeigen
; Danke an Pawellek aus dem Forum https://autoit.de/www.mpcforum.pl, Beitrag https://www.mpcforum.pl/topic/1598344-…rzystaniem-api/
#include <Crypt.au3>
#include <Date.au3>
Global $tZeit = TimerInit ;Startzeit
bitmarket_api()
Func bitmarket_api() ;Abfrage Balance
;https://poloniex.com/tradingApi
Local $key = "2F7CC9ZD-O0LTEC89-xxxxxxxx-9NLGYY9Q"
Local $secret = "24663e57c05c19f84d2bfc66486f3a723560df3cexxxxxxxx74281cd2b559c7cbf644e02bc894a79ee87d2a4bf743dff1c54feb5702169223003d8b2bc03c8"
$cNonce = Int(TimerDiff($tZeit)*1000)
ConsoleWrite($cNonce&@CR)
Local $tonce = _DateDiff('s', "1970/01/01 00:00:00", _DateAdd("h", -1, _NowCalc()))
Local $params = "command=returnBalances&nonce"&$cNonce
Local $sign = hmac($params, $secret)
;~ ConsoleWrite($sign&@CR)
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://poloniex.com/tradingApi", False)
$oHTTP.SetRequestHeader("Key",$key)
$oHTTP.SetRequestHeader("Sign",StringLower(Hex($sign)))
$oHTTP.Send($params)
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
ConsoleWrite($oReceived&@CR)
If $oStatusCode <> 200 Then
MsgBox(4096, "Response code", $oStatusCode)
Else
MsgBox(0, "ResponseText", $oReceived)
EndIf
EndFunc ;==>bitmarket_api
Func hmac($message, $key, $hash = "SHA512")
Local $blocksize = 128
Local $a_opad[$blocksize], $a_ipad[$blocksize]
Local Const $oconst = 0x5C, $iconst = 0x36
Local $opad = Binary(''), $ipad = Binary('')
$key = Binary($key)
If BinaryLen($key) > $blocksize Then $key = Call($hash, $key)
For $i = 1 To BinaryLen($key)
$a_ipad[$i - 1] = Number(BinaryMid($key, $i, 1))
$a_opad[$i - 1] = Number(BinaryMid($key, $i, 1))
Next
For $i = 0 To $blocksize - 1
$a_opad[$i] = BitXOR($a_opad[$i], $oconst)
$a_ipad[$i] = BitXOR($a_ipad[$i], $iconst)
Next
For $i = 0 To $blocksize - 1
$ipad &= Binary('0x' & Hex($a_ipad[$i], 2))
$opad &= Binary('0x' & Hex($a_opad[$i], 2))
Next
Return Call($hash, $opad & Call($hash, $ipad & Binary($message)))
EndFunc ;==>hmac
Func SHA512($message)
Return _Crypt_HashData($message, 0x0000800e)
EndFunc ;==>SHA512
Nicht sehr sauber zusammengestellt, es geht mir auch nur drum zu begreifen, wie das funktioniert.
Ich hab noch nie mit "Objecten" gearbeitet. Da tu ich mich noch schwer ... aber es wird.
Könnt ihr mir bitte erlären an welcher Stelle im "Post"-Befehl die "nonce"-Information eingebaut werden muß?
Vorab vielen Dank