Created
March 28, 2019 17:55
-
-
Save farbod-s/3a1ccbbd3eab285041dc840acfaceff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
query = 'http://members.tsetmc.com/tsev2/chart/data/Financial.aspx' | |
params = { | |
'i': '18027801615184692', | |
't': 'ph', | |
'a': '1' | |
} | |
params2 = { | |
'i': '35700344742885862', | |
't': 'ph', | |
'a': '1' | |
} | |
session = requests.session() | |
response = session.get(query, params=params) | |
content = response.text | |
response2 = session.get(query, params=params2) | |
content2 = response2.text | |
#response => 20031019,73,71,73,71,2000000,71;20031020,75,75,75,75,7500000,75;... | |
content_array = content.split(';') | |
content_array2 = content2.split(';') | |
values = [] | |
values2 = [] | |
i = 0 | |
j = 0 | |
for data in content_array: | |
values.append(data.split(',')[6]) | |
i = i + 1 | |
for data2 in content_array2: | |
values2.append(data2.split(',')[6]) | |
j = j + 1 | |
k = min(i, j, 300) | |
last_values = values[-k:] | |
last_values2 = values2[-k:] | |
min1 = min(last_values) | |
max1 = max(last_values) | |
min2 = min(last_values2) | |
max2 = max(last_values2) | |
new_values = [] | |
new_values2 = [] | |
for val in last_values: | |
new_val = (int(val) - int(min1)) / (int(max1) - int(min1)) | |
new_values.append(new_val) | |
for val2 in last_values2: | |
new_val2 = (int(val2) - int(min2)) / (int(max2) - int(min2)) | |
new_values2.append(new_val2) | |
df = pd.DataFrame({'x': range(0, k), 'y1': new_values, 'y2': new_values2}) | |
plt.plot('x', 'y1', data=df, color='blue', marker='', linewidth=1, label="KCH") | |
plt.plot('x', 'y2', data=df, color='red', marker='', linewidth=1, label="KGL") | |
plt.legend() | |
plt.show() |
Author
farbod-s
commented
Mar 28, 2019
Hi Farbod,
Great job!
I was wondering if there is any documentation for this query (http://members.tsetmc.com/tsev2/chart/data/Financial.aspx). Do you know what each parameter ('i', 't', 'a') mean?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment