⚝
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 :
~
/
proc
/
thread-self
/
root
/
home
/
python
/
View File Name :
coin.py
import time import argparse import pymysql import math import decimal from binance.client import Client from binance.enums import * from requests.exceptions import ConnectTimeout parser = argparse.ArgumentParser() parser.add_argument("-symbol", help="Sembol Giriniz") args = parser.parse_args() symbol=args.symbol def pozisyonkapat(client,position,ters): try: p_side='SELL' if position['positionSide']=='LONG' else 'BUY' client.futures_create_order( symbol=position['symbol'], side=p_side, positionSide=position['positionSide'], quantity=float(position['positionAmt']) if position['positionSide']=='LONG' else float(position['positionAmt'])*-1, type=ORDER_TYPE_MARKET, ) if ters == False: if position['positionSide']=='LONG': islem.execute('update `coinlist` set `highroi`=0 where `symbol`=%s',(position['symbol'])) baglanti.commit() elif position['positionSide']=='SHORT': islem.execute('update `coinlist` set `deeproi`=0 where `symbol`=%s',(position['symbol'])) baglanti.commit() return except ConnectTimeout: print("Bağlantı zaman aşımı hatası. Yeniden deneyin.") return def pozisyon_ac(ayar, client, symbol, yon, ters): try: positionSide=yon islem.execute('Select * From `coinlist` where `isActive`=1 and `symbol`=%s', (symbol)) dbcoin = islem.fetchone() baglanti.commit() if dbcoin is not None: position_side = 'BUY' if yon == 'LONG' else 'SELL' exchange_info = client.futures_exchange_info() symbol_info = next(filter(lambda x: x['symbol'] == symbol, exchange_info['symbols']), None) miktar=float(ayar['tersmargine']) if ters==True else float(ayar['margine']) decimal_part = abs(decimal.Decimal(str(symbol_info['quantityPrecision'])).as_tuple().exponent) entry_price = float(client.get_symbol_ticker(symbol=symbol)['price']) quantity = "{:.{}f}".format(math.ceil((float(miktar) * 20) / entry_price), decimal_part) order = client.futures_create_order( symbol=symbol, side=position_side, positionSide=positionSide, quantity=quantity, type=ORDER_TYPE_MARKET ) return except ConnectTimeout: print("Bağlantı zaman aşımı hatası. Yeniden deneyin.") return def coklupozisyonkontrol(ayar, client, positions,dbcoin): try: yon='LONG' if dbcoin['side']=='SHORT' else 'SHORT' target_position = next((position for position in positions if (position['symbol'] == symbol and position['positionSide'] == yon)), None) current_position = next((position for position in positions if (position['symbol'] == symbol and position['positionSide'] == dbcoin['side'])), None) c_unrealized_profit = float(current_position['unRealizedProfit']) c_notional = float(current_position['notional']) c_leverage = int(current_position['leverage']) c_roi = (c_unrealized_profit / (c_notional / c_leverage)) * 100 current_position_roi = round(c_roi, 2) if current_position['positionSide']=='LONG' else round(c_roi, 2)*-1 t_unrealized_profit = float(target_position['unRealizedProfit']) t_notional = float(target_position['notional']) t_leverage = int(target_position['leverage']) t_roi = (t_unrealized_profit / (t_notional / t_leverage)) * 100 target_position_roi = round(t_roi, 2) if target_position['positionSide']=='LONG' else round(t_roi, 2)*-1 print(symbol," ana:",current_position['positionSide'], " ",current_position_roi,"--ters:",target_position['positionSide']," ",target_position_roi) if current_position['positionSide']=='LONG': if current_position_roi > float(dbcoin['highroi']): islem.execute('UPDATE `coinlist` set `highroi`=%s where `symbol`=%s',(current_position_roi,current_position['symbol'])) baglanti.commit() elif current_position['positionSide']=='SHORT': if current_position_roi > float(dbcoin['deeproi']): islem.execute('UPDATE `coinlist` set `deeproi`=%s where `symbol`=%s',(current_position_roi,current_position['symbol'])) baglanti.commit() if current_position_roi > float(ayar['terslimit']): print(symbol," ters kapat-", current_position_roi) pozisyonkapat(client,target_position,True) return if target_position_roi >= float(ayar['analimit']): print(symbol," ana kapat-", target_position_roi) pozisyonkapat(client,current_position,True) yeniyon='SHORT' if current_position['positionSide']=='LONG' else 'LONG' islem.execute('update `coinlist` set `side`=%s where `symbol`=%s',(yeniyon,symbol)) baglanti.commit() return except ConnectTimeout: print("Bağlantı zaman aşımı hatası. Yeniden deneyin.") return def tekroikontrol(ayar, client, current_position,dbcoin): try: c_unrealized_profit = float(current_position['unRealizedProfit']) c_notional = float(current_position['notional']) c_leverage = int(current_position['leverage']) c_roi = (c_unrealized_profit / (c_notional / c_leverage)) * 100 current_position_roi = round(c_roi, 2) if current_position['positionSide']=='LONG' else round(c_roi, 2)*-1 if current_position['positionSide']=='LONG': if current_position_roi > float(dbcoin['highroi']): islem.execute('UPDATE `coinlist` set `highroi`=%s where `id`=%s',(current_position_roi,dbcoin['id'])) baglanti.commit() high_roi=current_position_roi else: high_roi=float(dbcoin['highroi']) target_roi=high_roi - float(ayar['tp']) elif current_position['positionSide']=='SHORT': if current_position_roi > float(dbcoin['deeproi']): islem.execute('UPDATE `coinlist` set `deeproi`=%s where `id`=%s',(current_position_roi,dbcoin['id'])) baglanti.commit() deep_roi=current_position_roi else: deep_roi=float(dbcoin['deeproi']) target_roi=deep_roi - float(ayar['tp']) yon='LONG' if current_position['positionSide']=='SHORT' else 'SHORT' if current_position_roi <= target_roi and current_position_roi >=int(ayar['hedef']): pozisyonkapat(client,current_position,False) pozisyon_ac(ayar,client,symbol,yon,False) if current_position_roi <= float(ayar['terslimit']): pozisyon_ac(ayar,client,symbol,yon,True) return except ConnectTimeout: print("Bağlantı zaman aşımı hatası. Yeniden deneyin.") return def islemler(ayar): while True: client = Client(ayar['binanceapikey'], ayar['binancesecretkey']) islem.execute('Select * From `coinlist` where `isActive`=1 and `symbol`=%s', (symbol, )) dbcoin = islem.fetchone() baglanti.commit() apositions = client.futures_position_information() positions = [position for position in apositions if (float(position['positionAmt']) > 0 and position['positionSide'] == 'LONG' and position['symbol'] == symbol) or (float(position['positionAmt']) < 0 and position['positionSide'] == 'SHORT') and position['symbol'] == symbol] if len(positions) == 2: coklupozisyonkontrol(ayar,client,positions,dbcoin) elif len(positions) == 1: tekroikontrol(ayar, client, positions[0],dbcoin) else: pozisyon_ac(ayar, client, symbol, dbcoin['side'], False) client.close_connection() time.sleep(1) try: baglanti = pymysql.connect( host='127.0.0.1', db='coinbot', user='root', password='Ua04420076*', port=3306, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor ) with baglanti.cursor() as islem: islem.execute('SELECT * from `settings` where `id`=1') ayar=islem.fetchone() baglanti.commit() islemler(ayar) finally: # Veritabanı bağlantısını kapat if 'baglanti' in locals(): baglanti.close() # Programı sonlandır #sys.exit()