08 February 2021

Scale Order with Adjustable Stop in TWS API - Interactive Brokers Part 6

Scenario:

I am using Python TWS API. For a Stock, I want to place a Limit Order with 2 Profit Takers and 1 Stop Loss. If Profit Taker 1 is hit, then the stop loss should decrease by the commensurate amount (so after Profit Taker 1 is hit, the stop loss quantity is now updated to be equal to Profit Taker 2 quantity). How to do this by packing this entire set of operation's into 1 order?

Solution:

Lets first experiment this scenario with the TWS GUI. For this we will use the Classic TWS.

03 February 2021

Handling Callback data between threads in TWS API - Interactive Brokers Part 5

Scenario:

After I place a market order using the TWS API, sometimes I do not receive the orderStatus callback for a very unusually long time. How then can I find out the status of the placed order ?

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:

One of my colleagues has a Windows 10 based laptop that uses multiple tabs of Chrome at any given point of time. Primarily for the use of Google Sheets and Google Docs. Besides this she also uses:
• Hangouts for conferencing wherein she needs to share her screen 
• Discord for Team Collaboration
• Skype for messaging
• Open Broadcaster Software(OBS) for audio-video recording
Performance finetuning of Win 10 has helped to improve the overall performance of her windows based laptop. But not as good as she would have preferred it to be. Hardware upgradation for performance improvement was not a factor for consideration . 

16 November 2020

Crack PDF Password using John the Ripper in Ubuntu 20.04

Scenario:

So I have this old PDF file which is password protected and  forgot the password. I tried various permutations and  combinations that came to my mind and they did not work. So what to do?

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:

PDFs can be encrypted for confidentiality by requiring either a user password  or a owner password (as in case of DRM). PDFs encrypted with a user password can only be opened by providing this password. PDFs encrypted with a owner password can be opened without providing a password, but some restrictions will apply (for example, printing could be disabled).

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:

My laptop uses Unified Extensible Firmware Interface (UEFI) and not the good old BIOS. I have a hybrid drive system in my machine, a mix of 256 GB SSD and 1 TB HDD. In my 256 GB SSD drive, I have my Win 10 operating system installed and main programs like Office , Chrome  etc. installed. I use the 1 TB HDD primarily to store data.

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 post uses the Interactive Brokers Python TWS API to explain Thread Synchronization using Event Object.

In many applications, sometimes, we need to pause the running of the program until some external condition occurs. You may need to wait until another thread finishes, or another callback is processed. In these situations and and many other similar situations you will need to figure out a way to make your script wait. Three common ways to achieve this are mentioned: 
  1. 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. 
  2. Another approach is to use flags to arrive at a better approximation in using the time.sleep() function.
  3. Use the Event Object to achieve thread synchronization