dxFeed / dxLink

Market Data API
https://demo.dxfeed.com/dxlink-ws/
Mozilla Public License 2.0
6 stars 2 forks source link

Unable to start DXLinkWebSocketClient - WebSocket is not defined #9

Closed sharanwj closed 1 day ago

sharanwj commented 1 month ago

Getting error when creating a client -

const client = new DXLinkWebSocketClient()
    client.connect('wss://openapi-ws.dxfeed.com/realtime')
    client.setAuthToken('xyz')

    const feed = new DXLinkFeed(client, FeedContract.AUTO)
    feed.configure({
        acceptAggregationPeriod: 10,
        acceptDataFormat: FeedDataFormat.COMPACT,
        acceptEventFields: {
            Quote: ['eventSymbol', 'askPrice', 'bidPrice'],
            Candle: ['eventSymbol', 'open', 'close', 'high', 'low', 'volume'],
        },
    })

Error - this.socket = new WebSocket(this.url) ^ ReferenceError: WebSocket is not defined at WebSocketConnector.start (file:///Users/xyz/tt/node_modules/@dxfeed/dxlink-websocket-client/src/connector.ts:23:23)

https://github.com/dxFeed/dxLink/blob/1eaefd9341ddde5ba0cb4b4690f84ead20fa073e/dxlink-javascript/dxlink-websocket-client/src/connector.ts#L23

I added this import in connector class which fixed the issue locally for me - import WebSocket from 'ws';

Fyzu commented 1 week ago

Hi,

WebSocket should be available in your environment. If necessary, you can simply polyfill it.

Let me know if you need any further adjustments!

Fyzu commented 1 day ago

Closing due to lack of responses. You may reopen the issue if you need to.

Regards, dxLink team