lykia0 commited on
Commit
f4953e9
·
verified ·
1 Parent(s): c29b89b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -67
app.py CHANGED
@@ -2,7 +2,7 @@ import requests
2
  import random
3
  import streamlit as st
4
 
5
- # Proxy listesi (SOCKS5)
6
  proxy_list = [
7
  '185.46.97.75:1080', # 20 ms, Rusya
8
  '89.104.71.70:1080', # 40 ms, Rusya
@@ -12,8 +12,18 @@ proxy_list = [
12
  ]
13
 
14
  def get_proxy():
15
- proxy = random.choice(proxy_list)
16
- return {'http': f'socks5h://{proxy}', 'https': f'socks5h://{proxy}'}
 
 
 
 
 
 
 
 
 
 
17
 
18
  def get_binance_price(symbol):
19
  try:
@@ -22,11 +32,13 @@ def get_binance_price(symbol):
22
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
23
  }
24
  proxies = get_proxy()
25
- response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
 
 
26
  response.raise_for_status()
27
  order_book = response.json()
28
- best_bid_price = float(order_book['bids'][0][0]) # En iyi alış fiyatı
29
- best_ask_price = float(order_book['asks'][0][0]) # En iyi satış fiyatı
30
  return best_bid_price, best_ask_price
31
  except Exception as e:
32
  st.error(f"Binance fiyat çekme hatası ({symbol}): {e}")
@@ -39,59 +51,17 @@ def get_okx_price(symbol):
39
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
40
  }
41
  proxies = get_proxy()
42
- response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
 
 
43
  response.raise_for_status()
44
  order_book = response.json()['data'][0]
45
- best_bid_price = float(order_book['bids'][0][0]) # En iyi alış fiyatı
46
  return best_bid_price
47
  except Exception as e:
48
  st.error(f"OKX fiyat çekme hatası ({symbol}): {e}")
49
  return None
50
 
51
- def calculate_profit_from_okx_to_binance(okx_usdt_try, binance_fdusd_try_ask, binance_fdusd_usdt_bid, user_try_amount):
52
- try:
53
- if okx_usdt_try and binance_fdusd_try_ask and binance_fdusd_usdt_bid:
54
- usdt_from_try = user_try_amount // okx_usdt_try
55
- fdusd_from_usdt = usdt_from_try // binance_fdusd_usdt_bid
56
- try_from_fdusd = fdusd_from_usdt * binance_fdusd_try_ask
57
-
58
- profit_from_user_try = try_from_fdusd - user_try_amount
59
- profit_ratio = (profit_from_user_try / user_try_amount) * 100
60
-
61
- st.write(f"OKX'te {user_try_amount} TRY ile {usdt_from_try} USDT alındı.")
62
- st.write(f"Binance'de {usdt_from_try} USDT ile {fdusd_from_usdt} FDUSD alındı.")
63
- st.write(f"Binance'de {fdusd_from_usdt} FDUSD ile {try_from_fdusd:.2f} TRY elde edildi.")
64
-
65
- return profit_ratio, profit_from_user_try, "OKX -> Binance"
66
- else:
67
- st.error("Eksik fiyat bilgisi nedeniyle kar hesaplanamadı.")
68
- return None, None, None
69
- except Exception as e:
70
- st.error(f"Kar hesaplama hatası: {e}")
71
- return None, None, None
72
-
73
- def calculate_profit_from_binance_to_okx(binance_fdusd_try_bid, binance_fdusd_usdt_bid, okx_usdt_try, user_try_amount):
74
- try:
75
- if binance_fdusd_try_bid and binance_fdusd_usdt_bid and okx_usdt_try:
76
- fdusd_from_try = user_try_amount // binance_fdusd_try_bid
77
- usdt_from_fdusd = fdusd_from_try * binance_fdusd_usdt_bid
78
- try_from_usdt = usdt_from_fdusd * okx_usdt_try
79
-
80
- profit_from_user_try = try_from_usdt - user_try_amount
81
- profit_ratio = (profit_from_user_try / user_try_amount) * 100
82
-
83
- st.write(f"Binance'de {user_try_amount} TRY ile {fdusd_from_try} FDUSD alındı.")
84
- st.write(f"Binance'de {fdusd_from_try} FDUSD ile {usdt_from_fdusd} USDT elde edildi.")
85
- st.write(f"OKX'te {usdt_from_fdusd} USDT ile {try_from_usdt:.2f} TRY alındı.")
86
-
87
- return profit_ratio, profit_from_user_try, "Binance -> OKX"
88
- else:
89
- st.error("Eksik fiyat bilgisi nedeniyle kar hesaplanadmadı.")
90
- return None, None, None
91
- except Exception as e:
92
- st.error(f"Kar hesaplama hatası: {e}")
93
- return None, None, None
94
-
95
  st.title("OKX ve Binance Arbitraj Fırsatları")
