21 November 2022
Send email from Gmail using Python
20 November 2022
Schedule Python Scripts with Windows Task Scheduler
Step 1
16 November 2022
Webscraping of JavaScript Pages using a combination of Selenium & Beautiful Soup
Why Selenium?
15 November 2022
Intro to Python logging module - An alternative to print() function
Logging is generally used to debug our Python code. Many of us (like me) have a habit of using the print() function extensively during the development of a program. Nothing bad in that per se, just that when we want to promote this program to the production environment we must necessarily remove the print() statements.
There are other reasons too why the print statement is not recommended and its better to use the logging module:
- The print statement works only if we have access to the console
- We have no mechanism to write the print statements to a text file for further perusal
08 May 2022
pdb - The Python Debugger / breakpoint
breakpoint versus pdb
import pdb pdb.set_trace()
breakpoint() # in python 3.7 and above
27 March 2021
Create a Watchdog in Python
What is Watchdog in Python
Step 1: Import some Stuff
import os import time from watchdog.observers import Observer from watchdog.events import PatternMatchingEventHandler
Step 2: Create the event handler
if __name__ == "__main__": # patterns = "*" # the file patterns we want to handle patterns = "*.csv" # choose only csv files ignore_patterns = "" ignore_directories = True case_sensitive = True # Create the event handler my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)
20 March 2021
Installation of WordPress on localhost
Why install wordpress.org locally on your computer?
Note: If you install WordPress locally on Windows, then the only person who can see that site is you. If you want to make a website that is available to the public, then you need to have a domain name and web hosting.
What do I need for running wordpress.org locally on my computer?
14 March 2021
A Primer to ib_insync - Interactive Brokers Part 8
Why ib_insync ?
Pls. note that ib_insync is very different from the TWS API provided by IB. The TWS API is the official API created by IB while ib_insync is created by a team of individuals headed by Guru Ji Ewald de Wit
08 March 2021
Developing a Trading System for TWS API - Interactive Brokers Part 7
What is a trading system?
What are the elements of a full fledged trading system that can be deployed in Production?
- An Entry Point
- A Stop Loss / Trailing Stop Loss
- An Exit Point
08 February 2021
Scale Order with Adjustable Stop in TWS API - Interactive Brokers Part 6
Scenario:
Solution:
03 February 2021
Handling Callback data between threads in TWS API - Interactive Brokers Part 5
Scenario:
Important notes concerning IBApi.EWrapper.orderStatus :
- Typically there are duplicate orderStatus messages with the same information that will be received by a client. This corresponds to messages sent back from TWS, the IB server, or the exchange.
- There is no guarantee that an orderStatus callbacks will be triggered for every change in order status. For example with market orders when the order is accepted and executes immediately, there commonly will not be any corresponding orderStatus callbacks. For that reason it is recommended to monitor the IBApi.EWrapper.execDetails function in addition to IBApi.EWrapper.orderStatus.
18 November 2020
Create Bootable Ubuntu USB Drive with Persistent Storage from Win 10
Scenario:
16 November 2020
Crack PDF Password using John the Ripper in Ubuntu 20.04
Scenario:
I started with PDFcrack and almost 3 days later, the program is still running !!!. So that's when I started looking at alternatives. Nothing wrong with PDFcrack per se, just that it is one of the limitations of brute force password cracking. In fact there is even a beautiful blogpost from Ruby Pdf Technologies on some of the intricacies of PDFcrack.
I remembered using something earlier when I was experimenting with Kali Linux. So I went back to the "gold standard" which is called John the Ripper password cracker.
Types of Password's:
14 November 2020
Install Nvidia Drivers & CUDA in Ubuntu 20.04 (in UEFI mode with Secure Boot Enabled)
In the previous article, we have dealt with Installation of Ubuntu in Dual Boot Mode using UEFI. Now lets look at the installation of Nvidia Drivers for the GPU.
Basic Verification's:
First let us find out the graphics card that is presently used by the system. Click on Settings->About. Presently we have "NV138 / Mesa Intel® UHD Graphics 620 (KBL GT2)" installed.
09 November 2020
Dual Boot Win 10 and Ubuntu for system with (SSD + HDD) using UEFI - GPT method
Scenario:
I intend to use a Linux based VPS to host my trading strategies on AWS. So how do I create a dual boot in my existing Win 10 machine ?
22 September 2020
Thread Synchronization using Event Object in Python - Interactive Brokers Part 4
- This is sometimes achieved by using a "trial and error approach using the time.sleep() function in Python". While this may work, it is always a problematic issue in determining the amount of time we need to wait. And using the time.sleep() in such cases is not the right way of achieving the result.
- Another approach is to use flags to arrive at a better approximation in using the time.sleep() function.
- Use the Event Object to achieve thread synchronization
07 September 2020
Making blogger a little less painful
Table of Contents
Recently google made an update to blogger for formatting code and inserting anchors in the Compose View itself(instead of HTML view). Yeah, it was just about the time when they came out with this fine separation between "blogger" and "legacy blogger".
The new changes they had incorporated was very good, focused as it was on simplicity . I actually used it to create one blog post which required the use of Table of Contents right from the "Compose View". I also used it to insert my Python code right from the "Compose View". Imagine the savings in time for somebody who makes a blog post daily ?
Suddenly a few days later all of it vanished as mysteriously as they appeared. Another Google+ ??? (oh yeah, that much touted alternative to Facebook)
Google seems to have done a veto on their recent updates to blogger. But yet I prefer google over some other blogging options like Medium becos in the near future google corporation don't need to worry about monetizing blogger , unlike the corporation run by Evan William's. ( He is the same guy who started blogger too , which was latter purchased by Google ).
So I began to think - How can I make blogging more easy on blogger instead of switching to another platform. Maybe google might bring those feature back, or maybe they wont. We don't know. So lets see what we can do for now.
I would like to cover the following issues which are of concern to me:
Formatting Source Code:
10 August 2020
Advanced Techniques in TWS API - Interactive Brokers Part 3
In the first part of the blog on the TWS API of Interactive Brokers, I have dealt with the Installation of TWS API on a Windows machine for Anaconda distro.
In the second part of the blog, titled Fundamentals of TWS API, I have dealt with the essentials to get started.
Now in this third part I seek to explore the concepts like using a scanner, retrieving the OHLCV data and writing it to a CSV file, Hedging a Futures Contract with Options and many others including a fully functional sample trading system.
Table of Contents :
Optionable Contracts in NSE using the Scanner
Let's get to the point straight - The TWS API is just an interface to the TWS. If you are having problems defining a scanner viz the API , always make sure you can create a similar scanner using the TWS or the Mosaic Market Scanner.
24 June 2020
Fundamentals of TWS API - Interactive Brokers Part 2
Generally Interactive Brokers releases the installer for both the TWS API and IB Gateway simultaneously. For this blog I will use TWS API ( Version: API 9.79 Release Date: Feb 05 2020 ) and not IB Gateway. Check out my previous blog post for detailed installation guide of TWS API on Win 10 Machine that uses the Anaconda Distribution for Python.
IB also has a host of API's. A recent one that they added is a REST based API which they refer to as Client Portal WebAPI . However this blog post deals solely with the TWS API
Table of Contents :
The general operation of the TWS API application is:
- Establish connection with IB server.
- Request information from IB server or execute an action
- If a response is provided by the IB server, then receive the response and process the response
- Repeat steps 2 & 3 until all the required information has been received and all the operations have been executed.
- Terminate the Connection with IB server.
30 April 2020
Installation of TWS API - Interactive Brokers Part 1
- Automate your strategies
- Create a custom trading terminal
- Develop a Screener
- Experiment with your own Trading Indicator
And besides the TWS API, there are also other API solutions that are offered by Interactive Brokers and check them in this PDF download. Also one can check out groups for discussion on API


