-
Notifications
You must be signed in to change notification settings - Fork 3
/
streamlit_app.py
158 lines (140 loc) Β· 5.77 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from collections import namedtuple
from pandas._libs.tslibs import timestamps
import altair as alt
import os
import math
import pandas as pd
import streamlit as st
import numpy as np
from bs4 import BeautifulSoup as BS
import requests
import urllib3
import time
import matplotlib.pyplot as plt
import plotly.express as px
import lstm_eth
import lstm_btc
import ichimoku
import rsi
from trading import PortfolioManager
from alpaca_trade_api.rest import REST
st.set_page_config(
page_title="Crypototo Roboto",
page_icon="πͺ",
layout="centered",
initial_sidebar_state="collapsed",
)
# ! Trading Sidebar - Start
# TODO: Change the below key to your own API key or Please follow the README file to export keys
alpaca_api_key = os.getenv("APCA_API_KEY_ID")
alpaca_secret_key = os.getenv("APCA_API_SECRET_KEY")
request = requests.get("https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=ETH&to_currency=USD&apikey=R298VOBAB51H5V8O").json()
eth_price = round(float(request['Realtime Currency Exchange Rate']['5. Exchange Rate']), 2)
api = REST(alpaca_api_key, alpaca_secret_key, api_version='v2')
manager = PortfolioManager()
with st.sidebar.form(key ='execution form'):
title = st.title('πΈ Execute Trade Now!')
my_account = st.header("Equity: $"+api.get_account().equity)
my_buying_power = st.subheader("Buying Power: $"+api.get_account().buying_power)
divider = st.markdown("---")
eth_icon = st.image("https://media.giphy.com/media/DdpmhAQpQZzwHSrQ3f/giphy.gif?cid=ecf05e477ppdd3d2qdsrijoe2u0mgeaw9y3pa95xigzoozkd&rid=giphy.gif&ct=s")
eth_price = st.metric(label="Current Price in $USD", value = eth_price)
eth_qty = st.number_input("Enter Quantity in ETH", value =0.10, min_value = 0.0, max_value = 10.0)
eth_side = st.selectbox("Do you wish to buy or sell?", ("buy", "sell"))
submit = st.form_submit_button(label = 'Place Market Order Now β
')
if submit:
post_url = "https://paper-api.alpaca.markets/v2/orders"
post_json = {"symbol":"TSLA", "qty":eth_qty, "side":eth_side, "type":"market", "time_in_force":"day"}
post_header = {"APCA-API-KEY-ID":alpaca_api_key , "APCA-API-SECRET-KEY":alpaca_secret_key}
response = requests.post(post_url, json = post_json, headers= post_header)
# ! Trading Sidebar - End
st.markdown(
"""
<style>
.wrapper {
height: 5vh;
/*This part is important for centering*/
display: flex;
align-items: center;
justify-content: center;
}
.typing-demo {
width: 22ch;
animation: typing 2s steps(22), blink 0.5s step-end infinite alternate;
white-space: nowrap;
overflow: hidden;
border-right: 3px solid;
font-family: monospace;
font-weight: bold;
font-size: 4em;
}
@keyframes typing {
from {
width: 0;
}
}
@keyframes blink {
50% {
border-color: transparent;
}
}
</style>
<div class="wrapper">
<div class="typing-demo">
πͺ Crypototo Roboto
</div>
</div>
<br />
<br />
<a href="https://github.com/cleopatrick1/Project_2"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white" alt="github repo"></a>
<br />
<br />
<b>A one-stop shop of all the key trading signals and technical indicators! π</b>
<br />
Don't forget to check out the <code>sidebar</code> where you can send order to Alpaca instantly without needed to switch between browser tabs!
"""
, unsafe_allow_html=True)
"""
---
# π Ichimoku Cloud Trading Strategy
[Ichimoku cloud](https://www.investopedia.com/terms/i/ichimoku-cloud.asp) is designed to spot direction and momentum in order to help you make buy and sell decisions more easily.
\n Five indicators are used with each corresponding to a different timeline.
"""
st.write(ichimoku.get_ichimoku_plot())
"""
---
# π Watch Out for Whales!
Crypto market is not yet mature. Large players such as hedge funds and investment funds can use their advantage to manipulate the crypto price to their desired price to some extent, so it is important to always keep track of whale's movement and trade wisely!
\n Price available in $USD - credit: [@whale-alert](https://whale-alert.io)
"""
response = requests.get('https://api.whale-alert.io/v1/transactions?api_key=zd1tXydtCfegKwzLvUIMPCAasDBMiCnk¤cy=eth&limit=5').json()
whale_data = response["transactions"]
whale_df = pd.json_normalize(whale_data)
whale_df["timestamp"] = pd.to_datetime(whale_df["timestamp"], unit='s').dt.time
whale_df = whale_df[["timestamp", "amount_usd", "from.address", "from.owner"]]
cols = st.columns(5)
for whale in range(5):
amount_usd = whale_df.iloc[whale, 1]
timestamp = whale_df.iloc[whale, 0]
cols[whale].metric(label=str(timestamp), value="π", delta=amount_usd)
"""
---
# π Price Prediction with LSTM Machine Learning
[Long short-term memory (LSTM)](https://en.wikipedia.org/wiki/Long_short-term_memory) deep learning algorithm is a specialized architecture that can "memorize" patterns from historical sequences of data and extrapolate such patterns for future events.
\n Here we try to use LSTM to predict ETH's closing price of the next trading day.
"""
st.write(lstm_eth.get_lstm_plot_data())
st.markdown("**However, it is fair more accurate when it comes to BTC!** ")
st.write(lstm_btc.get_lstm_plot_data())
"""
---
# πΉ RSI Trading Strategy
[RSI stands for Relative Strength Index](https://www.investopedia.com/terms/r/rsi.asp). It is a popular indicator for trading. When an assets RSI is below 30 it is considered oversold and a buy signal. When an assets RSI is above 70 it is considered overbought and a sell signal.
\n Below you will see a price feed for ETHUSD and the current RSI, when it is either overbought or oversold a signal will appear.
"""
chart_container = st.container()
price_container = st.container()
with chart_container:
rsi.plot_chart()
with price_container:
rsi.get_rsi_price()