@@ -165,7 +165,8 @@ def download_asset_prices(self, start_timestamp, end_timestamp, sources_list):
165165 MarketDataFeed .FRA : self .YahooFRA_Downloader ,
166166 MarketDataFeed .SMA_VICTORIA : self .Victoria_Downloader ,
167167 MarketDataFeed .COIN : self .Coinbase_Downloader ,
168- MarketDataFeed .MILAN : self .EuronextMilan_DataReader
168+ MarketDataFeed .MILAN : self .EuronextMilan_DataReader ,
169+ MarketDataFeed .WSE : self .Stooq_DataReader
169170 }
170171 assets = JalAsset .get_active_assets (start_timestamp , end_timestamp )
171172 assets = [(x ['asset' ], x ['currency' ]) for x in assets if x ['asset' ].quote_source (x ['currency' ]) in sources_list ]
@@ -523,6 +524,38 @@ def visitor_body(text, cm, tm, font_dict, font_size):
523524 self ._victoria_quotes .append ({'name' : fund_name , 'price' : Decimal (price .replace (',' , '.' ))})
524525 return self ._victoria_quotes
525526
527+ def Stooq_DataReader (self , asset , currency_id , start_timestamp , end_timestamp ):
528+ """Fetches historical data from Warsaw Stock Exchange (GPW) using Stooq API"""
529+ url = "https://stooq.com/q/d/l/"
530+ params = {
531+ 's' : asset .symbol (currency_id ),
532+ 'd1' : datetime .fromtimestamp (start_timestamp , tz = timezone .utc ).strftime ('%Y%m%d' ),
533+ 'd2' : datetime .fromtimestamp (end_timestamp , tz = timezone .utc ).strftime ('%Y%m%d' ),
534+ 'i' : 'd'
535+ }
536+
537+ self ._request = WebRequest (WebRequest .GET , url , params = params )
538+ self ._wait_for_event ()
539+
540+ try :
541+ data = pd .read_csv (
542+ StringIO (self ._request .data ()),
543+ converters = {'Close' : lambda x : Decimal (x .strip ())} # не теряем точность при чтении
544+ )
545+ if data .empty :
546+ return None
547+
548+ # Convert dates and filter required columns
549+ data ['Date' ] = pd .to_datetime (data ['Date' ], format = '%Y-%m-%d' , utc = True )
550+
551+ close = data [['Date' , 'Close' ]].set_index ('Date' )
552+ close .sort_index (inplace = True )
553+ return close
554+
555+ except (ParserError , KeyError , ValueError ) as e :
556+ logging .error (f"Failed to parse Stooq data: { str (e )} " )
557+ return None
558+
526559 def Coinbase_Downloader (self , asset , currency_id , start_timestamp , end_timestamp ):
527560 currency_symbol = JalAsset (currency_id ).symbol ()
528561 url = f"https://api.coinbase.com/v2/prices/{ asset .symbol (currency_id )} -{ currency_symbol } /spot"
0 commit comments