Created
April 2, 2024 20:25
-
-
Save nilayparikh/3908c1f4b47d0946f3fa3a262a84dc18 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
prev_df = None | |
columns_to_check = ["o", "h", "l", "c", "v"] | |
while True: | |
result = client.query( | |
f"SELECT l_sym, rght, strk, exp, first_value(o) as o, max(h) AS h, min(l) AS l, last_value(c) as c, last_value(av) as av, count(*) as trades FROM {ch_table_name} WHERE sym='AAPL' GROUP BY l_sym, strk, exp, rght ORDER BY av DESC;" | |
) | |
df = pd.DataFrame(result.result_rows, columns=result.column_names) | |
if prev_df is not None: | |
styled_df: Styler = df.head(20).style.apply( | |
lambda x: [ | |
( | |
"background: green" | |
if c in columns_to_check and v > prev_df.loc[x.name, c] | |
else ( | |
"background: red" | |
if c in columns_to_check and v < prev_df.loc[x.name, c] | |
else "" | |
) | |
) | |
for v, c in zip(x, x.index) | |
], | |
axis=1, | |
) | |
else: | |
styled_df = df.head(20) | |
clear_output(wait=True) | |
display(styled_df) | |
prev_df = df.copy() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment