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')
|
||||
|
||||
|
||||
myfile = Path('chats.txt')
|
||||
myfile = Path('/data/chats.txt')
|
||||
myfile.touch(exist_ok=True)
|
||||
|
||||
chats = open(myfile).readlines()
|
||||
|
|
@ -47,7 +47,7 @@ def send_all(msg):
|
|||
payload = {"encryptedUid": "F45BBD3F4C148BFCE413B0A343A1BF97", "tradeType": "PERPETUAL"}
|
||||
|
||||
def get_data(response):
|
||||
ret = []
|
||||
ret = {}
|
||||
for position in response:
|
||||
obj = {}
|
||||
obj["symbol"] = position["symbol"]
|
||||
|
|
@ -56,20 +56,29 @@ def get_data(response):
|
|||
obj["updateTime"] = position["updateTime"]
|
||||
obj["updateTimeStamp"] = position["updateTimeStamp"]
|
||||
obj["leverage"] = position["leverage"]
|
||||
ret.append(obj)
|
||||
ret[position["symbol"]] = obj
|
||||
return ret
|
||||
|
||||
def send_msg_formatted(position):
|
||||
text = f"""Symbol: *{position['symbol']}*
|
||||
def send_msg_formatted(position, state = None):
|
||||
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*
|
||||
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)
|
||||
|
||||
first = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload)
|
||||
first_r = first.json()
|
||||
data = get_data(first_r["data"]["otherPositionRetList"])
|
||||
|
||||
send_all("Bot restarted")
|
||||
for position in data:
|
||||
send_msg_formatted(position)
|
||||
|
||||
|
|
@ -79,8 +88,15 @@ while True:
|
|||
resp = r.json()
|
||||
ndata = get_data(resp["data"]["otherPositionRetList"])
|
||||
if ndata != data:
|
||||
for position in ndata:
|
||||
send_msg_formatted(position)
|
||||
for symbol in ndata:
|
||||
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)
|
||||
data = ndata
|
||||
except Exception:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ version = "0.1.0"
|
|||
description = ""
|
||||
authors = ["Aurelien Rebourg <aurelien.rebourg@gmail.com>"]
|
||||
readme = "README.md"
|
||||
packages = [{include = "binance_leaderboard"}]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
|
|
|
|||
Loading…
Reference in New Issue