altangent / ccxws

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

Kraken Subscription Issue #230

Closed baloian closed 3 years ago

baloian commented 3 years ago

Hi Everyone,

I am having an issue with Kraken subscription. When I do LTC subscription I do not get any trade, but when I create my own websocket I do get it. From the documentation it is not fully clear how is going to be subscription format for every exchange.

Here is my example

const kraken_markets = [
  {
    id: "LTCUSD",
    base: "LTC",
    quote: "USD"
  }
];

const kraken = new ccxws.Kraken();
kraken_markets.forEach((market) => kraken.subscribeTrades(market));
kraken.on('trade', (trade) => processTradeData(trade));

Does anybody having the same issue? Basically, I get only a few trades even if I subscribe all the available pairs.

fbadiola commented 3 years ago

Hi,

CCXWS is kraken api compliance so the valid market is XLTCZUSD. CCXT converts internally to WS api.

You can found it on README.md

CCXWS uses similar market structures to those generated by the CCXT library. This allows interoperability between the RESTful interfaces provided by CCXT and the realtime interfaces provided by CC

So if you use ccxt to fetch kraken_markets then you should use id .

const ccxt = require('ccxt');
const ccxws = require('ccxws');

async function main(exchange = new ccxt.kraken()) {
  const ws = new ccxws.Kraken();
  ws.on('trade', (trade) => processTradeData(trade));
  const krakenMarkets = (await exchange.fetchMarkets()).map(x => ({ id: x.id, base: x.base, quote: x.quote}));
  for (const subPayload of krakenMarkets) {
    ws.subscribeTrades(market)
  }
}

main();
baloian commented 3 years ago

Thank you very much @fbadiola. This solved my problem. I am closing the issue.

trasherdk commented 2 years ago

Updated version :smile:

import ccxt from 'ccxt';
import { KrakenClient } from 'ccxws';

async function processTradeData (trade) {
  console.log(trade)
}

async function main (exchange = new ccxt.kraken()) {
  const ws = new KrakenClient();
  ws.on('trade', (trade) => processTradeData(trade));
  const krakenMarkets = (await exchange.fetchMarkets()).map(x => ({ id: x.id, base: x.base, quote: x.quote }));
  for (const market of krakenMarkets) {
    ws.subscribeTrades(market)
  }
}

main();