Realtime stock positions' profit and loss

Hi, I am new and trying to make a small dashboard that will update me with my current positions profit&loss every 2 secs. I have written a python code that gets the data from my TD Ameritrade API and transforms it into every ticker’s p&l ( cumulative p&l of all options and stocks) and stores it in my influxdb as a measurement.
Goal - My goal is to see all the positions of an account as a line chart with each line representing a ticker ( APPL, TSLA etc). X axis time and Y - axis profit/loss and each line representing a ticker.

  1. The way I m creating my measurement is -
    json_complete={‘measurement’ : ‘stockpos’, ‘tags’: {‘account’:account_no},‘fields’: {‘pnl’ : float(ticker_dict[key]), ‘ticker’ : key}}. Which looks something like this->

1613370203172634400 325111132 -155.1 SPCE
1613370203175635000 455111111 -456 ACB
1613370203178634800 455111111 -122 OPEN
1613370203181634800 455111111 401 ITB
1613370203183634600 123033123 -187.5 SPY
1613370203186634500 123033123 30 KNOS
1613370203189634100 123033123 141 FB

When I try to plot it on grafana I don’t see anything that will help me plot. My pull is happening every 1sec… Now with the processing and all I see this in the python console.

Timestamp → 2021-02-15 07:00:00.927613
Timestamp → 2021-02-15 07:00:02.309643
Timestamp → 2021-02-15 07:00:03.780646
Every iteration is taking all positions and populating it in the measurement.

Hence, it is taking slightly more than 1 sec. Now when I am trying to plot the data every 5 sec on grafana. I see the numbers all over it should be just one number now as I m testing during off hours and all the numbers are stagnant.
I think the different refresh rate is messing it up.

  1. Can someone please help me first making the measurement correct - I mean the fields n tag. I do not see anything that will plot all the tickers on the chart with P&L.
  2. what should be the query on the grafana?
  3. Does the sync frequency matter?

You are scraping the data from your broker using py and pushing it into influxdb and you want to graph it there?

Yes. I was able to figure it out on my own. Now its working on my local machine… Next step is to push out to the cloud.

How do I close the thread?

@bluebird mark a solution! :slight_smile:

1 Like

thanks…

@bluebird do you have a tutorial on this? Or code posted anywhere?