Skip to content
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ https://discord.gg/Qb9unmxD6D
#### Current Exchanges
- [Bybit](https://partner.bybit.com/b/webhookbot)
- [Binance Futures](https://www.binance.com/en/register?ref=LMFD8MJ5)
- [Binance Spot](https://www.binance.com/en/register?ref=LMFD8MJ5)
- [KuCoin](https://www.kucoin.com/)
- More will be done on request or can be added by submitting a pull request.

<br>
Expand All @@ -22,6 +24,8 @@ https://discord.gg/Qb9unmxD6D

[Create Binance Futures Account](https://www.binance.com/en/register?ref=LMFD8MJ5)

[Create Binance Spot Account](https://www.binance.com/en/register?ref=LMFD8MJ5)

<br>
<br>

Expand Down Expand Up @@ -119,7 +123,7 @@ _Now when your alerts fire off they should go strait to your server and get proc
| Constant |Settings Keys |
|--|--|
|key| unique key that protects your webhook server|
|exchange | bybit, binacne-futures |
|exchange | bybit, binance-futures, binance-spot, kucoin |
|symbol | Exchange Specific ** See Below for more |
|side|Buy or Sell |
|type | Market or Limit |
Expand All @@ -138,3 +142,5 @@ _Now when your alerts fire off they should go strait to your server and get proc
|BYBIT INVERSE| BTCUSD|
|BYBIT PERP | BTCUSDT|
|Binance Futures | BTC/USDT|
|Binance Spot | BTC/USDT|
|KuCoin | BTC/USDT|
133 changes: 102 additions & 31 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from pybit import HTTP
import time
import ccxt
from binanceFutures import Bot
from binanceFutures import Bot as BinanceFuturesBot
from binanceSpot import Bot as BinanceSpotBot
from kucoin import Bot as KuCoinBot

def validate_bybit_api_key(session):
try:
Expand All @@ -13,12 +15,12 @@ def validate_bybit_api_key(session):
print("Bybit API key validation failed:", str(e))
return False

def validate_binance_api_key(exchange):
def validate_exchange_api_key(exchange, exchange_name):
try:
result = exchange.fetch_balance()
return True
except Exception as e:
print("Binance API key validation failed:", str(e))
print(exchange_name + " API key validation failed:", str(e))
return False

app = Flask(__name__)
Expand Down Expand Up @@ -46,24 +48,47 @@ def validate_binance_api_key(exchange):
)

use_binance_futures = False
binance_futures_exchange = None
if 'BINANCE-FUTURES' in config['EXCHANGES']:
if config['EXCHANGES']['BINANCE-FUTURES']['ENABLED']:
print("Binance is enabled!")
print("Binance Futures is enabled!")
use_binance_futures = True

exchange = ccxt.binance({
'apiKey': config['EXCHANGES']['BINANCE-FUTURES']['API_KEY'],
'secret': config['EXCHANGES']['BINANCE-FUTURES']['API_SECRET'],
'options': {
'defaultType': 'future',
binance_futures_options = {
'apiKey': config['EXCHANGES']['BINANCE-FUTURES']['API_KEY'],
'secret': config['EXCHANGES']['BINANCE-FUTURES']['API_SECRET'],
'options': {
'defaultType': 'future',
},
}
if config['EXCHANGES']['BINANCE-FUTURES'].get('TESTNET'):
binance_futures_options['urls'] = {
'api': {
'public': 'https://testnet.binancefuture.com/fapi/v1',
'private': 'https://testnet.binancefuture.com/fapi/v1',
},
}

binance_futures_exchange = ccxt.binance(binance_futures_options)
if config['EXCHANGES']['BINANCE-FUTURES'].get('TESTNET'):
binance_futures_exchange.set_sandbox_mode(True)

use_binance_spot = False
binance_spot_exchange = None
if 'BINANCE-SPOT' in config['EXCHANGES']:
if config['EXCHANGES']['BINANCE-SPOT']['ENABLED']:
print("Binance Spot is enabled!")
use_binance_spot = True

binance_spot_exchange = ccxt.binance({
'apiKey': config['EXCHANGES']['BINANCE-SPOT']['API_KEY'],
'secret': config['EXCHANGES']['BINANCE-SPOT']['API_SECRET'],
'options': {
'defaultType': 'spot',
},
'urls': {
'api': {
'public': 'https://testnet.binancefuture.com/fapi/v1',
'private': 'https://testnet.binancefuture.com/fapi/v1',
}, }
})
exchange.set_sandbox_mode(True)
if config['EXCHANGES']['BINANCE-SPOT'].get('TESTNET'):
binance_spot_exchange.set_sandbox_mode(True)

# Validate Bybit API key
if use_bybit:
Expand All @@ -73,10 +98,37 @@ def validate_binance_api_key(exchange):

# Validate Binance Futures API key
if use_binance_futures:
if not validate_binance_api_key(exchange):
if not validate_exchange_api_key(binance_futures_exchange, "Binance Futures"):
print("Invalid Binance Futures API key.")
use_binance_futures = False

# Validate Binance Spot API key
if use_binance_spot:
if not validate_exchange_api_key(binance_spot_exchange, "Binance Spot"):
print("Invalid Binance Spot API key.")
use_binance_spot = False

use_kucoin = False
kucoin_exchange = None
if 'KUCOIN' in config['EXCHANGES']:
if config['EXCHANGES']['KUCOIN']['ENABLED']:
print("KuCoin is enabled!")
use_kucoin = True

kucoin_exchange = ccxt.kucoin({
'apiKey': config['EXCHANGES']['KUCOIN']['API_KEY'],
'secret': config['EXCHANGES']['KUCOIN']['API_SECRET'],
'password': config['EXCHANGES']['KUCOIN']['API_PASSPHRASE'],
})
if config['EXCHANGES']['KUCOIN'].get('TESTNET'):
kucoin_exchange.set_sandbox_mode(True)

# Validate KuCoin API key
if use_kucoin:
if not validate_exchange_api_key(kucoin_exchange, "KuCoin"):
print("Invalid KuCoin API key.")
use_kucoin = False

@app.route('/')
def index():
return {'message': 'Server is running!'}
Expand Down Expand Up @@ -170,23 +222,42 @@ def webhook():
##############################################################################
# Binance Futures
##############################################################################
if data['exchange'] == 'binance-futures':
if use_binance_futures:
bot = Bot()
bot.run(data)
return {
"status": "success",
"message": "Binance Futures Webhook Received!"
}

else:
print("Invalid Exchange, Please Try Again!")
if data['exchange'] == 'binance-futures':
if use_binance_futures:
bot = BinanceFuturesBot(exchange_override=binance_futures_exchange)
bot.run(data)
return {
"status": "error",
"message": "Invalid Exchange, Please Try Again!"
"status": "success",
"message": "Binance Futures Webhook Received!"
}
##############################################################################
# Binance Spot
##############################################################################
if data['exchange'] == 'binance-spot':
if use_binance_spot:
bot = BinanceSpotBot(exchange_override=binance_spot_exchange)
bot.run(data)
return {
"status": "success",
"message": "Binance Spot Webhook Received!"
}
##############################################################################
# KuCoin
##############################################################################
if data['exchange'] == 'kucoin':
if use_kucoin:
bot = KuCoinBot(exchange_override=kucoin_exchange)
bot.run(data)
return {
"status": "success",
"message": "KuCoin Webhook Received!"
}

print("Invalid Exchange, Please Try Again!")
return {
"status": "error",
"message": "Invalid Exchange, Please Try Again!"
}

if __name__ == '__main__':
app.run(debug=False)


Loading