27 March 2021

Create a Watchdog in Python

 What is Watchdog in Python

Watchdog is a python module that can be used to monitor file system changes. As the name suggests this module observes the given directory and can notify if a file is created or changed.

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?

We can do all our testing on our local computer , one that doesn’t affect our live WordPress site.

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?

For Windows users, WampServer is the best way to start off with installation of wordspress.org on your computer? WAMP, is a compilation of Apache web server, PHP and MySQL bundled for Windows computers.

14 March 2021

A Primer to ib_insync - Interactive Brokers Part 8

Why ib_insync ?

While retrieving stock data for multiple symbols asynchronously from the TWS API provided by IB, I found the going a little steep. And here was ib_insync which made the task so very simple for me.

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?

It is a set of rules that can be based on technical indicators, quantitative methods, fundamental analysis or simply a mix of all or some of them.


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:

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.