Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add price and graph dynamic update #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions callback_graph.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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'}
Expand Down
8 changes: 5 additions & 3 deletions callback_price.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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]

Expand Down
4 changes: 3 additions & 1 deletion layout.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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=10000),

],
style={'padding': 30, 'flex': 1, 'font-family': 'Inter'},
)
2 changes: 1 addition & 1 deletion prime_api.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests==2.27.1
requests==2.31.0
dash==2.6.2
ta==0.10.2
pandas==1.5.0
Expand Down