Headers are required for this third-party WebSocket according to the Gemini documentation:
Your WebSocket request needs to include these three headers:
X-GEMINI-APIKEY
X-GEMINI-PAYLOAD
X-GEMINI-SIGNATURE
Python WebSocket connection example from the documentation:
import ssl
import websocket
...
ws = websocket.WebSocketApp("wss://api.gemini.com/v1/order/events",
on_message=on_message,
header={
'X-GEMINI-PAYLOAD': b64.decode(),
'X-GEMINI-APIKEY': gemini_api_key,
'X-GEMINI-SIGNATURE': signature
})
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
Important: I do not control this WebSocket server so I can't use server-side 'hacks'.
I am able to successfully request this websocket from Google Cloud Functions using the NodeJS 'ws' library:
const WebSocket = require('ws');
exports.start_gemini_socket = functions.https.onCall((data, context) => {
var socket = new WebSocket(url, {headers:{myHeaders}});
}
I can also request a different Gemini WebSocket (no headers) directly from my TypeScript Angular web app using the 'RxJs' library. This works as expected and flows into my web app, but it's a public WebSocket and doesn't require headers:
import { webSocket } from 'rxjs/webSocket'
this.connection$ = webSocket('wss://api.gemini.com/v1/marketdata/btcusd')
I understand browser-based websocket requests are not allowed to send headers:
Stack Overflow: Custom headers for WebSocket JS
Stack Overflow: HTTP headers in Websockets client API
Is there a better solution to getting this data into my Angular web app?