Storing and Retrieving Tick Data using MySQL and Python

We want that a single table should store the price values of multiple instrument tokens.

So, we will create a table that will have four columns:

  • id (auto increment)
  • time (default timestamp)
  • instrument_token (int)
  • last_price (float)

Let us first create a table.

Now, let us populate this with tick data.

Now the table looks like this.

Now, what if we want to retrieve the latest price of a particular instrument token.

We will execute the following sql command.

Here, we get the latest price of the instrument_token 11230.

Now, let’s see how this can be done with python.