Fix WebSocket hang and add EGX sector-based stock grouping#1
Conversation
|
@copilot but my request was make more effecient approach but sectoring the stocks grouping them and get the related group. also add a feature in the EGX tap where users can open a list of sectors and pick a sector to view all its stocks |
Done. Here's what was added:
Three new methods on # List all EGX sectors
sectors = fetcher.list_sectors('EGX')
# Get the stocks in a sector
banking_stocks = fetcher.get_sector_stocks("Banking", "EGX")
# → ['COMI', 'EGAL', 'ADIB', ...]
# Fetch OHLCV data for an entire sector in one call
df = fetcher.get_sector(
"Banking", "EGX", "Daily",
start=date(2024, 1, 1),
end=date(2024, 12, 31),
)
The standalone helpers Commit: |
Changes
WebSocket timeout fix
The
get_histwhile Truereceive loop had no timeout on the underlying WebSocket connection, causing the process to hang forever if TradingView stopped sending data without closing the connection (network stall, invalid symbol, etc.)._vendor/main.py: Addedtimeout=60parameter toTvDatafeed.__init__; passed astimeout=self.timeouttocreate_connection(), sows.recv()raisesWebSocketTimeoutExceptioninstead of blocking indefinitelycore.py: All fourTvDatafeedLive(...)call sites now passtimeout=self.config.connection_timeout, wiringFetcherConfig.connection_timeout(default: 60s) down to the socket layerEGX sector grouping & browsing
Stocks can now be grouped by sector and fetched as a unit. Sector data is built in for the Egyptian Exchange (EGX).
tradeglob/markets/egx.py: 15 EGX sectors with correctly classified stock tickers (Banking, Real Estate & Housing, Telecommunications, Food & Beverages, Construction & Building Materials, Healthcare & Pharmaceuticals, Petroleum & Energy, Financial Services & Investment, Insurance, Tourism & Hotels, Industrial & Manufacturing, Transportation & Logistics, Chemicals & Petrochemicals, Textile & Garments, Technology). Standalone helperslist_egx_sectors()andget_egx_sector_stocks()are provided.tradeglob/markets/__init__.py: Newmarketspackage.core.py: Three new methods onTradeGlobFetcher:list_sectors(exchange)— list available sectors for an exchangeget_sector_stocks(sector, exchange)— return the ticker list for a sectorget_sector(sector, exchange, interval, start, end, ...)— fetch OHLCV data for every stock in a sector in one call, reusing the existing parallelget_multiple()enginetradeglob/__init__.py: ExportsEGX_SECTORS,list_egx_sectors,get_egx_sector_stocksat the package level.examples/example_5_egx_sectors.py: End-to-end usage example.Original prompt
Created from VS Code.