app index detail price
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from starlette.responses import FileResponse
|
|
| 7 |
from index_data import IndexEnum,INDEX_MAP
|
| 8 |
from typing import Dict, List
|
| 9 |
from pydantic import BaseModel
|
| 10 |
-
from models import PsxMarketResponse,PsxStock
|
| 11 |
from threading import Thread
|
| 12 |
from datetime import datetime,timedelta
|
| 13 |
import re
|
|
@@ -491,4 +491,25 @@ def get_all_currency():
|
|
| 491 |
|
| 492 |
response = currencyExchange.get_all_currency()
|
| 493 |
|
| 494 |
-
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from index_data import IndexEnum,INDEX_MAP
|
| 8 |
from typing import Dict, List
|
| 9 |
from pydantic import BaseModel
|
| 10 |
+
from models import PsxMarketResponse,PsxStock,IndexPrice,IndexPriceFormate,DataIndex
|
| 11 |
from threading import Thread
|
| 12 |
from datetime import datetime,timedelta
|
| 13 |
import re
|
|
|
|
| 491 |
|
| 492 |
response = currencyExchange.get_all_currency()
|
| 493 |
|
| 494 |
+
return response
|
| 495 |
+
|
| 496 |
+
@app.get("/get_index_price/{index_name}")
|
| 497 |
+
def get_index_price(index_name: str):
|
| 498 |
+
r = requests.get(f"https://dps.psx.com.pk/timeseries/int/{index_name}")
|
| 499 |
+
response = IndexPrice.model_validate_json(r.json())
|
| 500 |
+
|
| 501 |
+
formatted_data = [
|
| 502 |
+
DataIndex(
|
| 503 |
+
date=item[0],
|
| 504 |
+
price=item[1],
|
| 505 |
+
volume=item[2]
|
| 506 |
+
) for item in response.data
|
| 507 |
+
]
|
| 508 |
+
|
| 509 |
+
formatted_response = IndexPriceFormate(
|
| 510 |
+
status=response.status,
|
| 511 |
+
message=response.message,
|
| 512 |
+
data=formatted_data
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
return formatted_response
|
models.py
CHANGED
|
@@ -812,3 +812,23 @@ class CurrencyCountryResponse(BaseModel):
|
|
| 812 |
response: List[CurrencyResponse]
|
| 813 |
|
| 814 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 812 |
response: List[CurrencyResponse]
|
| 813 |
|
| 814 |
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
class IndexPrice(BaseModel):
|
| 818 |
+
status: int
|
| 819 |
+
message: str
|
| 820 |
+
data: List[List[float]]
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
class DataIndex(BaseModel):
|
| 824 |
+
date: float
|
| 825 |
+
price: float
|
| 826 |
+
volume: float
|
| 827 |
+
|
| 828 |
+
class IndexPriceFormate(BaseModel):
|
| 829 |
+
status: int
|
| 830 |
+
message: str
|
| 831 |
+
data: List[DataIndex]
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
|