⚝
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 :
posyaz.py
from binance.um_futures import UMFutures import pymysql from requests.exceptions import ConnectTimeout from binance.exceptions import BinanceAPIException def remove_redis(symbol, side): if side == "LONG": islem.execute( "update symbols set L_positionAmt=0, L_entryPrice=0, L_unRealizedProfit=0, L_roi=0, highroi=0, p_long=0 where symbol=%s", symbol) baglanti.commit() elif side == "SHORT": islem.execute( "update symbols set S_positionAmt=0, S_entryPrice=0, S_unRealizedProfit=0, S_roi=0, deeproi=0, p_short=0 where symbol=%s", symbol) baglanti.commit() def update_redis(pozisyon, side): unrealized_profit = float(pozisyon['unrealizedProfit']) notional = float(pozisyon['notional']) leverage = int(pozisyon['leverage']) roi = round(((unrealized_profit / (notional / leverage)) * 100), 2) if side == 'LONG' else ( round(((unrealized_profit / (notional / leverage)) * 100), 2) * -1) islem.execute("update symbols set leverage=%s where symbol=%s", (pozisyon['leverage'], symbol)) baglanti.commit() if side == "LONG": islem.execute("update symbols set L_positionAmt=%s, L_unRealizedProfit=%s, L_entryPrice=%s, L_roi=%s where symbol=%s", (pozisyon['positionAmt'], str(unrealized_profit), pozisyon['entryPrice'], str(roi), symbol)) baglanti.commit() elif side == "SHORT": islem.execute("update symbols set S_positionAmt=%s, S_unRealizedProfit=%s, S_entryPrice=%s, S_roi=%s where symbol=%s", (pozisyon['positionAmt'], str(unrealized_profit), pozisyon['entryPrice'], str(roi), symbol)) baglanti.commit() def create_futures_client(ayar): return UMFutures(ayar["binanceapikey"], ayar["binancesecretkey"], base_url='https://testnet.binancefuture.com',) try: baglanti = pymysql.connect( host='127.0.0.1', db='newcoin', user='root', password='Ua04420076*', port=3306, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor ) with baglanti.cursor() as islem: try: islem.execute("select * from settings where id=1") ayar = islem.fetchone() baglanti.commit() client = create_futures_client(ayar) while True: try: apositions = client.account() apositions1 = [position for position in apositions['positions'] 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) islem.execute("select * from symbols") liste_redis = islem.fetchall() for value in liste_redis: if value["symbol"] in symbol_positions: if len(symbol_positions[value["symbol"]]["LONG"]) > 0: update_redis( symbol_positions[value["symbol"]]["LONG"][0], "LONG") else: remove_redis(value["symbol"], "LONG") if len(symbol_positions[value["symbol"]]["SHORT"]) > 0: update_redis( symbol_positions[value["symbol"]]["SHORT"][0], "SHORT") else: remove_redis(value["symbol"], "SHORT") else: remove_redis(value["symbol"], "LONG") remove_redis(value["symbol"], "SHORT") except (ConnectTimeout, ConnectionError, TimeoutError, BinanceAPIException) as e: print(f"Hata oluştu: {e}") client = create_futures_client(ayar) except Exception as e: print(f"Bilinmeyen bir hata oluştu: {e}") except Exception as e: print(f"Bilinmeyen bir hata oluştu: {e}") except KeyboardInterrupt: print("Ctrl+C'ye basıldı, program kapatılmayacak.") while True: pass finally: if 'baglanti' in locals(): baglanti.close()