Notes
Notes - notes.io |
import numpy as np
import talib
import time
api_key = "ziYYeICrmuQbXcBWgmDmQ9Dk6x6omdz4BFmPdeaFnHK0GVyyijyeqBnewtdOK3dq"
secret_key = "39JKULdh5LH8Q1IQTECePJ9C34FX5ZsRWrGD995kY30Rxi4OphiMO0Kv2snLOiG4"
exchange = ccxt.binance({
'apiKey': api_key,
'secret': secret_key,
'enableRateLimit': True,
'options': {
'defaultType': 'future', # Use 'future' for Binance Futures
},
})
symbol = 'BTC/USDT'
timeframe = '1h'
length = 50
mult = 6.0
leverage = 20 # Set your desired leverage
def r(src, n):
s = 0.0
for i in range(n):
s += ((n-(i*2+1))/2) * src[i]
return s / (n * (n + 1))
def get_usdt_balance():
try:
balances = exchange.fetch_balance()
usdt_balance = float(balances['total']['USDT'])
return usdt_balance
except Exception as e:
print(f"Error fetching balance: {e}")
return None
def set_leverage(symbol, leverage):
try:
exchange.fapiPrivate_post_leverage({
'symbol': exchange.market_id(symbol),
'leverage': leverage,
})
print(f"Leverage set to {leverage} for {symbol}")
except Exception as e:
print(f"Error setting leverage: {e}")
def create_market_buy_order(symbol, quote_amount):
try:
ticker = exchange.fetch_ticker(symbol)
ask_price = ticker['ask']
amount = quote_amount / ask_price
order = exchange.create_market_buy_order(symbol, amount)
print(f"Market buy order created: {order}")
except Exception as e:
print(f"Error creating market buy order: {e}")
def create_market_sell_order(symbol, base_amount):
try:
order = exchange.create_market_sell_order(symbol, base_amount)
print(f"Market sell order created: {order}")
except Exception as e:
print(f"Error creating market sell order: {e}")
# Set leverage
set_leverage(symbol, leverage)
while True:
candles = exchange.fetch_ohlcv(symbol, timeframe)
close = np.array([c[4] for c in candles])
high = np.array([c[2] for c in candles])
low = np.array([c[3] for c in candles])
l = talib.SMA(low, length)
h = talib.SMA(high, length)
lr = l + mult * r(low, length)
hr = h + mult * r(high, length)
trend = np.where(close > lr, 1, np.where(close < hr, -1, 0))
long_signal = (trend == 1) & (close > h)
short_signal = (trend == -1) & (close < l)
if long_signal[-1]:
print('Long Signal')
usdt_balance = get_usdt_balance()
if usdt_balance:
create_market_buy_order(symbol, usdt_balance)
if short_signal[-1]:
print('Short Signal')
base_currency = symbol.split('/')[0]
base_balance = exchange.fetch_balance()['total'][base_currency]
if base_balance:
create_market_sell_order(symbol, base_balance)
time.sleep(60 * 60)
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team