96
  user_try_amount = st.number_input("İşlem yapmak istediğiniz TRY miktarını girin:", min_value=1, step=1)
97
 
@@ -102,18 +72,7 @@ if st.button("Hesapla"):
102
  binance_fdusd_usdt_bid, _ = get_binance_price("FDUSDUSDT")
103
  okx_usdt_try = get_okx_price("USDT-TRY")
104
 
105
- profit_ratio_okx_to_binance, profit_from_user_try_okx_to_binance, route_okx_to_binance = calculate_profit_from_okx_to_binance(
106
- okx_usdt_try, binance_fdusd_try_ask, binance_fdusd_usdt_bid, user_try_amount)
107
-
108
- profit_ratio_binance_to_okx, profit_from_user_try_binance_to_okx, route_binance_to_okx = calculate_profit_from_binance_to_okx(
109
- binance_fdusd_try_bid, binance_fdusd_usdt_bid, okx_usdt_try, user_try_amount)
110
-
111
- if profit_ratio_okx_to_binance is not None:
112
- st.success(f"{route_okx_to_binance}: Tahmini Kar Oranı: {profit_ratio_okx_to_binance:.2f}%")
113
- st.success(
114
- f"{user_try_amount} TRY ile işlem yapıldığında tahmini kar: {profit_from_user_try_okx_to_binance:.2f} TRY")
115
-
116
- if profit_ratio_binance_to_okx is not None:
117
- st.success(f"{route_binance_to_okx}: Tahmini Kar Oranı: {profit_ratio_binance_to_okx:.2f}%")
118
- st.success(
119
- f"{user_try_amount} TRY ile işlem yapıldığında tahmini kar: {profit_from_user_try_binance_to_okx:.2f} TRY")
 
2
  import random
3
  import streamlit as st
4
 
5
+ # Proxy listesi (SOCKS5) - En hızlı proxy'leri ekledik
6
  proxy_list = [
7
  '185.46.97.75:1080', # 20 ms, Rusya
8
  '89.104.71.70:1080', # 40 ms, Rusya
 
12
  ]
13
 
14
  def get_proxy():
15
+ """Rastgele çalışan bir proxy döndür."""
16
+ for _ in range(len(proxy_list)):
17
+ proxy = random.choice(proxy_list)
18
+ try:
19
+ response = requests.get('https://httpbin.org/ip', proxies={'http': f'socks5h://{proxy}', 'https': f'socks5h://{proxy}'}, timeout=10)
20
+ if response.status_code == 200:
21
+ st.write(f"Proxy bağlantısı başarılı: {proxy}")
22
+ return {'http': f'socks5h://{proxy}', 'https': f'socks5h://{proxy}'}
23
+ except Exception as e:
24
+ st.error(f"Proxy çalışmıyor: {proxy} Hata: {e}")
25
+ st.error("Uygun bir proxy bulunamadı. Proxy listesini kontrol edin.")
26
+ return None
27
 
28
  def get_binance_price(symbol):
29
  try:
 
32
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
33
  }
34
  proxies = get_proxy()
35
+ if not proxies:
36
+ return None, None
37
+ response = requests.get(url, headers=headers, proxies=proxies, timeout=30)
38
  response.raise_for_status()
39
  order_book = response.json()
40
+ best_bid_price = float(order_book['bids'][0][0])
41
+ best_ask_price = float(order_book['asks'][0][0])
42
  return best_bid_price, best_ask_price
43
  except Exception as e:
44
  st.error(f"Binance fiyat çekme hatası ({symbol}): {e}")
 
51
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
52
  }
53
  proxies = get_proxy()
54
+ if not proxies:
55
+ return None
56
+ response = requests.get(url, headers=headers, proxies=proxies, timeout=30)
57
  response.raise_for_status()
58
  order_book = response.json()['data'][0]
59
+ best_bid_price = float(order_book['bids'][0][0])
60
  return best_bid_price
61
  except Exception as e:
62
  st.error(f"OKX fiyat çekme hatası ({symbol}): {e}")
63
  return None
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  st.title("OKX ve Binance Arbitraj Fırsatları")
66
  user_try_amount = st.number_input("İşlem yapmak istediğiniz TRY miktarını girin:", min_value=1, step=1)
67
 
 
72
  binance_fdusd_usdt_bid, _ = get_binance_price("FDUSDUSDT")
73
  okx_usdt_try = get_okx_price("USDT-TRY")
74
 
75
+ if binance_fdusd_try_bid and binance_fdusd_try_ask and binance_fdusd_usdt_bid and okx_usdt_try:
76
+ st.success("Fiyatlar başarıyla çekildi!")
77
+ else:
78
+ st.error("Bazı fiyatlar alınamadı, lütfen daha sonra tekrar deneyin.")