- Joined
- Feb 3, 2023
- Messages
- 1
- Reaction score
- 0
Can anyone help me with my Code im trying to programm my first crypto bot and need your help.
import ccxt
import time
import yfinance as yf
API_KEY = input("Your API Key : ")
SECRET_KEY = input("Your Secret Key : ")
# Verbindung zu Börse aufbauen
exchange = ccxt.bitvavo ({
'apiKey': API_KEY,
'secret': SECRET_KEY,
})
symbol = 'BTC/USDT'
# Berechnung der Bollinger Bänder mit yFinance
equity = yf.Ticker("AAPL")
data = equity.history(period='1y')
df = data[['Close']]
sma = df.rolling(window=20).mean().dropna()
rstd = df.rolling(window=20).std().dropna()
upper_band = sma + 2 * rstd
lower_band = sma - 2 * rstd
upper_band = upper_band.rename(columns={'Close': 'upper'})
lower_band = lower_band.rename(columns={'Close': 'lower'})
bb = df.join(upper_band).join(lower_band)
bb = bb.dropna()
buyers = bb[bb['Close'] <= bb['lower']]
sellers = bb[bb['Close'] >= bb['upper']]
# Stop Loss Level
stop_loss = 0.005
Anzahl = 75
# Ausführung des Bot-Tradings
while True:
# Preise abrufen
ticker = exchange.fetch_ticker(symbol)
# Geld pro Trade in USDT
cost=20
price = ticker['last']
amount=cost/price
# Handels Order setzen
if price == buyers:
# kaufen
exchange.create_order(symbol, 'limit', 'buy', amount, price)
buy_price = ticker['last']
elif price == sellers:
# Stop Loss Überprüfung
if price < stop_loss * buyers:
# verkaufen
exchange.create_order(symbol, 'limit', 'sell',amount, price)
# Pause von 5 Sekunden
time.sleep(5)
import plotly.io as pio
import plotly.graph_objects as go
pio.templates.default = "plotly_dark"
fig = go.Figure()
fig.add_trace(go.Scatter(x=lower_band.index,
y=lower_band['lower'],
name='Lower Band',
line_color='rgba(173,204,255,0.2)'
))
fig.add_trace(go.Scatter(x=upper_band.index,
y=upper_band['upper'],
name='Upper Band',
fill='tonexty',
fillcolor='rgba(173,204,255,0.2)',
line_color='rgba(173,204,255,0.2)'
))
fig.add_trace(go.Scatter(x=df.index,
y=df['Close'],
name='Close',
line_color='#636EFA'
))
fig.add_trace(go.Scatter(x=sma.index,
y=sma['Close'],
name='SMA',
line_color='#FECB52'
))
fig.add_trace(go.Scatter(x=buyers.index,
y=buyers['Close'],
name='Buyers',
mode='markers',
marker=dict(
color='#00CC96',
size=10,
)
))
fig.add_trace(go.Scatter(x=sellers.index,
y=sellers['Close'],
name='Sellers',
mode='markers',
marker=dict(
color='#EF553B',
size=10,
)
))
fig.show()
This is my Code but something seems to be wrong with creating the Orders.
import ccxt
import time
import yfinance as yf
API_KEY = input("Your API Key : ")
SECRET_KEY = input("Your Secret Key : ")
# Verbindung zu Börse aufbauen
exchange = ccxt.bitvavo ({
'apiKey': API_KEY,
'secret': SECRET_KEY,
})
symbol = 'BTC/USDT'
# Berechnung der Bollinger Bänder mit yFinance
equity = yf.Ticker("AAPL")
data = equity.history(period='1y')
df = data[['Close']]
sma = df.rolling(window=20).mean().dropna()
rstd = df.rolling(window=20).std().dropna()
upper_band = sma + 2 * rstd
lower_band = sma - 2 * rstd
upper_band = upper_band.rename(columns={'Close': 'upper'})
lower_band = lower_band.rename(columns={'Close': 'lower'})
bb = df.join(upper_band).join(lower_band)
bb = bb.dropna()
buyers = bb[bb['Close'] <= bb['lower']]
sellers = bb[bb['Close'] >= bb['upper']]
# Stop Loss Level
stop_loss = 0.005
Anzahl = 75
# Ausführung des Bot-Tradings
while True:
# Preise abrufen
ticker = exchange.fetch_ticker(symbol)
# Geld pro Trade in USDT
cost=20
price = ticker['last']
amount=cost/price
# Handels Order setzen
if price == buyers:
# kaufen
exchange.create_order(symbol, 'limit', 'buy', amount, price)
buy_price = ticker['last']
elif price == sellers:
# Stop Loss Überprüfung
if price < stop_loss * buyers:
# verkaufen
exchange.create_order(symbol, 'limit', 'sell',amount, price)
# Pause von 5 Sekunden
time.sleep(5)
import plotly.io as pio
import plotly.graph_objects as go
pio.templates.default = "plotly_dark"
fig = go.Figure()
fig.add_trace(go.Scatter(x=lower_band.index,
y=lower_band['lower'],
name='Lower Band',
line_color='rgba(173,204,255,0.2)'
))
fig.add_trace(go.Scatter(x=upper_band.index,
y=upper_band['upper'],
name='Upper Band',
fill='tonexty',
fillcolor='rgba(173,204,255,0.2)',
line_color='rgba(173,204,255,0.2)'
))
fig.add_trace(go.Scatter(x=df.index,
y=df['Close'],
name='Close',
line_color='#636EFA'
))
fig.add_trace(go.Scatter(x=sma.index,
y=sma['Close'],
name='SMA',
line_color='#FECB52'
))
fig.add_trace(go.Scatter(x=buyers.index,
y=buyers['Close'],
name='Buyers',
mode='markers',
marker=dict(
color='#00CC96',
size=10,
)
))
fig.add_trace(go.Scatter(x=sellers.index,
y=sellers['Close'],
name='Sellers',
mode='markers',
marker=dict(
color='#EF553B',
size=10,
)
))
fig.show()
This is my Code but something seems to be wrong with creating the Orders.