Update app.py
Browse files
app.py
CHANGED
|
@@ -217,23 +217,36 @@ def create_chart():
|
|
| 217 |
|
| 218 |
return fig_widget
|
| 219 |
|
|
|
|
|
|
|
| 220 |
async def continuous_data_update():
|
| 221 |
global latest_data
|
| 222 |
while True:
|
| 223 |
-
premium_info = get_combined_premium()
|
| 224 |
if "Combined Premium:" in premium_info:
|
| 225 |
crudeoilm, strike, premium = premium_info.split("|")
|
| 226 |
crudeoilm_value = float(crudeoilm.split(":")[1].strip())
|
| 227 |
strike_value = int(strike.split(":")[1].strip())
|
| 228 |
premium_value = float(premium.split(":")[1].strip())
|
|
|
|
| 229 |
latest_data = {
|
| 230 |
"premium": premium_value,
|
| 231 |
"time": pd.Timestamp.now(tz='Asia/Kolkata'),
|
| 232 |
"strike": strike_value,
|
| 233 |
"crudeoilm": crudeoilm_value
|
| 234 |
}
|
|
|
|
|
|
|
| 235 |
await asyncio.sleep(1)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
def update_chart():
|
| 238 |
global historical_data, latest_data
|
| 239 |
if latest_data["premium"] is not None:
|
|
|
|
| 217 |
|
| 218 |
return fig_widget
|
| 219 |
|
| 220 |
+
latest_data = {}
|
| 221 |
+
|
| 222 |
async def continuous_data_update():
|
| 223 |
global latest_data
|
| 224 |
while True:
|
| 225 |
+
premium_info = get_combined_premium() # Make sure this function works synchronously
|
| 226 |
if "Combined Premium:" in premium_info:
|
| 227 |
crudeoilm, strike, premium = premium_info.split("|")
|
| 228 |
crudeoilm_value = float(crudeoilm.split(":")[1].strip())
|
| 229 |
strike_value = int(strike.split(":")[1].strip())
|
| 230 |
premium_value = float(premium.split(":")[1].strip())
|
| 231 |
+
|
| 232 |
latest_data = {
|
| 233 |
"premium": premium_value,
|
| 234 |
"time": pd.Timestamp.now(tz='Asia/Kolkata'),
|
| 235 |
"strike": strike_value,
|
| 236 |
"crudeoilm": crudeoilm_value
|
| 237 |
}
|
| 238 |
+
|
| 239 |
+
# Sleep for 1 second between updates
|
| 240 |
await asyncio.sleep(1)
|
| 241 |
|
| 242 |
+
async def main():
|
| 243 |
+
# Run the data update task
|
| 244 |
+
await continuous_data_update()
|
| 245 |
+
|
| 246 |
+
if __name__ == "__main__":
|
| 247 |
+
# Start the event loop and run the main coroutine
|
| 248 |
+
asyncio.run(main())
|
| 249 |
+
|
| 250 |
def update_chart():
|
| 251 |
global historical_data, latest_data
|
| 252 |
if latest_data["premium"] is not None:
|