Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_securities_in_blocks(provider: str = 'eastmoney',
categories: List[Union[str, StockCategory]] = ['concept', 'industry'],
names=None, codes=None, ids=None):
session = get_db_session(provider=provider, data_schema=Index)
categories = [StockCategory(category).value for category in categories]
filters = [Index.category.in_(categories)]
# add name filters
if names:
filters.append(Index.name.in_(names))
blocks = get_entities(entity_ids=ids, codes=codes, entity_type='index', provider=provider,
filters=filters, return_type='domain', session=session)
securities = []
for block in blocks:
securities += [item.stock_id for item in block.stocks]
return securities
def generate_url(self, category, code, number):
if category == StockCategory.industry.value:
block = 0
elif category == StockCategory.concept.value:
block = 1
return self.url.format(number, block, code)
def get_indices(provider: str = 'sina',
block_category: Union[str, StockCategory] = 'concept',
return_type: str = 'df') -> object:
"""
get indices/blocks on block_category
:param provider:
:type provider:
:param block_category:
:type block_category:
:param return_type:
:type return_type:
:return:
:rtype:
"""
if type(block_category) == StockCategory:
block_category = block_category.value
session = get_db_session(provider=provider, data_schema=Index)
filters = [Index.category == block_category]
blocks = get_entities(entity_type='index', provider=provider, filters=filters,
session=session, return_type=return_type)
return blocks