/
fgtmenow
/
tb
Обзор
Документация
Войти
/
fgtmenow
/
tb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
_common/api/GetTickets.py
49 строк
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.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_tickets(session: HTTP, target: list[str], trace: bool) -> dict[str, TickerInfo]: result: dict[str, TickerInfo] = {} cache_file_name = get_cache_file_path( filename="all", directory="tickets", 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_tickers( category="linear", ) json.dump(response, open(os.path.join(os.getcwd(), cache_file_name), 'w')) if trace: print_message(message=response) for d in response["result"]["list"]: symbol = str(d["symbol"]) if not is_valid_symbol(target, symbol): continue fundingRateStr = d['fundingRate'] if fundingRateStr == '': continue result[symbol] = TickerInfo( float(d['lastPrice']), float(d['prevPrice24h']), float(d['price24hPcnt']), float(d['highPrice24h']), float(d['lowPrice24h']), float(d['prevPrice1h']), float(d['openInterest']), float(d['turnover24h']), float(d['volume24h']), float(fundingRateStr), float(d['ask1Size']), float(d['bid1Size']), ) return result