0% found this document useful (0 votes)
3 views1 page

Daytrade 2

The document is a Python script that retrieves trading data from a specified API. It collects names of trading items, fetches their daily trade data, and aggregates the volume and prices by time. The script then prints names and details of items with more than five unique prices and a volume of at least 200,000.

Uploaded by

norooz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Daytrade 2

The document is a Python script that retrieves trading data from a specified API. It collects names of trading items, fetches their daily trade data, and aggregates the volume and prices by time. The script then prints names and details of items with more than five unique prices and a volume of at least 200,000.

Uploaded by

norooz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import json

import requests
from collections import OrderedDict
url='https://bourse.chartapi.ir/3uDlxKL6FD5F43wjCYW9WfysYHjN5lzf/alldata'
data_name=requests.get(url)
result_name=data_name.json()
names=[]
for item_name in result_name['data']:
names.append(item_name['name'])

for name in names:

try:
url=f'https://bourse.chartapi.ir/3uDlxKL6FD5F43wjCYW9WfysYHjN5lzf/
daytrades?name={name}'
data=requests.get(url)

result=data.json()
result = result['data']
regrouped_data = {}

for item in result:


time_key=item['time']
volume_key=item['volume']
price_key=item['price']

if time_key not in regrouped_data:


regrouped_data[time_key]={'count':1 , 'time':time_key ,
'volume':int(volume_key),'price':[price_key]}
else:
regrouped_data[time_key]['count']+=1
regrouped_data[time_key]['volume']+=int(volume_key)
regrouped_data[time_key]['price'].append(price_key)

result_data = list(regrouped_data.values())
for item in result_data:
item['price']=list(OrderedDict.fromkeys(item['price']))

for items in result_data:


if len(items['price'])>5 and items['volume']>=200000:

print(name)
print(items)
except:
None

You might also like