Jump to content

Recommended Posts

Hi everyone!

I'm using AutoIt for several years now and I really get the hang of it!
I'm quite the curious OCD perfectionist kind of guy, so I can't help wondering..
what would be the best way to program stuff for the compiler / interpreter / scripting engine?

We're talking about the inner workings of the AutoIt's core here, and how to give it as less friction as possible but also take care of the machine running the script.
For example,

Imagine a script where we would constantly have to assign a Boolean value to a variable:

; A:

local $bool = false

$bool = true
$bool = true
$bool = false

; B:

local $bool = false

check(true)
check(true)
check(false)

func check($b)
    if $bool = $b then return
    $bool = $b
endfunc

In this case, would it be better to just overwrite (A) the variable or first check if we really need to (B)?
What would be best for the computers memory if it had to do this for a year non stop?

Another example, imagine you're writing a function with an if statement.
If you would look under the hood of AutoIt, what would be the best way to give your computer as less work / code nesting stack filling as possible:

; A:

func decide($b_Input)
    if $b_Input then
        ;do something
    else
        ;do something else
    endif
endfunc

; B:

func decide($b_Input)
    if $b_Input then
        ;do something
        return
    endif
    ;do something else
endfunc

Last one for now:

; A:

while 1
    ; do stuff
wend

; B:

while true
    ; do stuff
wend

Isn't AutoIt taking an extra step in converting 1 to a Boolean in example (A)?
Or is it the other way around and does the (B) way make AutoIt first convert a keyword (true or false) to a numerical value (0 or 1).

I think this kinda detail stuff is quite interesting, makes me wonder how AutoIt converts and runs our code.

What are your opinions on this topic?
Any coders who know more about the inner workings of AutoIt?
Any people like me who ask themselves similar questions (with examples)?

Let me know! 😉

Link to post
Share on other sites

Example 1: better to just overwrite (A) the variable (same memory location, so the number of (re)writes doesn't matter). But every extra function call costs performance.

Example 2: Fastest evaluation uses Switch, not If/Then/Else, e.g.,

Switch $b_Input
    Case True
        ; do something
    Case Else
        ; do something else
EndSwitch

Example 3: AFAIK, boolean "True" is converted to 1, so "While 1" is marginally faster than "While True".

Edited by RTFC
clarification
Link to post
Share on other sites

Another interesting one would be, do we include every constant needed manually instead of just using them all with #include ?
Or does AutoIt delete non used variables and functions while compiling to an exe file?

I have a hundred of these questions actually, not sure where to put them at this point 😅

Link to post
Share on other sites
  • Moderators

TheAutomator,

Quote

does AutoIt delete non used variables and functions while compiling to an exe file?

No, but using the Au3Stripper utility (which is in the full SciTE4AutoIt3 package) does exactly that if you give it the correct parameters.

Quote

I have a hundred of these questions actually, not sure where to put them at this point

Keep asking them in this thread.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
14 hours ago, TheAutomator said:

how do you know AutoIt works that way

Because under the hood, AutoIt is coded in C++ (link).

M23 beat me to the punch on Au3Stripper. Quoting Jos: "Au3Stripper can produce a single sourcefile that is similar to what is stored in the compiled script file. "

EDIT: this is also why script line numbers usually don't match up with the exe's reported error line numbers.

 

Edited by RTFC
Link to post
Share on other sites

Thanks RTFC, Melba23!

So AutoIt is closed source since autoit-v3.1.0, to bad I can't literally look at the source for that matter..

Okay! i'll keep the questions rolling 😀
What about this one:

;A:

while 1
    for $item = 0 to ubound($array) - 1
         ;do stuff
    next
wend

;B:

$ubound = ubound($array) - 1

while 1
    for $item = 0 to $ubound
         ;do stuff
    next
wend

do we each time calculate ubound() - 1 and save memory or take up more space like in example (B) but spare our computer on doing those ubound() call and -1 calculations?

Link to post
Share on other sites

Another one:

Does it matter if we have one big loop full of switches with code that decide what happens (A)?

Or do we make a switch that calls functions doing that stuff (B)?
(imagine huge blocks of code)

Example A

while 1
    switch guigetmsg()
        case $gui_event_close
            exit
        case $a
            guictrlsetstate($x, $gui_disable)
            local $y = guictrlread($z)
            guictrlsetdata($user, '')
            ...
        case $b
            guictrlsetstate($x, $gui_enable)
            local $y = guictrlread($z)
            ...
        case $c
            guictrlsetdata($aze, '123456789')
            ...
            ...
            ...
            ...
    endswitch
wend

Example B

while 1
    switch guigetmsg()
        case $a
            do_stuff_for_A()
        case $a
            do_stuff_for_B()
        case $a
            do_stuff_for_C()
        ...
        ...
        ...
    endswitch
wend

 

Edited by TheAutomator
Link to post
Share on other sites

You could use functions TimerInit and TimerDiff to check which one is faster:

;A:
Global $hTimer
$hTimer = TimerInit()
while 1
    for $item = 0 to ubound($array) - 1
         ;do stuff
    next
wend
ConsoleWrite("A: " & TimerDiff($hTimer) & @CRLF)

;B:
$hTimer = TimerInit()
$ubound = ubound($array) - 1
while 1
    for $item = 0 to $ubound
         ;do stuff
    next
wend
ConsoleWrite("B: " & TimerDiff($hTimer) & @CRLF)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

BTW: Your While loop needs to check for an exit condition, else it will run forever ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Water,

30 minutes ago, water said:

You could use functions TimerInit and TimerDiff to check which one is faster:

not looking for the fastest way here, but for the way that gives the computer as less work as possible.
e.g. checking and evaluating / allocating and overwriting memory (low level behind the scenes stuff).

Imagine you would be a computer and had to do all that stuff manually yourself, what would give you the most work / wear? Do you know what i mean? 😉
 

28 minutes ago, water said:

BTW: Your While loop needs to check for an exit condition, else it will run forever ;)

