nznet
Active Members-
Posts
25 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
nznet's Achievements
Seeker (1/7)
0
Reputation
-
Hi, I have tried to write a script to call Binance for Account information... just trying to get the structure right before I create the other calls. My attempt is below... but I keep on getting the response code 403 which means it is on my side malformed calling or whatever... I have remove my API key and Secret for obvious security reasons...I have left other code snippets that show other attempts... Please help! #include <Crypt.au3> #include <Date.au3> #include <Array.au3> #include <string.au3> #include <MsgBoxConstants.au3> #include <Timers.au3> #include <String.au3> $timeStamp = _Timer_Init() ConsoleWrite("TimeStamp >> " & $timeStamp & @CRLF) ;$time = _TimeGetStamp() ;ConsoleWrite("time >> " & $time & @CRLF) __AccountInfo() Func __AccountInfo() ; https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md site with information on Binance API calls $accessKey = "" ;; Add the key from Binance $secretKey = "" ;; Add the key from Binance $param = 'recvWindow=20000×tamp=' & $timeStamp $BinarySignature = HMAC($secretKey, $param) ;$signature = _Base64Encode($BinarySignature) ;Encode signature $signature = _StringToHex($BinarySignature) ;ConsoleWrite(">> Signature >> " & $signature & @CRLF) $request = $param & '&signature=' & $signature ;ConsoleWrite(">> $request >> " & $request & @CRLF) $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://api.binance.com/api/v3/account", False) $oHTTP.SetRequestHeader("User-Agent", 'Mozilla/5.0 (Windows NT 10.0; WOW64) WinHttp/1.6.3.9 (WinHTTP/5.1) like Gecko') $oHTTP.SetRequestHeader("X-MBX-APIKEY", $accessKey) $oHTTP.Send($request) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 Then MsgBox(4096, "Response code", $oStatusCode) EndIf ConsoleWrite("Response Text >> " & $oReceived & @CRLF & @CRLF) EndFunc ;==>__BinanceAPI Func sha256($message) Return _Crypt_HashData($message, $CALG_SHA_256) EndFunc Func HMAC($key, $message, $hash="sha256") Local $blocksize = 64 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 Func _TimeGetStamp() Local $av_Time $av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If @error Then SetError(99) Return False EndIf Return $av_Time[0] EndFunc Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode
-
Hi Danyfirex, I tried using JSON Notation, as below: $sParameters = '{"exchange_code":"GDAX","exchange_market":"BTC/USD","type":"all"}' Still get the same error: {"err_num":"1057-14-01","err_msg":"Missing or empty parameters:"} I also tried (Reading through your post mLipok): $sParameters = '{' & @CRLF $sParameters &= 'Content-Transfer-Encoding: binary' & @CRLF $sParameters &= '"exchange_code":"GDAX"' & @CRLF $sParameters &= '"exchange_market":"BTC/USD"' & @CRLF $sParameters &= '"type":"all"' & @CRLF $sParameters &= '}' & @CRLF Any more help would be greatly appreciated.
-
Hi Guys, I have been trying to write the API calls to Coinigy.com in AutoitScipt. I have managed to solve most of them put are having trouble with the ones that require parameters to be passed. The source to the API calls can be found here: http://docs.coinigy.apiary.io/#reference/market-data/market-data/data-{type:history} Example code from this site: curl --include \ --request POST \ --header "Content-Type: application/json" \ --header "X-API-KEY: " \ --header "X-API-SECRET: " \ --data-binary " { \"exchange_code\": \"GDAX\", \"exchange_market\": \"BTC/USD\", \"type\": \"history\" }" \ ' https://api.coinigy.com/api/v1/data ' This data one is really annoying me. I have the following so far: #include <Array.au3> #include <string.au3> #include <MsgBoxConstants.au3> #Region Coinigy Const Global $sCoinigyAPIUrl = "https://api.coinigy.com/api/v1/" #EndRegion Coinigy Const #Region keys Global Const $sCoinigyAPIKey = "" ; just removed my APIKey Global Const $sCoinigyAPISecret = "" ; just removed my APISecret #EndRegion keys $sResults = CoinigyQueryPrivate("data", "exchange_code=GDAX&exchange_market=BTC/USD&type=history") ; Trade history, asks and bids for any supported exchange/market ConsoleWrite("Market Data: " & $sResults & @CRLF & @CRLF) Func CoinigyQueryPrivate($sMethod, $sParameters) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $sCoinigyAPIUrl & $sMethod, False) $oHTTP.SetRequestHeader("X-API-KEY", $sCoinigyAPIKey) $oHTTP.SetRequestHeader("X-API-SECRET", $sCoinigyAPISecret) ; $oHTTP.Send(Binary($sParameters)) ; tried this as well $oHTTP.Send($sParameters) Local $sReceived = $oHTTP.ResponseText Return $sReceived EndFunc ;==>CoinigyQueryPrivate If I do other queries that don't require Parameters they work perfectly. I am just totally stumped by the parameter passing queries. I have tried everything and I still can't get it to go. Would really appreciate some help. If you want to try for yourself live, Coinigy.com give a free 30 trial.... Please help... Thanks in advance.
-
Hi Guys, Sorry Richard... I did not respond to your posting the other week. Thanks for pitching in. And Thanks John for your Valent atempt to help. However, is there any other suggestions anyone can give. If it means I need to go back to TextGrab to have them modify a dll to suit I am prepared to do this if I know what changes need to be made. Kind Regards Stephen
-
Hi John, Tried your other two suggestions. Both return an error returns '0'. Thanks Stephen
-
Hi John, Sorry about that... should not have missed the array part. I have chnaged to the following: #include <Array.au3> Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $hWnd = WinGetHandle("Notepad") $Struct = DllStructCreate('wchar[1024]') $text = DllCall("tgsdkx.dll","int","CaptureFromHWND","hwnd",$hwnd, "ptr", $struct) If IsArray($text) Then MsgBox(0, "Text", $text[0]) Else MsgBox(0, "Error", @error) EndIf ;_ArrayDisplay($text, "Text") Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Endfunc The error message that is returned is '0'. Thanks, Stephen
-
Hi John, I have been looking at the calling directly and going through the tutorial I found on the forum a few days ago. I have tried the following: $hWnd = WinGetHandle("Notepad") MsgBox(0,"hWnd",$hWnd) $Struct = DllStructCreate('wchar[1024]') $text = DllCall("tgsdkx.dll","int","CaptureFromHWND","hwnd",$hwnd,"ptr", $struct) MsgBox(0,"Text",$Text) This time I get no errors but the result is displayed as 0. Thanks, Stephen
-
Hi John, The Visual Basic code for the calling of the DLL is: [Visual Basic] object.CaptureFromHWND( ByVal hwnd As INT_PTR, ByRef text As String ) I now get an error in the expression by placing ByRef where it is. Thanks, Stephen
-
Hi John, I have been using the following at the top of my script. Something I found yesterday reading through the forum: $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Endfunc I made the chnage to wchar as per your suggestion. I now do not get the other message but one generated from the code above that states: We intercepted a COM Error! err.windescription Uspecified error err.number is: 80020009 The error is stated to be on the following line: $Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr) Thanks, Stephen
-
Hi John, I tried: 1) $Struct = DllStructCreate('str') ; maybe wstr. $StrPtr = DllStructGetPtr($Struct) $Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr) 2) $Struct = DllStructCreate('wstr') ; maybe wstr. $StrPtr = DllStructGetPtr($Struct) $Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr) 3) $Struct = DllStructCreate('char[1024]') $StrPtr = DllStructGetPtr($Struct) $Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr) I take it that I read your suggestions correctly. And yes they all produced the same error. Thanks Stephen
-
Hi John, Thanks for your suggestions. I have tried them both and now I get the following: Exception occured during text capture. Please see the log fil. The log file is list below: <?xml version="1.0"?> -<Exception><ExceptionRecord LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xb04" FunctionName="ClearCustData" ExceptionAddress="74A195CB" ExceptionDescription="EXCEPTION_ACCESS_VIOLATION" ExceptionCode="0xc0000005" CommandLine=""C:Program Files (x86)AutoIt3AutoIt3.exe" "G:SanDiskSecureAccessNew MidasTextgrabtextgrab2.au3" " ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe"/><Processor NumberOfProcessors="8" Level="Intel Pentium Pro or Pentium II" Architecture="PROCESSOR_ARCHITECTURE_INTEL"/><OperatingSystem CSDVersion="Service Pack 1" BuildNumber="7601" MinorVersion="1" MajorVersion="6"/><Modules/>-<CallStack><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xb05" FunctionName="ClearCustData" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x74a195cb" FrameNumber="1"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xbdd6" FunctionName="VarDecNeg" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x749e239f" FrameNumber="2"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xa63" FunctionName="LoadRegTypeLib" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x749b3c91" FrameNumber="3"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:TextGRABSDKtgsdkx.dll" ReturnAddress="0x365108" FrameNumber="4"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x20b281" FrameNumber="5"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x20e373" FrameNumber="6"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1b961e" FrameNumber="7"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19af90" FrameNumber="8"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x199303" FrameNumber="9"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1996c0" FrameNumber="10"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19d87e" FrameNumber="11"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19d967" FrameNumber="12"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1a648e" FrameNumber="13"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x12" FunctionName="BaseThreadInitThunk" ModuleName="C:Windowssyswow64kernel32.dll" ReturnAddress="0x758e339a" FrameNumber="14"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x63" FunctionName="RtlInitializeExceptionChain" ModuleName="C:WindowsSysWOW64ntdll.dll" ReturnAddress="0x77289ef2" FrameNumber="15"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x36" FunctionName="RtlInitializeExceptionChain" ModuleName="C:WindowsSysWOW64ntdll.dll" ReturnAddress="0x77289ec5" FrameNumber="16"/></CallStack></Exception> Do you have any suggestions? Thanks again for taking the time to answer my post.
-
The below is the link the C and Visual basic examples: http://www.renovation-software.com/en/tgsdk-doc/capture-from-hwnd.html