Showing posts with label Automation. Show all posts
Showing posts with label Automation. Show all posts

20 November 2022

Schedule Python Scripts with Windows Task Scheduler

Step 1

First let us identify the where python.exe is situated. Open the command prompt and type in "where python". 


16 November 2022

Webscraping of JavaScript Pages using a combination of Selenium & Beautiful Soup

Why Selenium?

Beautiful Soup makes web scraping easy by traversing the DOM (Document Object Model). But it handles only Static Scraping and is not capable of handling JavaScript. Essentially Beautiful Soup fetches webpage from the server without the help of a browser. We get what we see in the "view page source". If the data that we are looking for is available in the "view page source", then Beautiful Soup is sufficient for web scraping. But if we  need data that gets rendered only upon clicking a JavaScript link, then we need to use dynamic web scraping methods In such a situation we first use Selenium to automate the browser and click on the JavaScript link, wait for the elements to load and then use Beautiful Soup to extract the elements.

13 August 2017

Facebook Cleaner - Automate deletion of FB Posts/Likes/Comments

The Selenium WebDriver API is a great choice when it comes to automating browsers for auto / semi-auto trading. It also has some other quick fix applications like automating the deletion of facebook posts/likes/comments etc. To give a rough analogy -  As CCleaner is to the PC, this Facebook Cleaner is to your facebook  profile.
For the specific purpose of automating Facebook,  using the  Facebook SDK for Python is another  good option for consideration. However at the time of the development of this script,  the  Graph API Version 2.7 was the latest released version for the  facebook SDK for Python. But the official Graph API Version of facebook was 2.10. And so Selenium it was !!!!


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 


17 February 2017

Automation of the Windows Terminal of NSE NOW

Disclaimer:
  1. Try this at your own risk.
  1. If you do decide to use this, Test  it thoroughly before you do so.
  2. At the time of writing, the NSE NOW version is : 1.13.3.5
  1. This has been tested by me  only for the above mentioned version for the NSE NOW software provided by my broker Finvasia.
  1. This has been tested on  Win 10 64 bit OS
  1. The automation script is designed for day trading on the NSE CASH segment

Acknowledgement:
This brilliant article from Stocksonfire set me thinking. Its perfectly suited for those of us who like to trade on the FnO segment  for a fixed lot size.  Although limited in its functionality, X-Mouse Button Control is a good choice for this.
But what if I need to trade on the NSE Cash segment with a clear cut position sizing and a dynamic Stop Loss ? Therein lay the origin of this script written in AutoIt.  Some of the other tools that I have explored for this automation are SikuliX, Selenium and AutoHotkey


Purpose of this Automation:
  1. Create a Hotkey for placing a Buy/Sell order. Here (Shift + B) is used for placing a Buy Order. And (Shift + S) is used to place a Sell Order
  2. Automatically place a SL (either SL-Limit Order or a SL-Market Order) along with each Buy/Sell Order.  The default is  SL-Limit Order.
  3. For a Long position, the Low of the day is taken as Stop Loss . For a Short position, the High of the day is taken as SL.
  1. A rudimentary Position Sizing .  For the input trading capital , the number of shares to Buy/Sell are determined by the formulae: (ltp - stoploss)*noofshares = risk per trade. For finer details on position sizing, check with the writings of GuruJi Van Tharp