0

I am trying to read data online from a website every 1 seconds using following code, then plot the result in real time. I mean I like to add new last_price in every second to the previous plot and update it.

import time
import requests


for i in range(2600):

    time.sleep(1)
    with requests.Session() as s:
        data = {'ContractCode' : 'SAFTR98'}
        r = s.post('http://cdn.ime.co.ir/Services/Fut_Live_Loc_Service.asmx/GetContractInfo', json = data ).json()


    for key, value in r.items():
        print(r[key]['ContractCode'])
        last_prices = (r[key]['LastTradedPrice']) 

I used animation.FuncAnimation but didn't work because it plots all the results after the 2600 iterations is done or I stop the program! So I thought maybe I can do the work with multi-threading. But I don't know how exactly should I use it? I searched about but couldn't understand the examples and how should I map it to my problem?

This is not a duplicated question. In the mentioned link I tried to solve the problem using Animations but in this question I am trying to find a new way using multi-threading.

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • Possible duplicate of [Matplotlib create real time animated graph](https://stackoverflow.com/questions/34376656/matplotlib-create-real-time-animated-graph) – David Sidarous May 11 '19 at 20:08
  • @DavidSidarous: This is not a duplicated question. In the mentioned link I tried to solve the problem using Animations but in this question I am trying to find a new way using multi-threading. – Hasani May 11 '19 at 20:13

0 Answers0