If true
, this client will throw an error if it attempts to subscribe to
an authenticated subscription.
typedoc Reference Documentation
You can access the current WebSocket
typedoc Reference Documentation
A boolean indicating whether the WebSocket client is currently connected to the IDEX WebSocket API.
typedoc Reference Documentation
Connect to the IDEX WebSocket API
If true
, the promise will not resolve until the connection is established
this
to allow chaining with other methods or requests.typedoc Reference Documentation
Disconnect from the WebSocket if connected.
terminate
is true
, the WebSocket will be disconnected immediately and this client will
cease to work or connect.Optional
terminate: booleantypedoc Reference Documentation
Subscribe a handler to all WebSocket disconnect events.
A handler function matching WebSocketHandlerConnect that will receive events.
Optional
replaceAll: booleanReplaces all current handlers with the provided handler.
this
to allow chaining with other methods or requests. websocketClient.onConnect(() => {
console.warn('WebSocket Connection Connects')
})
typedoc Reference Documentation
Subscribe a handler to all WebSocket disconnect events.
A handler function matching WebSocketHandlerDisconnect that will receive events.
Optional
replaceAll: booleanReplaces all current handlers with the provided handler.
this
to allow chaining with other methods or requests. websocketClient.onDisconnect((code, reason) => {
console.warn('WebSocket Connection Disconnects: ', code, reason)
})
typedoc Reference Documentation
Subscribe a handler to all WebSocket connection errors that may occur during your requests.
ws
library itself and provide
its ErrorEvent errors.A handler function matching WebSocketHandlerError that will receive events.
Optional
replaceAll: booleanReplaces all current handlers with the provided handler.
this
to allow chaining with other methods or requests. websocketClient.onError(errorEvent => {
console.error('Connection Error on WebSocket: ', errorEvent.error)
})
typedoc Reference Documentation
Subscribe a handler to all subscription responses.
type
values that can be received on the WebSocket message (see example).A handler function matching WebSocketHandlerMessage that will receive events.
Optional
replaceAll: booleanReplaces all current handlers with the provided handler.
this
to allow chaining with other methods or requests. import { MessageEventType } from '@idexio/idex-sdk';
// ... client setup
websocketClient.onMessage(message => {
console.log('Receiving Message: ', message)
switch(message.type) {
case MessageEventType.subscriptions:
return handleSubscriptions(message.subscriptions);
case MessageEventType.error:
return handleAPIError(message.data);
case MessageEventType.candles:
return handleCandles(message.data);
default:
break;
}
})
Creates new authenticated subscriptions based on the provided parameters.
Subscription Update Events:
An array of IDEXSubscribeTypeAuthenticated subscription objects.
Optional
cid: stringOptionally provide a cid
property which will be returned in the response
so that you can correlate the response to the request.
this
to allow chaining with other methods or requests.This method will throw an error if you did not provide the auth option to the constructor in order to handle authenticated subscriptions.
import {
WebSocketClient,
SubscriptionNameAuthenticated,
} from '@idexio/idex-sdk';
const client = new WebSocketClient({
auth: {
apiKey: '...',
apiSecret: '...',
wallet: '0x...'
}
})
client.onMessage(message => {
console.log('Received WebSocket Message: ', message)
})
await client.subscribeAuthenticated([
{ name: SubscriptionNameAuthenticated.positions },
{ name: SubscriptionNameAuthenticated.orders },
])
This method allows subscribing to IDEX's public subscriptions.
Subscription Update Events:
An array of IDEXSubscribeTypePublic subscription objects.
Optional
markets: string[]Optionally provide top-level markets.
markets
array will inherit this set of markets.Optional
cid: stringOptionally provide a cid
property which will be returned in the response
so that you can correlate the response to the request.
this
to allow chaining with other methods or requests. import {
WebSocketClient,
SubscriptionNamePublic,
CandleInterval
} from '@idexio/idex-sdk';
const client = new WebSocketClient();
await client.subscribePublic([
// will inherit markets from the markets array
{ name: SubscriptionNamePublic.tickers },
// overrides the top level markets array with its own
{
name: SubscriptionNamePublic.candles,
interval: CandleInterval.ONE_MINUTE,
// replaces the top-level markets when provided
markets: ['ETH-USD', 'BTC-USD'],
},
], ['ETH-USD'])
Unsubscribes from a subscription or subscriptions
Subscription Update Events:
Optional
subscriptions: (WebSocketRequestUnsubscribeSubscription | WebSocketRequestUnsubscribeShortNames)[]Optional
markets: string[]Optional
cid: stringList all active subscriptions
Subscription Update Events:
Optional
cid: stringOptionally provide a cid
property which will be returned in the response
so that you can correlate the response to the request.
this
to allow chaining with other methods or requests.typedoc Reference Documentation
When a client is terminated, it will cease to function and a new WebSocketClient must be created to start a new connection.
You must provide constructor options that match either:
import {
WebSocketClient,
SubscriptionNameAuthenticated,
SubscriptionNamePublic
} from '@idexio/idex-sdk';
const webSocketClientPublicOnly = new WebSocketClient();
// or ... to enable both public and authenticated subscriptions:
const client = new WebSocketClient({
// Edit the values before for your environment
auth: {
apiKey: '1f7c4f52-4af7-4e1b-aa94-94fac8d931aa',
apiSecret: 'axuh3ywgg854aq7m73oy6gnnpj5ar9a67szuw5lclbz77zqu0j',
wallet: '0x...',
}
// sandbox: true,
// logger: console.log
});
client.onConnect(() => {
// [see onConnect docs for full example and information]
})
client.onDisconnect((code, reason) => {
// [see onDisconnect docs for full example and information]
})
client.onError(errorEvent => {
// [see onError docs for full example and information]
})
client.onMessage(message => {
console.log('Receiving Message: ', message)
switch(message.type) {
case MessageEventType.subscriptions:
return handleSubscriptions(message.subscriptions);
case MessageEventType.error:
return handleAPIError(message.data);
case MessageEventType.candles:
return handleCandles(message.data);
default:
break;
})
await client.connect();
// subscribe as needed!
await client
.subscribePublic([
{
name: SubscriptionNamePublic.tickers,
markets: ['ETH-USD']
},
])
.subscribeAuthenticated([
{ name: SubscriptionNameAuthenticated.positions },
{ name: SubscriptionNameAuthenticated.orders },
]);
typedoc Reference Documentation
WebSocket API client
You must provide constructor options that match either:
Example
See
typedoc Reference Documentation