Spaces:
Sleeping
Sleeping
Making interactive
Browse files
app.py
CHANGED
|
@@ -1,31 +1,62 @@
|
|
| 1 |
-
|
| 2 |
import asyncio
|
| 3 |
-
import
|
| 4 |
-
os.environ["USE_MINIMAL_LIBS"] = "true"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
for
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import asyncio
|
| 3 |
+
from triangular_arbitrage import detector
|
|
|
|
| 4 |
|
| 5 |
+
async def run_detection_ui(exchange_name):
|
| 6 |
+
try:
|
| 7 |
+
best_opps, best_profit = await detector.run_detection(
|
| 8 |
+
exchange_name=exchange_name,
|
| 9 |
+
max_cycle=3, # fixed triangular only
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
if not best_opps:
|
| 13 |
+
return "No arbitrage opportunity found."
|
| 14 |
+
|
| 15 |
+
result_lines = []
|
| 16 |
+
for ticker in best_opps:
|
| 17 |
+
result_lines.append(
|
| 18 |
+
f"{ticker.symbol} | price: {ticker.last_price:.8f}"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
result_text = "\n".join(result_lines)
|
| 22 |
+
result_text += f"\n\n**Total cycle profit:** {best_profit:.6f}"
|
| 23 |
+
|
| 24 |
+
return result_text
|
| 25 |
+
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error while scanning: {str(e)}"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
with gr.Blocks(title="Triangular Arbitrage Scanner") as demo:
|
| 31 |
+
gr.Markdown("# Triangular Arbitrage Scanner")
|
| 32 |
+
|
| 33 |
+
exchange = gr.Dropdown(
|
| 34 |
+
choices=[
|
| 35 |
+
"binanceus", # safer default for Spaces
|
| 36 |
+
"kraken",
|
| 37 |
+
"bitget",
|
| 38 |
+
"bybit",
|
| 39 |
+
"okx",
|
| 40 |
+
"coinbase",
|
| 41 |
+
"kucoin",
|
| 42 |
+
"gateio",
|
| 43 |
+
"huobi",
|
| 44 |
+
],
|
| 45 |
+
value="kraken",
|
| 46 |
+
label="Exchange",
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
scan_btn = gr.Button("Scan for opportunities", variant="primary")
|
| 50 |
+
|
| 51 |
+
output = gr.Markdown(
|
| 52 |
+
value="Select exchange and click **Scan**.",
|
| 53 |
+
label="Result"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
scan_btn.click(
|
| 57 |
+
fn=run_detection_ui,
|
| 58 |
+
inputs=exchange,
|
| 59 |
+
outputs=output,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
demo.launch()
|