add dockerfile and improve bot
This commit is contained in:
parent
1d5916e74f
commit
bf2c4f18d5
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM python:3.10-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN pip3 install poetry && \
|
||||||
|
poetry config virtualenvs.create false
|
||||||
|
|
||||||
|
COPY poetry.lock pyproject.toml ./
|
||||||
|
|
||||||
|
RUN poetry install --no-dev
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENTRYPOINT poetry run python3 binance_leaderboard/main.py
|
||||||
|
|
@ -11,7 +11,7 @@ from pathlib import Path
|
||||||
TOKEN = os.getenv('TELEGRAM_TOKEN')
|
TOKEN = os.getenv('TELEGRAM_TOKEN')
|
||||||
|
|
||||||
|
|
||||||
myfile = Path('chats.txt')
|
myfile = Path('/data/chats.txt')
|
||||||
myfile.touch(exist_ok=True)
|
myfile.touch(exist_ok=True)
|
||||||
|
|
||||||
chats = open(myfile).readlines()
|
chats = open(myfile).readlines()
|
||||||
|
|
@ -47,7 +47,7 @@ def send_all(msg):
|
||||||
payload = {"encryptedUid": "F45BBD3F4C148BFCE413B0A343A1BF97", "tradeType": "PERPETUAL"}
|
payload = {"encryptedUid": "F45BBD3F4C148BFCE413B0A343A1BF97", "tradeType": "PERPETUAL"}
|
||||||
|
|
||||||
def get_data(response):
|
def get_data(response):
|
||||||
ret = []
|
ret = {}
|
||||||
for position in response:
|
for position in response:
|
||||||
obj = {}
|
obj = {}
|
||||||
obj["symbol"] = position["symbol"]
|
obj["symbol"] = position["symbol"]
|
||||||
|
|
@ -56,20 +56,29 @@ def get_data(response):
|
||||||
obj["updateTime"] = position["updateTime"]
|
obj["updateTime"] = position["updateTime"]
|
||||||
obj["updateTimeStamp"] = position["updateTimeStamp"]
|
obj["updateTimeStamp"] = position["updateTimeStamp"]
|
||||||
obj["leverage"] = position["leverage"]
|
obj["leverage"] = position["leverage"]
|
||||||
ret.append(obj)
|
ret[position["symbol"]] = obj
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def send_msg_formatted(position):
|
def send_msg_formatted(position, state = None):
|
||||||
text = f"""Symbol: *{position['symbol']}*
|
text = ""
|
||||||
|
if state == "open":
|
||||||
|
text += "🚨 Ouverture\n"
|
||||||
|
elif state == "close":
|
||||||
|
text += "🔒 Clôture\n"
|
||||||
|
else:
|
||||||
|
text += "➡️ Changement de position\n"
|
||||||
|
text += f"""Symbol: *{position['symbol']}*
|
||||||
Leverage: *{position['leverage']}x*
|
Leverage: *{position['leverage']}x*
|
||||||
Opening: *{position['entryPrice']}*
|
Opening: *{position['entryPrice']}*
|
||||||
Type: *{'🔴 Short' if position['amount'] < 0 else '🟢 Long'}*"""
|
Type: *{'🔴 Short' if position['amount'] < 0 else '🟢 Long'}*
|
||||||
|
Amount: *{abs(position['amount'])}*"""
|
||||||
send_all(text)
|
send_all(text)
|
||||||
|
|
||||||
first = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload)
|
first = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload)
|
||||||
first_r = first.json()
|
first_r = first.json()
|
||||||
data = get_data(first_r["data"]["otherPositionRetList"])
|
data = get_data(first_r["data"]["otherPositionRetList"])
|
||||||
|
|
||||||
|
send_all("Bot restarted")
|
||||||
for position in data:
|
for position in data:
|
||||||
send_msg_formatted(position)
|
send_msg_formatted(position)
|
||||||
|
|
||||||
|
|
@ -79,8 +88,15 @@ while True:
|
||||||
resp = r.json()
|
resp = r.json()
|
||||||
ndata = get_data(resp["data"]["otherPositionRetList"])
|
ndata = get_data(resp["data"]["otherPositionRetList"])
|
||||||
if ndata != data:
|
if ndata != data:
|
||||||
for position in ndata:
|
for symbol in ndata:
|
||||||
send_msg_formatted(position)
|
if symbol not in data:
|
||||||
|
send_msg_formatted(ndata[symbol], "open")
|
||||||
|
elif ndata[symbol] != data[symbol]:
|
||||||
|
send_msg_formatted(ndata[symbol])
|
||||||
|
for symbol in data:
|
||||||
|
if symbol not in ndata:
|
||||||
|
send_msg_formatted(ndata[symbol], "close")
|
||||||
|
|
||||||
print("c'est pas la meme", ndata, data)
|
print("c'est pas la meme", ndata, data)
|
||||||
data = ndata
|
data = ndata
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Aurelien Rebourg <aurelien.rebourg@gmail.com>"]
|
authors = ["Aurelien Rebourg <aurelien.rebourg@gmail.com>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
packages = [{include = "binance_leaderboard"}]
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue