AlpacaHandshake
A long-lived WebSocketManager handshake handler for Alpaca's market-data streams. A WebSocketManager connection created with a handshake asks a handler for its login on every socket open: connect, reconnect and actor handoff. This worker answers those requests, so a connection stays logged in without a notebook or script running.
| Property | Value |
|---|---|
| Project | Virtufin.Worker.AlpacaHandshake |
| Base class | Virtufin.Worker.DevKit.WorkerBase<JsonNode, JsonObject> |
| Engine | application/x-dotnet-dll |
| Input topic | the connection's handshake.topic (yours to choose) |
| Output | the request's replytopic, same correlationid, ce-type com.virtufin.alpacahandshake.reply |
| Secrets | alpacakey, alpacasecret (worker secrets, WorkManager 0.21+) |
| Config | symbols (BTC/USD,ETH/USD), channels (default orderbooks) |
Reply
{"messages": [
{"text": "{\"action\":\"auth\",\"key\":\"…\",\"secret\":\"…\"}",
"expect": "\"msg\":\"authenticated\"", "fail": "\"T\":\"error\""},
{"text": "{\"action\":\"subscribe\",\"orderbooks\":[\"BTC/USD\",\"ETH/USD\"]}"}
]}
symbolsandchannelsin the connection's handshake config win over the worker's config.- Without its secrets, or without symbols, it replies
{"error": …}, which fails the handshake (ConnectreturnsFAILED_PRECONDITION; a reconnect counts as a failed attempt). - An event without
replytopicandcorrelationidis not a handshake request and is ignored.
Deploy
- Put the key in the worker secret (once per cluster):
kubectl -n virtufin create secret generic virtufin-worker-secrets \
--from-literal=alpaca-paper-key="$ALPACA_API_KEY" \
--from-literal=alpaca-paper-secret="$ALPACA_API_SECRET"
- Create the worker on your handshake topic, with secrets by reference:
{
"code_source": {"url": "https://nuget.haenerconsulting.com/api/packages/virtufin/nuget/package/Virtufin.Worker.AlpacaHandshake/0.1.0/Virtufin.Worker.AlpacaHandshake.0.1.0.nupkg",
"credential": {"named": "virtufin"}},
"mime_type": "application/x-dotnet-dll",
"topics": ["x.myapp.alpaca.handshake"],
"config": {"symbols": "BTC/USD,ETH/USD"},
"secrets": {"alpacakey": "alpaca-paper-key", "alpacasecret": "alpaca-paper-secret"}
}
- Connect with
handshake = {topic: "x.myapp.alpaca.handshake"}.
Security
The reply carries the login over pub/sub to the WebSocketManager instance's reply topic; anyone who can subscribe to that topic can read it (WebSocketManager handshake docs, "Security"). Prefer a paper or low-privilege key.