I am working on my first julia program and using an existing python script I wrote to give me a data stream. To develop I am using Pluto and PyCall and trying to implement a asynch callback that returns a stream of data. So the calling cell is posting an asynchronous request to a broker api which starts to send back a stream of stock price change EVENTS which triggers a series of python print statements. So each time a price changes the callback gets triggered.
In python it’s working properly and I get a stream of data that looks like this
640898070.0 ^ V ^ 49462172 ^ 217.87
1640898070.0 ^ VLO ^ 13497 ^ 74.28
1640898070.0 ^ VWO ^ 27684033 ^ 49.59
1640898070.0 ^ VZ ^ 4901 ^ 52.25
1640898070.0 ^ WBA ^ 178634687 ^ 51.99
1640898070.0 ^ WDAY ^ 115324104 ^ 276.5
1640898075.0 ^ ESH2 ^ 461318816 ^ 4773.25
I don’t know if I can do this in Pluto?
I have been working my way ( with a LOT of help from discourse) down the python code using the journey to learn.
begin
py"""
def onBarUpdate(bars, hasNewBar):
print( datetime.timestamp(bars[-1].time),"^ ", bars.contract.localSymbol," ^ ",bars.contract.conId," ^ ",bars[-1].close )
"""
onBarUpdate_py = py"onBarUpdate"
end
where onbarupdate is an event that emits values to connected listeners.
calling cell which posts a request for 5 second bars for the related stock.
stock_bars.updateEvent += onBarUpdate_py
Right now the PyCall is throwing an error that has caused me to ask the bigger question, does Pluto handle this sort of event.
PyError ($(Expr(:escape, :(ccall(#= /home/dave/.julia/packages/PyCall/L0fLP/src/pyoperators.jl:12 =# @pysym(:PyNumber_Add), PyPtr, (PyPtr, PyPtr), a, b))))) <class 'TypeError'>
TypeError("unsupported operand type(s) for +: 'Event' and 'function'")
pyerr_check@exception.jl:62[inlined]
pyerr_check@exception.jl:66[inlined]
_handle_error(::String)@exception.jl:83
macro expansion@exception.jl:97[inlined]
+@pyoperators.jl:11[inlined]
top-level scope@Local: 1[inlined]
I’m going to hit the PyCall docs related to the TypeError but I’m wondering if Pluto can’t handle these types of events. If it can would someone point me at a worked example of a Pluto cell ( or series of cells) that can handle asynchronous events. I have tried a few google searches for clues like this one
Real-time updating of plot data #30
thank you