I know i know, it's just to give you an example.. The ;do stuff part would be replaced with that kinda stuff if it wasn't an example 🙂

Edited by TheAutomator
Link to post
Share on other sites
16 minutes ago, TheAutomator said:

but for the way that gives the computer as less work as possible.

More work to do means more CPU cycles means longer run time. So i think measuring the time it takes to do the work is a good indicator for efficiency.

 

18 minutes ago, TheAutomator said:

just to give you an example

It is good practice on this forum to post runable examples so people don't have to spend much time to play with your code :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Water,

About the TimerDiff example , wasn't sure if it gave reliable results for all types of actions like declaring variables etc..

And sure, but I just don't want to write miles of code to give an obvious little example or have to think out and write a bunch of code making the example more unreadable.
I get what you mean tho, so for more advanced stuff i will write working code examples 🙂

Edited by TheAutomator
Link to post
Share on other sites

For this one i'm not sure if there are any better solutions:

You have a huge array, filled with lots of data and you need to delete one of the items in the middle.
The array fills up almost all of your computer memory, what would be the best way to resize it?

Should I search the index number of the item to delete and then in a loop copy the next item over the current one and redim to cut the last one of?
You always copy one of the elements that way doubling it's memory usage temporary..

Is this the only way?

Edited by TheAutomator
Link to post
Share on other sites

In this case I suggest to use a database. Because sooner or later you will hit one of the AutoIt limits with such a huge array.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

BTW AutoIt arrays are limited to only 16 millions cells, while databases are essentially unbounded in size (I've [remotely] approached an SQLite DB totalling 120Tb) and they offer unrivaled possibilities for searching, sorting, massaging data in any volume and complexity.

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 post
Share on other sites
17 hours ago, TheAutomator said:

do we each time calculate ubound() - 1 and save memory or take up more space like in example (B) but spare our computer on doing those ubound() call and -1 calculations

This is bascially the same question as you posed before, with the same answer: every function call requires a stack frame push, a jump to the function code, function execution (possibly with local var read/writes), storage of result(s) (either on the stack or in a global var), and return from the call with stack pop. So whenever a function in a loop would always provide the same return, you should move it out of the loop, as just reading a value from memory is much, much faster.

RE. the huge-array question, I wouldn't resize each time you delete one entry, just reserve some special value/content to mark a cell as deleted, and clean-up periodicially or after some threshold is reached. Also, you don't have to store content contiguously. But if you're really into large-scale, low-level memory management, then AutoIt wouldn't necessarily be the most appropriate work environment. If you're interested, you can have a look at how my HighMem environment (in AutoIt) manages large memory allocations.

And for high performance, using ReDim repeatedly is a terrible idea.

Edited by RTFC
Link to post
Share on other sites
2 hours ago, TheAutomator said:

It seems like $boolValue = False would also be better then NOT($boolValue) i guess.

I' am not sure if this is a robust test ?

Global $hTimer, $bBoolean, $iMax = 5000000

$hTimer = TimerInit()
For $i = 1 To $iMax
    $bBoolean = False
Next
ConsoleWrite("1. Time = " & TimerDiff($hTimer) & @CRLF)

$hTimer = TimerInit()
For $i = 1 To $iMax
    $bBoolean = Not(True)
Next
ConsoleWrite("2. Time = " & TimerDiff($hTimer) & @CRLF)

Variation 2 takes twice as long.

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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DJ143
      I have a autoit exe file which is used in upload/browse file functionality.  This has been integrated with selenium framework and I am invoking the autoit exe using Java process and runtime. 
      Now the issue is when I run the scripts and invoke the autoit exe in local it works perfectly.  But when I use selenium grid or jenkins to run the scripts in another windows server it is not working.
      Can anyone please suggest any solution for this?
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
×
×
  • Create New...