Open LimitlessTrader opened 3 years ago
Thanks for reaching out! It is possible to subscribe to many events simultaneously on single thread. Just define the associated call back for each event. It’s not clear that parfeval is needed. Let me know if that helps. I can look into it more tomorrow/this week
Thanks for the prompt response.
Yes I have tested subscribing multiple events on a single thread, (and it works well). My goal is to move the data streams to a "background" thread to leave the primary thread for function Main() to train Deep Learning algorithms on the streamed data.
I wonder if I can push the Neural Network training to background threads as well? I'd really like to keep the primary thread clear for real time control of order management.
Thanks
I see, as far as I know the events are processed on background “event dispatch thread” or EDT.
https://undocumentedmatlab.com/articles/matlab-and-the-event-dispatch-thread-edt
You might be able to use EDT but either way at some point you’ll need to block on main Matlab thread. I would suggest if you need strong multi thread support to compile out the Matlab algorithm to Java and then use it in Java API.
Certainly, TWS events will queue in IB4m. So you wouldn’t ever miss an event but could get latency/lag if have long event processing.
I'm not expert enough in Java for that. I bought the Parallel Computing Toolbox in MATLAB to take care of that for me, hence the attempted use of parfeval
and batch
.
I raised the issue, because the warning messages were indicating that the parallel threads were expecting something, I believe within IB4M to be 'serializable'. I don't know technically what that means, where the problem is or how to fix it.
I'll continue testing and looking for ways to resolve the problem, but I wanted to report it so it can be investigated and if necessary rectified or improved for everyone. I do the same with MATLAB products.
My apologies, I should have included my software environment in the issue:
IB4M ver 1.2.1.0 Installed 10 December 2020
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.10.0.1684407 (R2021a) Update 3
Operating System: Microsoft Windows 10 Home Single Language Version 10.0 (Build 19043)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.10 (R2021a)
Curve Fitting Toolbox Version 3.5.13 (R2021a)
DSP System Toolbox Version 9.12 (R2021a)
Database Toolbox Version 10.1 (R2021a)
Datafeed Toolbox Version 6.0 (R2021a)
Deep Learning Toolbox Version 14.2 (R2021a)
Econometrics Toolbox Version 5.6 (R2021a)
Financial Instruments Toolbox Version 3.2 (R2021a)
Financial Toolbox Version 6.1 (R2021a)
Global Optimization Toolbox Version 4.5 (R2021a)
MATLAB Report Generator Version 5.10 (R2021a)
Optimization Toolbox Version 9.1 (R2021a)
Parallel Computing Toolbox Version 7.4 (R2021a)
Reinforcement Learning Toolbox Version 2.0 (R2021a)
Signal Processing Toolbox Version 8.6 (R2021a)
Statistics and Machine Learning Toolbox Version 12.1 (R2021a)
IB TWS
`Trader Workstation
Copyright © 2000-2021 LICENSOR to Interactive Brokers
ALL RIGHTS RESERVED
Build 985.1d, Jun 23, 2021 4:48:46 PM
Jolt Build 1.17.11, May 7, 2021 10:25:19 AM
Nia Build 2.22.8, May 27, 2021 04:55:16 PM
ModelNav Build 1.11.3, Oct 20, 2020 05:52:13 PM
Riskfeed Build 2.42.17, May 27, 2021 04:38:09 PM
Java Version: 1.8.0_152, OS: Windows 10 (amd64, 10.0),
Memory: heap max 768Mb, current 125Mb`
Abel,
Thank you for creating and maintaining such a great app (IB4M). While I'm new to OOP and almost certainly don't fully appreciate the elegance of the architecture, I really do appreciate the readability of the code.
(PS Apologies for the formatting of this issue, I haven't got to grips with this text editor yet)
Problem / Objective
I'm trying to submit/run multiple, independent data streams in parallel (e.g. 1. TWS.Events.MARKETDEPTH, 2. TWS.Events.TICKBYTICK_BIDASK, 3. later there will be others), which update an object in the main function, while allowing the main function to continue processing other activities (e.g. creating and maintaining orders in IB)
I have tried using
parfeval
andbatch
both with similar error results: (Note: these are selected error messages, the full results are attached in documents.)Warning: conid 0 symbol GBP secType CASH strike 0.0 exchange IDEALPRO currency USD localSymbol GBP.USD is not serializable
Warning: Could not serialize object: com.proxy.ProxyBuilder$Handler@239b0f9d java.io.NotSerializableException: com.proxy.ProxyBuilder$Handler
Warning: com.tws.Handler@6bee793f is not serializable
Warning: com.ib.client.EClientSocket@726aa968 is not serializable
Warning: Could not serialize object: [com.tws.Handler$MarketDepthEvent[source=com.tws.Handler@6bee793f],
(Caution: The attached error logs are very large, I'm sure there is much duplication, but I've highlighted what I believe to be the relevant messages for IB4M triggered by the
parfeval
lines in Main() ).Error Messages from Market Depth.txt Error Messages from Time & Sales.txt
Relevant code from the Main (controlling) function
(Please note that I have included the code for both
parfeval
&batch
and just comment out those lines I'm not testing).function Main()
%% Create the 'contract' for the instrument
` %% Start the data streams
end
Relevant code from class 'marketDepth'
classdef marketDepth()
end`
Relevant code from class 'timeSales'
classdef timeSales()
%timeSales - Stream the Time & Sales data
% All methods required to manage the Time & Sales data stream, (TICKBYTICK_BIDASK) from Interactive Brokers (IB)
end`
Relevant code from class 'MyEnvironment'
classdef MyEnvironment
`%MYENVIRONMENT: custom environment in MATLABend`