⚝
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
/
erol
/
View File Name :
t3.py
import time import json from binance.client import Client 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) existing_data.pop("L_entryPrice", None) existing_data.pop("L_markPrice", None) existing_data.pop("L_unRealizedProfit", None) elif side=="SHORT": existing_data.pop("S_positionAmt", None) existing_data.pop("S_entryPrice", None) existing_data.pop("S_markPrice", None) existing_data.pop("S_unRealizedProfit", None) r.hset("symbols", symbol, json.dumps(existing_data)) def update_redis(pozisyon, side): data = r.hget("symbols", pozisyon["symbol"]) if data: data = json.loads(data) if side == "LONG": data["L_positionAmt"] = pozisyon['positionAmt'] data["L_entryPrice"] = pozisyon['entryPrice'] data["L_markPrice"] = pozisyon['markPrice'] data["L_unRealizedProfit"] = pozisyon['unRealizedProfit'] elif side == "SHORT": data["S_positionAmt"] = pozisyon['positionAmt'] data["S_entryPrice"] = pozisyon['entryPrice'] data["S_markPrice"] = pozisyon['markPrice'] data["S_unRealizedProfit"] = pozisyon['unRealizedProfit'] else: if side == "LONG": data = { "L_positionAmt": pozisyon['positionAmt'], "L_entryPrice": pozisyon['entryPrice'], "L_markPrice": pozisyon['markPrice'], "L_unRealizedProfit": pozisyon['unRealizedProfit'], } elif side == "SHORT": data = { "S_positionAmt": pozisyon['positionAmt'], "S_entryPrice": pozisyon['entryPrice'], "S_markPrice": pozisyon['markPrice'], "S_unRealizedProfit": pozisyon['unRealizedProfit'], } r.hset("symbols", pozisyon["symbol"], json.dumps(data)) def add_price(symbol, pozisyon): data = {} if pozisyon['positionSide'] == 'LONG': data["L_positionAmt"] = pozisyon['positionAmt'] data["L_entryPrice"] = pozisyon['entryPrice'] data["L_markPrice"] = pozisyon['markPrice'] data["L_unRealizedProfit"] = pozisyon['unRealizedProfit'] elif pozisyon['positionSide'] == 'SHORT': data["S_positionAmt"] = pozisyon['positionAmt'] data["S_entryPrice"] = pozisyon['entryPrice'] data["S_markPrice"] = pozisyon['markPrice'] data["S_unRealizedProfit"] = pozisyon['unRealizedProfit'] update_redis(symbol, data) def create_futures_client(): if r.hexists("ayarlar", "binanceapikey") and r.hexists("ayarlar", "binancesecretkey"): return Client(r.hget("ayarlar", "binanceapikey").decode("utf-8"), r.hget("ayarlar", "binancesecretkey").decode("utf-8")) client = create_futures_client() try: while True: try: apositions = client.futures_position_information() apositions1 = [position for position in apositions if (float(position['positionAmt']) > 0) or (float(position['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: 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") # for p2 in position2: # add_price(symbol, p2) #else: # for symbol in r.hkeys("symbols"): # update_redis(symbol.decode("utf-8"), {}) except (ConnectTimeout, ConnectionError, TimeoutError, BinanceAPIException) as e: print(f"Hata oluştu: {e}") client = create_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()