Skip to content

Instantly share code, notes, and snippets.

@jeff47
Last active August 31, 2021 11:24
Show Gist options
  • Save jeff47/7afeecb6f5399d4ca9548c672d22df02 to your computer and use it in GitHub Desktop.
Save jeff47/7afeecb6f5399d4ca9548c672d22df02 to your computer and use it in GitHub Desktop.
Funding Fee alerts for Binance/Pionex
#!/usr/bin/python3
import json, urllib, http.client
import requests
# Pionex does not currently have a way to send alerts if the funding fee for the Spot-Arbitrage bot falls below a
# certain level. In some cases, the funding fee can even be negative. I created this script to check the new funding
# fees from Binance, and send an alert via Pushover if the upcoming fee is below a cutoff. This will give me time to close
# the bot if the conditions are not favorable.
# To use this script, you'll need to register a Pushover account, get a Pushover ID and an API token. Those are all free.
# Then set this script to run periodically. The funding fees change 3 times a day, at 0, 8, and 16 UTC. There isn't much
# reason to run the bot much more frequently than that.
# I excluded these because they are always low and I don't want constant alerts from them.
excludelist = ["ETHUSDT_210625", "BTCUSDT_210625", "BTCSTUSDT", "BNTUSDT", "ETCUSDT", "BNBBUSD"]
# Send an alert if a token's funding fee for the next period is less than 0.05%.
lowlevelalert = 0.0005
# Pushovev [reference: https://pushover.net/api]
# You'll need to get your own API token and User ID from pushover.
pushoverAPIToken = "YOUR_API_TOKEN_HERE"
pushoverUserID = "YOUR_PUSHOVER_ID_HERE"
# Binance API [https://binance-docs.github.io/apidocs/futures/en/]
page = requests.get('https://fapi.binance.com/fapi/v1/premiumIndex')
futures = json.loads(page.content)
symbols = []
message = "The following tokens will be under " + str(lowlevelalert*100) + "% during the next period: "
for i in futures:
if float(i["lastFundingRate"]) < lowlevelalert and i["symbol"] not in excludelist:
#print(i["symbol"] + ": " + i["lastFundingRate"])
symbols.append(i["symbol"])
symbols.sort()
# Pushover
# reference: https://pushover.net/api
if len(symbols):
messages = {
"token": pushoverAPIToken,
"user": pushoverUserID,
"message": message + ", ".join(symbols),
"title": "Funding Fee Alert",
"html": 1,
"priority": 1,
"sound": "falling",
"url": "https://www.binance.com/en/futures/funding-history/0"
}
r = requests.post(url = "https://api.pushover.net/1/messages.json", data = messages)
@jeff47
Copy link
Author

jeff47 commented Apr 7, 2021

Revised so that the list is sorted alphabetically by symbol, which makes it easier to find the token you are interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment