Askhat777 commited on
Commit
f2a876a
·
verified ·
1 Parent(s): c729a87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -130,13 +130,23 @@ def get_bot_state() -> BotState:
130
  # ─────────────────────────────────────────────
131
  # РАБОТА С БИРЖЕЙ
132
  # ─────────────────────────────────────────────
133
- def build_exchange(api_key: str, api_secret: str) -> ccxt.binance:
134
- exchange = ccxt.binance({
135
  "apiKey": api_key,
136
  "secret": api_secret,
137
  "options": {"defaultType": "spot"},
138
  "enableRateLimit": True,
139
- })
 
 
 
 
 
 
 
 
 
 
140
  return exchange
141
 
142
 
@@ -441,9 +451,9 @@ def trading_loop(state: BotState):
441
 
442
  try:
443
  if state.paper_trading:
444
- exchange = build_exchange("", "")
445
  else:
446
- exchange = build_exchange(state.api_key, state.api_secret)
447
  exchange.load_markets()
448
  state.log("Биржа подключена", "OK")
449
 
@@ -791,9 +801,9 @@ def render_ui():
791
  if st.button(f"🚨 Panic Sell слот {slot.index}", key=f"panic_{slot.index}"):
792
  try:
793
  if state.paper_trading:
794
- exchange = build_exchange("", "")
795
  else:
796
- exchange = build_exchange(state.api_key, state.api_secret)
797
  panic_sell_slot(exchange, slot, state, manual=True)
798
  st.warning(f"Слот {slot.index} закрыт принудительно!")
799
  st.rerun()
 
130
  # ─────────────────────────────────────────────
131
  # РАБОТА С БИРЖЕЙ
132
  # ─────────────────────────────────────────────
133
+ def build_exchange(api_key: str, api_secret: str, paper_trading: bool = False) -> ccxt.binance:
134
+ config = {
135
  "apiKey": api_key,
136
  "secret": api_secret,
137
  "options": {"defaultType": "spot"},
138
  "enableRateLimit": True,
139
+ }
140
+ if paper_trading:
141
+ # Для бесплатного симулятора на серверах в США (Hugging Face)
142
+ # перенаправляем запросы на официальный незаблокированный шлюз рыночных данных Binance
143
+ config["urls"] = {
144
+ "api": {
145
+ "public": "https://data-api.binance.vision/api/v3",
146
+ "private": "https://data-api.binance.vision/api/v3"
147
+ }
148
+ }
149
+ exchange = ccxt.binance(config)
150
  return exchange
151
 
152
 
 
451
 
452
  try:
453
  if state.paper_trading:
454
+ exchange = build_exchange("", "", paper_trading=True)
455
  else:
456
+ exchange = build_exchange(state.api_key, state.api_secret, paper_trading=False)
457
  exchange.load_markets()
458
  state.log("Биржа подключена", "OK")
459
 
 
801
  if st.button(f"🚨 Panic Sell слот {slot.index}", key=f"panic_{slot.index}"):
802
  try:
803
  if state.paper_trading:
804
+ exchange = build_exchange("", "", paper_trading=True)
805
  else:
806
+ exchange = build_exchange(state.api_key, state.api_secret, paper_trading=False)
807
  panic_sell_slot(exchange, slot, state, manual=True)
808
  st.warning(f"Слот {slot.index} закрыт принудительно!")
809
  st.rerun()