Jump to content

api json by https how to do ?


faustf
 Share

Recommended Posts

hi guys  i want interact with my binance account for control if my trade go good or not and  close it if not , i try to  create something like this but not understund  if  work good  because i am not  good for use http request

anyone can help me???

thankz

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#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)

__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 = IniRead (@ScriptDir & "\BinCode.ini","CODE","acceskey","")
    $secretKey = IniRead (@ScriptDir & "\BinCode.ini","CODE","secretkey","")

    $param = 'recvWindow=20000&timestamp=' & $timeStamp
   ; $BinarySignature = HMAC($secretKey, $param)
    $BinarySignature = _Crypt_HashData($secretKey&$param,$CALG_SHA_256)

    ;$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




#cs
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
#ce

 

Link to comment
Share on other sites

  • 2 weeks later...

What exactly is the problem you are facing?

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

  • Developers

So, what do you think a 403 response means with websites? 

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

403DeColumbo.jpg.583781c24d6e83ad67f8d76cb58c95e0.jpg

403: a good starting point for an investigation!

Spoiler

Hint: his car is a Peugeot 403

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 hour ago, faustf said:

return 403  response 

To answer this question, you don't have to annoy Detective Columbo :lol:. It is sufficient to simply enter Http error 403 at Google.

https://en.wikipedia.org/wiki/HTTP_403

https://www.howtogeek.com/357785/what-is-a-403-forbidden-error-and-how-can-i-fix-it/

@faustf : I am slightly surprised that a member with 1000+ posts asks such a question (not meant to be insulting).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Developers
1 hour ago, Musashi said:

@faustf : I am slightly surprised that a member with 1000+ posts asks such a question (not meant to be insulting).

Stop being surprised and yes this is meant as it sounds as this has been told to the OP a zillion times.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hello. Main Issue I see in your code is you send data in the get query, the correct way is  that the parameters and signature need to be part of the URI.

 

Saludos

Link to comment
Share on other sites

On 9/18/2019 at 8:07 AM, faustf said:

i try to  create something like this but not understund  if  work good  because i am not  good for use http request

Really?!?  :naughty:  Then where is the code that you created?  Because the code that you posted looks exactly like the code in the post below (which of course doesn't work).  As Danyfirex said, if the API call is a GET, then the URI should include the params, not sent as request data (which would be a POST).

 

 

Edited by TheXman
Link to comment
Share on other sites

thankz  at all for  help  i just start to understund somthing about http

func _de()
; https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md     site with information on Binance API calls

    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", "https://api.binance.com/api/v1/exchangeInfo", False)
    $oHTTP.SetRequestHeader("User-Agent", 'Mozilla/5.0 (Windows NT 10.0; WOW64) WinHttp/1.6.3.9 (WinHTTP/5.1) like Gecko')
    $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

dont worry  @TheXman  I don't want to take merit for the scripts of others, i create a script is only way of saying........ I thought you understood

but,  Welcome..  I appreciate your clarification :D, and  your suggest

 

Edited by faustf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...