25 June 2017

Scrap/Automate the Windows Terminal of Zerodha PI Scanner

Scenario:
Consider a case where you already have your Trading Strategy on Zerodha PI. This is written in TadeScript. Normally this code can be re-written in any other platform. But there is a catch - What if you are using some TradeScript specific built-in function like TREND . As per the manual, the TREND function is built-in to the core of the programming language ,  "primitives" , as they call it.

Recreating the TREND  in a programming language like Python calls for reverse engineering.  And despite my efforts, I was not able to do so accurately. My take is that identifying the trend of any financial instrument goes a long way In determining the profitability of a trader. And the Trend function in TradeScript is pretty good.  So the best way forward is to retain the strategy "as is"  in TradeScript and merely Scarp the data from the Scanner output of Zerodha. 


Approach:
I first tried to scarp the data using AutoIt . But then the reality dawned upon me that AutoIt does not support  .NET based WinForms and Windows Presentation Forms (WPF).   This can be determined with the help of the Inspect tool provided in   Windows 10SDK .  ( On Win10, the following path should help you to locate Inspect.exe: C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86 ). The  UIA Verify can also be used and is installed with the Windows Software Development Kit (SDK). It is located in the \bin\<platform>\UIAVerify folder of the SDK installation path (VisualUIAVerifyNative.exe).

Although AutoIt didn’t help, thankfully Pywinauto was up and ready with version  0.6.1 that fully supports  MSUI Automation (UIA support for WinForms, WPF, Qt, browsers, Store apps and more).

A point to note here is that once we identify the type of Controls of the Zerodha Pi Scanner Output  using Inspect / Spy ++ / UIAVerify / AutoIt Window Info , put these tools to rest. For use in the Python program,  use the name of the specific dialog by using the  Control Identifiers from   print_control_identifiers() method of Pywinauto 



Settings of the Scanner:
  • This was tested with Zerodha PI as on 25 June 2017. The latest update to Zerodha PI is 05/19/2017
  • Create a Scanner titled "MyScannerAPP"  with your settings.  You can have any TradeScript code that you so desire.

  • Next Load the Scanner.

  • View->Pop Out Active Window.  This will create an independent window with the Title "Scanner: MySignalAPP" (Warning !!! . If you first Pop Out the Active Window and then Load the Scanner, the tile of the Scanner will be different  ie; as of this version of Zerodha.)


The Python program:

The program first sets focus on the window with title "Scanner: MySignalAPP". Before retrieving the data,  it draws an outline (green coloured) on the first row of the  DataGridView. In case the selected row is not the first, it scrolls up and the first row and draws the green coloured outline before retrieving the data from the first row onward.  The output is written to a Pandas DataFrame for further processing.

Details of the Program on GitHub



1 comment:

  1. Thanks a lot for sharing this with all people you actually know what you are talking approximately!
    Bookmarked. Please also visit my website =). We will have a
    link alternate contract between us

    ReplyDelete