Need help with BrokerAsset workaround

Posted By: CpOo

Need help with BrokerAsset workaround - 06/11/21 18:48

Hi,

I need some ideas / help to bypass a problem with BrokerAsset (Error 053) while trading a multi Asset strategy using the Binance Futures Plugin.

The problem is that when an Asset becomes unavailable or unsubscribed from the websocket, the connection stopped as a whole and trading stops not only for the unavailable assets, but for all:

From the _diag log:

Code
Load ETCUSDT
BrokerAsset ETCUSDT 0 => 
printf: 
!§s0  (494.990800 ms)
printf: 
Error 053: §s unavailable at this time


From the _real log (Debug 7):

Code
!FEED_WS: readloop_handler: unspecified system error
!BrokerAccount: 'stopped' detected!
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
!BrokerAsset: stopped
...


As for the BrokerPlugin docs (https://manual.zorro-project.com/brokerplugin.htm) when an Asset is unavailable it returns Error 053 and trading with that asset is disabled. That's Ok, and perfectly fine, but as my understanding trading should be disabled only for that asset, and not the remaining ones that are Ok and available IMHO. I debug that and If I comment the affected asset and connect again the system resume the trading session without problem.

I talked with support about this and they were very helpful, but unfortunately I am not a very good coder, and not sure what are the best way to setup this workaround, as it is more complex than expected.

Option 1: Use Ignore(53) to continue trading with the other assets: This option is not working (in my test) maybe because it only have effect at the start of the trading session: https://manual.zorro-project.com/errors.htm

Option 2: Detect that the Asset is unavailable by script and exclude it from the trading session, restarting the connection with the broker again.

This is a complex thing because it is necessary to do in the error() or callback() function and then connect again without the unavailable Assets. It could be something like this:

1.- Detect the error
2.- Check and Stop the connection with the broker if already open with login(2); or login(4);
3.- Exclude the affected asset
4.- Start again the connection with the broker with login(1)

If someone have a better idea, or similar experiences and can share some code it would be great as I am a bit desperate with this problem.

Thank you so much
Posted By: jcl

Re: Need help with BrokerAsset workaround - 06/15/21 07:31

Error 53 does not stop a session. It only returns 0 when asset() is called. If that stops the session or not depends on the script. Of course it's also possible that the broker API then throws an internal error from which it does not recover.

Posted By: CpOo

Re: Need help with BrokerAsset workaround - 06/15/21 11:27

Hi,

Yes, in my understanding Error 53 (BrokerAsset == 0) should only stop trading with the Asset that has problems, but continue trading with the other ones. I think that session with the broker is not completely closed (because I can see that the affected Asset re-subscribed again few minutes later), but somewhat freeze, and if one asset loose the subscription everything is stopped until that asset is subscribed again. Support and developer are looking into it.
© 2024 lite-C Forums