AlpacaPlugin 1.0.0 released

Posted By: kzhao

AlpacaPlugin 1.0.0 released - 03/15/21 04:15

AlpacaZorroPlugin v1.0.0 released.

https://github.com/kzhdev/alpaca_zorro_plugin


- Introduced ZorroWebsocketProxy so that multiple ZorroS instances can share one Websocket connection
**NOTE** ZorroWebsocketProxy adopts a lock-free design which spins on one CPU core. High CPU usage is normal and expected.

- Added Alpaca MarketData V2 Websocket support
- Las trade and last quote are directly from WebSocket stream. This is dramatically reduced Zorro API query.
- if last trade or last quote update have not received yet, the plugin will pull last trade and quote from V1 endpoint.

- Added Alpaca plugin specific setting to Zorro.ini or ZorroFix.ini file.
- AlpacaDataSource = 1 // 0 = Alpaca, 1 = Polygon
- AlpacaPaidDataPlan = 1 // 0 = False, 1 = True
- AlpacaLogLevel = 0 // 0 = OFF, 1 = ERROR, 2 = WARNING, 3 = INFO, 4 = DEBUG, 5 = TRACE
- PolygonApiKey = "*************" // Polygon ApiKey
please refer to the README.md for details.

- Historical bars are still retrieved from V1 endpoint because V2 Historical Bars are not ready yet.

- Polygon MarketData is still supported, but the ApiKey has moved into Zorro config file.
NOTE: Polygon free plan can't be used as alternative market data source due to lack of last trade and last quote data.
Posted By: AndrewAMD

Re: AlpacaPlugin 1.0.0 released - 03/15/21 12:50

Originally Posted by kzhao
- Introduced ZorroWebsocketProxy so that multiple ZorroS instances can share one Websocket connection
**NOTE** ZorroWebsocketProxy adopts a lock-free design which spins on one CPU core. High CPU usage is normal and expected.
Why is high CPU usage normal and expected? What is using up the CPU?
Posted By: kzhao

Re: AlpacaPlugin 1.0.0 released - 03/15/21 13:53

The websocket proxy server/client spins a CPU core by doing busy wait. It keeps the CPU busy to wait messages or sending heartbeat between the server and clients. It is not doing hard spin though, the CPU will not totally locked up. If there is no job to do, it yields the thread so that other thread can be executed. I have been running at least 2 Zorro S instances on a single core VM, everything works fine.
Posted By: DdlV

Re: AlpacaPlugin 1.0.0 released - 03/17/21 20:05

@kzhao, I am trying v1.0.0. I have not added any settings into Zorro[Fix].ini - presumably that means defaulting to Alpaca Market Data and no logging. I am running this on Linux in a VM under Wine, testing with Z8/9.

- Most of the time Trade gives "!Unable to open Alpaca websocket". So far this happens always on the first Trade after Zorro starts, and sometimes again later.

- After the initial prices download, the Server goes Offline and the connection box goes red.

- After that I get "BrokerLogin: No Data!", and the strategy appears to hang.

- If I Stop Trading, zorro_websocket continues to loop until I close Zorro. Shouldn't it be stopped when the strategy stops?

- zorro_websocket is using all cores.
Posted By: kzhao

Re: AlpacaPlugin 1.0.0 released - 03/18/21 20:22

I did not run Zorro under Wine. I do found an issue where sometimes when starting a strategy the very first time, the proxy server heartbeat timed out. If you launch the strategy again, it should be fine. I already have a fix. I will try running zorro under Wine to see what happens.

The WebSocket proxy server keeps running after you stop trading because it can serve multiple Zorro instances. I can add an option so the server can shutdown after all connected clients are disconnected

How many cores does your VM have? The WebSocket proxy will keep the CPU busy, but most of the time it checks if there is an event and yields the CPU to other threads.
Posted By: DdlV

Re: AlpacaPlugin 1.0.0 released - 03/18/21 20:38

Thanks kzhao. VM has 2 cores & websocket seems to use both...
Posted By: kzhao

Re: AlpacaPlugin 1.0.0 released - 03/18/21 20:40

I am developing and testing the plugin on a single-core VM. Yes, you will see high CPU usage, but everything works fine.
Posted By: kzhao

Re: AlpacaPlugin 1.0.0 released - 03/18/21 21:07

In your case, the WebSocket server and the client spin on two separate CPU cores.
© 2024 lite-C Forums