From 5cb85d721fe6e49a36952a9eb192bc3fa53310f1 Mon Sep 17 00:00:00 2001 From: jc-cb <102254382+jc-cb@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:04:01 -0500 Subject: [PATCH 1/4] add price and graph dynamic update --- README.md | 2 +- callback_graph.py | 6 +++--- callback_price.py | 6 ++++-- layout.py | 2 ++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dba20ee..d3479ac 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a single page trading application built for Coinbase Prime using Dash, an open source framework for building Python data apps. All scripts are written in Python and tested with version 3.8.9. -![figure](assets/app.png) +> ![figure](assets/app.png) ## Installation Simply clone the repo from your terminal window with the below command. diff --git a/callback_graph.py b/callback_graph.py index b8fba84..690d712 100644 --- a/callback_graph.py +++ b/callback_graph.py @@ -35,13 +35,12 @@ def create_dataframe(parse): ) df = df.loc[::-1].reset_index(drop=True) df['diff'] = df['price_close'] - df['price_open'] - df['rsi'] = momentum.rsi(df['price_close'], window=14, fillna=False) df.loc[df['diff'] >= 0, 'color'] = 'green' df.loc[df['diff'] < 0, 'color'] = 'red' df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s') - df['rsi'] = momentum.rsi(df['price_close'], window=14, fillna=False) df['MA20'] = df['price_close'].rolling(window=20).mean() df['MA7'] = df['price_close'].rolling(window=7).mean() + df['rsi'] = momentum.rsi(df['price_close'], window=14, fillna=False) return df @@ -151,8 +150,9 @@ def register_graph(app): Output('product-chart', 'figure'), Input('product-switcher', 'value'), Input('gran-switcher', 'value'), + Input('timer', 'n_intervals'), ) - def update_output(product_id_selection, granularity_selection): + def update_output(product_id_selection, granularity_selection, n_intervals): """updates Plotly candlestick chart on UI product and granularity inputs""" url = f'https://api.exchange.coinbase.com/products/{product_id_selection}/candles?granularity={str(granularity_selection)}' headers = {'Accept': 'application/json'} diff --git a/callback_price.py b/callback_price.py index 89457a1..b85c085 100644 --- a/callback_price.py +++ b/callback_price.py @@ -21,8 +21,10 @@ def register_price(app): @app.callback( Output('price-ref', 'children'), - Input('product-switcher', 'value')) - def update_price(product_id_selection): + Input('product-switcher', 'value'), + Input('timer', 'n_intervals'), + ) + def update_price(product_id_selection,n_intervals): """calls Exchange Get Product Ticker endpoint for price data""" denomination = product_id_selection.split('-')[1] diff --git a/layout.py b/layout.py index 80c159a..91a9e6d 100644 --- a/layout.py +++ b/layout.py @@ -65,6 +65,8 @@ ), html.Button('Submit', id='submit-button', n_clicks=0), html.Div(id='buy-sell-response', style={'padding-top': 10}), + dcc.Interval(id='timer', interval=3000), + ], style={'padding': 30, 'flex': 1, 'font-family': 'Inter'}, ) From bcbc73a4d690adf6c839430c29576725a43c5930 Mon Sep 17 00:00:00 2001 From: jc-cb <102254382+jc-cb@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:06:53 -0500 Subject: [PATCH 2/4] dates --- LICENSE | 2 +- app.py | 2 +- callback_graph.py | 2 +- callback_price.py | 2 +- layout.py | 2 +- prime_api.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index e36cbe4..d021944 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022 Coinbase Global, Inc. + Copyright 2022-present Coinbase Global, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/app.py b/app.py index 3f993d4..63d09c8 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -# Copyright 2022 Coinbase Global, Inc. +# Copyright 2022-present Coinbase Global, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/callback_graph.py b/callback_graph.py index 690d712..f2bb2f6 100644 --- a/callback_graph.py +++ b/callback_graph.py @@ -1,4 +1,4 @@ -# Copyright 2022 Coinbase Global, Inc. +# Copyright 2022-present Coinbase Global, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/callback_price.py b/callback_price.py index b85c085..35f6cfb 100644 --- a/callback_price.py +++ b/callback_price.py @@ -1,4 +1,4 @@ -# Copyright 2022 Coinbase Global, Inc. +# Copyright 2022-present Coinbase Global, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/layout.py b/layout.py index 91a9e6d..17e6cef 100644 --- a/layout.py +++ b/layout.py @@ -1,4 +1,4 @@ -# Copyright 2022 Coinbase Global, Inc. +# Copyright 2022-present Coinbase Global, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/prime_api.py b/prime_api.py index 58bf573..fea2afe 100644 --- a/prime_api.py +++ b/prime_api.py @@ -1,4 +1,4 @@ -# Copyright 2022 Coinbase Global, Inc. +# Copyright 2022-present Coinbase Global, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 53692388e81f67f21be1c5e2315a34afd55511f0 Mon Sep 17 00:00:00 2001 From: jc-cb <102254382+jc-cb@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:17:59 -0500 Subject: [PATCH 3/4] time --- layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layout.py b/layout.py index 17e6cef..67ae32a 100644 --- a/layout.py +++ b/layout.py @@ -65,7 +65,7 @@ ), html.Button('Submit', id='submit-button', n_clicks=0), html.Div(id='buy-sell-response', style={'padding-top': 10}), - dcc.Interval(id='timer', interval=3000), + dcc.Interval(id='timer', interval=10000), ], style={'padding': 30, 'flex': 1, 'font-family': 'Inter'}, From 4ab5e1793edeb3619c7af1b48ea3a36bf7457e7c Mon Sep 17 00:00:00 2001 From: jc-cb Date: Wed, 24 May 2023 14:48:59 -0400 Subject: [PATCH 4/4] update requests --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f21c7ed..48c9499 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -requests==2.27.1 +requests==2.31.0 dash==2.6.2 ta==0.10.2 pandas==1.5.0