altangent / ccxws

WebSocket client for 38 cryptocurrency exchanges
MIT License
617 stars 186 forks source link

Add Okex Futures and Swap Markets #175

Closed sanjujosh closed 4 years ago

sanjujosh commented 4 years ago

Hello,

Okex has swap and futures on the same ws end point. Is it possible to add them ?

I have the below hacky changes to add the support for swaps

for swaps,

  // okex-client.js 
  _sendSubTrades(remote_id) {
    let businessType = 'spot' // Default
    if (remote_id.includes('SWAP')) {
      businessType = 'swap'
    }
    this._sem.take(() => {
      this._wss.send(
        JSON.stringify({
          op: "subscribe",
          args: [`${businessType}/trade:${remote_id}`],
        })
      );
    });
  }

same changes added to _processsMessage function to handle swap trades

// trades swap
    if (msg.table === "swap/trade") {
      this._processTrades(msg);
      return;
    }
bmancini55 commented 4 years ago

Thanks for submitting the issue! It should be possible to add swaps, futures and options.

I'm thinking it would be beneficial to pass the market as a second optional value to the subscribe methods. This way the _sendSub* methods could use the metadata in the market instead of trying to infer the type based on the remote_id. This should be pretty easy to get into the library.