Pass in Attributes to the onBarUpdate() Callback Function Possible?
See original GitHub issueIs it possible to pass in features/variables to the onBarUpdate callback? I’m wanting to pass in the contract object to it so I can parse the contract’s symbol from it. What I have so far looks like this:
contracts = [Forex(pair) for pair in ('EURUSD', 'USDJPY', 'GBPUSD', 'USDCHF', 'USDCAD')]
ib.qualifyContracts(*contracts)
def onBarUpdate(bars, hasNewBar):
df = util.df(bars)
df.to_csv("datasets/" + todays_date + "/" + TICKER/CONTRACT_HERE + ".csv", index=True)
for contract in contracts:
bars = ib.reqHistoricalData(contract, endDateTime='', durationStr='3 D', barSizeSetting='5 mins', whatToShow='MIDPOINT', useRTH=False, keepUpToDate=True)
bars.updateEvent += onBarUpdate
…and what I envision I’m after would look something like:
def onBarUpdate(bars, hasNewBar, contract):
....
bars.updateEvent += onBarUpdate(contract)
…however I’m having issues troubleshooting this to get it working. As I’m sure can be guessed, I’d like to replace the “TICKER/CONTRACT_HERE” with something like “contract.symbol” so I could save the .csv file with the ticker for the corresponding bars contract in the filename. I’m just getting used to async callback functions as well so not sure the correct syntax. Any help would be greatly appreciated! Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Passing attributes to callback functions - php - Stack Overflow
you can try this way, call_user_func_array() class foo { function bar($arg, $arg2) { echo __METHOD__, " got $arg and $arg2\n"; } ...
Read more >OnBarUpdate() - NinjaScript - NinjaTrader 8
A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. IsDataSeriesRequired....
Read more >insync@groups.io | Topics
Error 'list' object has no attribute 'conId' although there is a conId 4 messages ... Hi, I have a few question about callbacks...
Read more >Add attributes of Script used with API Genesys Cloud to create ...
My question is regarding the Participant Data and how to put some variables ... If you want to pass a set of variables/data...
Read more >Viewing online file analysis results for 'NinjaTrader.Core.dll'
This report is generated from a file or URL submitted to this webservice on September ... Found a potential E-Mail address in binary/memory....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s easier to use
bars.contract
You can use partial from functools