⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.1
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
python
/
yeni
/
Edit File: posyaz.py
import time import json from binance.client import Client from binance.um_futures import UMFutures from requests.exceptions import ConnectTimeout from binance.exceptions import BinanceAPIException import redis r = redis.Redis() def remove_redis(symbol,side): if r.hexists("symbols", symbol): existing_data = json.loads(r.hget("symbols", symbol)) if side=="LONG": existing_data.pop("L_positionAmt", None) if "L_entryPrice" in existing_data: existing_data.pop("L_entryPrice", None) if "L_unRealizedProfit" in existing_data: existing_data.pop("L_unRealizedProfit", None) if "L_roi" in existing_data: existing_data.pop("L_roi", None) if "highroi" in existing_data: existing_data.pop("highroi", None) elif side=="SHORT": if "S_positionAmt" in existing_data: existing_data.pop("S_positionAmt", None) if "S_entryPrice" in existing_data: existing_data.pop("S_entryPrice", None) if "S_unRealizedProfit" in existing_data: existing_data.pop("S_unRealizedProfit", None) if "S_roi" in existing_data: existing_data.pop("S_roi", None) if "deeproi" in existing_data: existing_data.pop("deeproi", None) r.hset("symbols", symbol, json.dumps(existing_data)) def update_redis(pozisyon, side): unrealized_profit = float(pozisyon['unrealizedProfit']) notional = float(pozisyon['notional']) leverage = int(pozisyon['leverage']) roi = (unrealized_profit / (notional / leverage)) * 100 data = r.hget("symbols", pozisyon["symbol"]) if data: data = json.loads(data) data['leverage'] = pozisyon['leverage'] if side == "LONG": data["L_positionAmt"] = pozisyon['positionAmt'] data["L_unRealizedProfit"] = pozisyon['unrealizedProfit'] data["L_entryPrice"] = pozisyon['entryPrice'] data["L_roi"] = round(roi, 2) elif side == "SHORT": data["S_positionAmt"] = pozisyon['positionAmt'] data["S_unRealizedProfit"] = pozisyon['unrealizedProfit'] data["S_entryPrice"] = pozisyon['entryPrice'] data["S_roi"] = round(roi, 2)*-1 else: if side == "LONG": data = { "L_positionAmt": pozisyon['positionAmt'], "L_unRealizedProfit": pozisyon['unrealizedProfit'], "L_entryPrice": pozisyon['entryPrice'], "L_roi": round(roi, 2), } elif side == "SHORT": data = { "S_positionAmt": pozisyon['positionAmt'], "S_unRealizedProfit":pozisyon['unrealizedProfit'], "S_entryPrice": pozisyon['entryPrice'], "S_roi": round(roi, 2)*-1, } data['leverage'] = pozisyon['leverage'] r.hset("symbols", pozisyon["symbol"], json.dumps(data)) def ceretae_um_futures_client(): if r.hexists("ayarlar", "binanceapikey") and r.hexists("ayarlar", "binancesecretkey"): return UMFutures(r.hget("ayarlar", "binanceapikey").decode("utf-8"), r.hget("ayarlar", "binancesecretkey").decode("utf-8")) um_futures_client = ceretae_um_futures_client() try: while True: try: positions = um_futures_client.account()["positions"] apositions1 = [p for p in positions if float(p['positionAmt']) != 0 ] #short_positions = [p for p in positions if p['positionSide'] == "SHORT" and float(p['positionAmt']) != 0 ] symbol_positions = {} for position1 in apositions1: symbol = position1["symbol"] if symbol not in symbol_positions: symbol_positions[symbol] = {"LONG": [], "SHORT": []} if position1['positionSide']=="LONG": symbol_positions[symbol]["LONG"].append(position1) elif position1['positionSide']=="SHORT": symbol_positions[symbol]["SHORT"].append(position1) liste_redis = r.hgetall("symbols") for key, value in liste_redis.items(): symbol = key.decode("utf-8") # Anahtarın byte dizisini çözümle data = json.loads(value.decode("utf-8")) # Değeri byte dizisini çözümle ve JSON'a dönüştür if symbol in symbol_positions: #current roi hesapla redise yaz if len(symbol_positions[symbol]["LONG"])>0: update_redis(symbol_positions[symbol]["LONG"][0], "LONG") else: remove_redis(symbol, "LONG") if len(symbol_positions[symbol]["SHORT"])>0: update_redis(symbol_positions[symbol]["SHORT"][0], "SHORT") else: remove_redis(symbol, "SHORT") else: remove_redis(symbol,"LONG") remove_redis(symbol,"SHORT") except (ConnectTimeout, ConnectionError, TimeoutError, BinanceAPIException) as e: print(f"Hata oluştu: {e}") um_futures_client = ceretae_um_futures_client() except Exception as e: print(f"Bilinmeyen bir hata oluştu: {e}") time.sleep(1) except KeyboardInterrupt: print("Program kapatıldı.") finally: r.close()
Simpan