-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BQL Feature Enhancement Request #18
Comments
@tmlynowski could you spec out what this involves? Is this a feature of the underlying |
@matthewgilbert BQL is indeed a functionality that can only be accessed via Excel (or BQNT). However, there seems to be a workaround that involves accessing Excel via Python to make BQL requests (https://stackoverflow.com/a/69014472). Do you think it would be possible to create a new class to implement this workaround? |
|
@matthewgilbert Rather like the |
Is this feature available for the Desktop API or is it exclusive to BQNT? |
@avantgardeam It is in the API, accessible via |
Thanks for flagging @DS-London . In that case I’m happy to except a PR for this feature. |
@DS-London, thank you for sharing this option! @matthewgilbert, I have successfully made requests to query = {'sendQuery': {'expression': "get( px_last() ) for( 'AAPL BZ Equity' )"}}
response = bquery.query(query, parse=False, collector=list) Response snippet: [{'eventType': 5,
'eventTypeName': 'blpapi.Event.RESPONSE',
'messageNumber': 0,
'message': {'fragmentType': 0,
'correlationIds': [66],
'messageType': 'result',
'timeReceived': Timestamp('2023-06-28 04:45:19.509121+0000', tz='UTC'),
'element': '{"results":{"px_last()":{"name":"px_last()","offsets":[0], ...'}] The issue arises because In this case, how should I proceed? Should I set |
@avantgardeam The response is a JSON string. You can parse the whole string by using
is one way of converting the JSON to a DataFrame, though only tested on a sub-set of BQL queries. |
Thanks, for sharing, @DS-London ! Sometimes, the import json
bquery = BlpQuery().start()
query = create_query(
"sendQuery",
{"expression": "get( PX_LAST(start = -3D), CUR_MKT_CAP, PX_TO_BOOK_RATIO ) for( ['IBM US Equity', 'AAPL US Equity', 'AZUL4 BZ Equity'] )"}
)
res = bquery.query(query, parse=False, collector=list)
result = json.loads(res[0]['message']['element'])['results']
data = []
for field in result.values():
# ID column may be a security ticker
aux_dict = {
"field": field['name'],
"id": field['idColumn']['values'],
"value": field['valuesColumn']['values']
}
# Secondary columns may be DATE or CURRENCY, for example
for secondary_column in field['secondaryColumns']:
aux_dict[secondary_column['name']] = secondary_column['values']
df = pandas.DataFrame(aux_dict)
# Since we have multiple secondary columns, we need to melt the dataframe
id_vars = ['field', 'id', 'value']
df = df.melt(
id_vars=id_vars, value_vars=df.columns.difference(id_vars),
var_name="secondary_name", value_name="secondary_value"
).dropna(subset=["value"])
column_order = ['secondary_name', 'secondary_value', 'field', 'id', 'value']
df = df[column_order]
data.append(df)
final_df = pandas.concat(data) |
Feature enhancement Request: Is it possible to implement BQL functionality same as Excel BQL Builder? Thanks
The text was updated successfully, but these errors were encountered: