⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.45
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 :
~
/
proc
/
self
/
root
/
home
/
python
/
yeni
/
Edit File: checksymbol.py
import decimal import math 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 from datetime import datetime, timedelta import subprocess import argparse parser = argparse.ArgumentParser() parser.add_argument("-symbol", help="Sembol Giriniz", required=True) args = parser.parse_args() symbol = args.symbol r = redis.Redis() def update_redis(symbol,data): if r.hexists("symbols", symbol): existing_data = json.loads(r.hget("symbols", symbol)) existing_data.pop("L_roi", None) existing_data.pop("S_roi", None) existing_data.pop("longsay", None) existing_data.pop("shortsay", None) r.hset("symbols", symbol, json.dumps(existing_data)) def basamaksay(number): decimal_part = str(number).rstrip("0").split(".")[1] return len(decimal_part) if decimal_part else 0 def limit_al(client,symbol,sayi,yon): while (sayi <= 6): if r.hexists("symbols", symbol): data = json.loads(r.hget("symbols", symbol)) if "longsay" not in data and yon=="LONG": data['longsay']=1 if "shortsay" not in data and yon=="SHORT": data['shortsay']=1 kacinci=float(data['longsay']) if yon=="LONG" else float(data['shortsay']) price=float(data['L_entryPrice']) if yon=="LONG" else float(data['S_entryPrice']) aralik=float(data['aralikyuzde'])*kacinci kaldirac =float(data['leverage']) decimal_part = abs(decimal.Decimal(str(data['qp'])).as_tuple().exponent) quantity = "{:.{}f}".format(math.ceil((float(data['aralikmargin']) * kaldirac) / price), decimal_part) stop_loss_price = (price * (1+(aralik/kaldirac/100))) if yon=="LONG" else (price * (1-(aralik/kaldirac/100))) hedefprice ="{:0.0{}f}".format(stop_loss_price, basamaksay(data['price'])) open_long = client.futures_create_order( symbol=symbol, side=Client.SIDE_BUY if yon=="LONG" else Client.SIDE_SELL, positionSide="LONG" if yon=="LONG" else "SHORT", quantity=quantity, timeInForce = Client.TIME_IN_FORCE_GTC, type=Client.FUTURE_ORDER_TYPE_STOP, price = hedefprice, stopPrice = hedefprice ) if open_long: kacinci += 1 if yon=="LONG": data['longsay']=kacinci elif yon=="SHORT": data['shortsay']=kacinci r.hset("symbols", symbol, json.dumps(data)) sayi += 1 def tpkontrol(symbol): script_path = "tpkontrol.py" process_name = f"python3.11 {script_path} -symbol {symbol}" process_exists = subprocess.run(["pgrep", "-f", process_name], capture_output=True, text=True).returncode == 0 if not process_exists: try: subprocess.Popen(["python3.11", script_path, "-symbol", symbol]) #print(f"{process_name} sembolüyle çalışan süreç başlatıldı.") except subprocess.CalledProcessError as e: print(f"Hata: {e}") return def eksikapat(um_futures_client,client,symbol,data): order_long = client.futures_create_order( symbol=symbol, side="SELL" if float(data['S_unRealizedProfit']) >= 0 else "BUY", positionSide="LONG" if float(data['S_unRealizedProfit']) >= 0 else "SHORT", quantity=float(data['L_positionAmt']) if float(data['S_unRealizedProfit']) >= 0 else float(data['S_positionAmt'])*-1, type=Client.ORDER_TYPE_MARKET ) um_futures_client.cancel_open_orders(symbol=symbol) if r.hexists("symbols", symbol): existing_data = json.loads(r.hget("symbols", symbol)) existing_data.pop("longsay", None) existing_data.pop("shortsay", None) r.hset("symbols", symbol, json.dumps(existing_data)) return def yuvarla(fiyat,basamak): decimal_part = abs(decimal.Decimal(str(basamak)).as_tuple().exponent) return "{:.{}f}".format(math.ceil(fiyat), decimal_part) def pozisyon_ac(client,symbol,data): update_redis(symbol,data) kaldirac =float(data['leverage']) quantity = yuvarla((((float(data['margin']) * kaldirac ) / float(data['price']))),int(data['qp'])) order_long = client.futures_create_order( symbol=symbol, side="BUY", positionSide="LONG", quantity=quantity, type=Client.ORDER_TYPE_MARKET ) order_short = client.futures_create_order( symbol=symbol, side="SELL", positionSide="SHORT", quantity=quantity, type=Client.ORDER_TYPE_MARKET ) time.sleep(1) 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")) 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() client = create_futures_client() try: while True: resp = um_futures_client.get_position_risk(symbol=symbol) long_posizyon = list(filter(lambda order: float(order['positionAmt']) != 0 and order["positionSide"] == "LONG", resp)) sort_posizyon = list(filter(lambda order: float(order['positionAmt']) != 0 and order["positionSide"] == "SHORT", resp)) try: data = r.hget("symbols",symbol) if data: data = json.loads(data.decode("utf-8")) if data['isActive']==1: if data['isFollow']==1: if not long_posizyon and not sort_posizyon: closedDateTime=datetime.strptime(str(data['closedDateTime']), '%Y-%m-%dT%H:%M:%S') fark=datetime.now() - closedDateTime if fark >= timedelta(seconds=float(data['waitTime'])) : pozisyon_ac(client,symbol,data) if long_posizyon and sort_posizyon: if float(long_posizyon[0]['unRealizedProfit'])+float(sort_posizyon[0]['unRealizedProfit']) >= float(data['hedef']) + (float(long_posizyon[0]['positionAmt'])*(float(data['tp'])/100)): eksikapat(um_futures_client,client,symbol,data) continue else: acikemirler = client.futures_get_open_orders(symbol=symbol) long_orders = list(filter(lambda order: order["positionSide"] == "LONG" , acikemirler)) short_orders = list(filter(lambda order: order["positionSide"] == "SHORT", acikemirler)) print("long: ",len(long_orders)," short: ",len(short_orders)) if len(long_orders)<5: limit_al(client,symbol,len(long_orders),"LONG") if len(short_orders)<5: limit_al(client,symbol,len(short_orders),"SHORT") elif (long_posizyon and not sort_posizyon) or (not long_posizyon and sort_posizyon): tpkontrol(symbol) except (ConnectTimeout, ConnectionError, TimeoutError, BinanceAPIException) as e: print(f"Hata oluştu: {e}") client = create_futures_client() 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