/
fgtmenow
/
tb
Обзор
Документация
Войти
/
fgtmenow
/
tb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
_common/api/GetInstrumentsInfo.py
54 строки
2 KB
artemazarev
move config to bot
30 мар 2025, 03:48
30 мар 2025, 03:48
aa3c5ae
Код
Авторство
О чём код?
import json import os from pybit.unified_trading import HTTP from _common.api.GetMaintenanceMargin import get_maintenance_margin from _common.domain.model.Instrument import Instrument from _common.domain.model.TickerInfo import TickerInfo from _common.domain.util.CacheUtil import get_cache_file_path from _common.domain.util.Logger import print_message from _common.domain.util.SymbolUtils import is_valid_symbol def get_instruments_info( session: HTTP, target:list[str], trace: bool, tickers: dict[str, TickerInfo] ) -> dict[str, Instrument]: result: dict[str, Instrument] = {} cache_file_name = get_cache_file_path( filename="all", directory="instruments", ext="json" ) if os.path.exists(cache_file_name): response = json.load(open(os.path.join(os.getcwd(), cache_file_name))) else: response = session.get_instruments_info( category="linear", limit=1000 ) json.dump(response, open(os.path.join(os.getcwd(), cache_file_name), 'w')) if trace: print_message(response) for info in response["result"]["list"]: symbol = info["symbol"] if tickers.__contains__(symbol): if not is_valid_symbol(target, symbol): continue mm = get_maintenance_margin(session, trace, symbol) result[symbol] = Instrument( info["contractType"], info["status"], mm, float(info["leverageFilter"]["minLeverage"]), float(info["leverageFilter"]["maxLeverage"]), float(info["lotSizeFilter"]["minOrderQty"]), float(info["lotSizeFilter"]["maxOrderQty"]), float(info["lotSizeFilter"]["qtyStep"]), tickers[symbol] ) return result