Coder Social home page Coder Social logo

Comments (7)

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024

Could you run your code using DEBUG=cewsc:Client. There mighty be a pb in your kline handler. Data passed to the handler is already an object and will fail on JSON.parse

from crypto-exchanges-gateway.

Gabri avatar Gabri commented on June 6, 2024

Sorry, I don't understand how to use that property or flag. As a parameter starting the crytpo-exchange-gateway? Or in my code? I'm running it in debug with Visual Studio Code, it is an additional parameter?

from crypto-exchanges-gateway.

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024

When running the code which is connectant to the gateway DEBUG=cewsc:Client node bot.js. This will enable debug of the ws client

from crypto-exchanges-gateway.

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024

You can wrap your event handler with a try...catch to see the problem

this.client.on('kline', (data) => {
    log.debug('WS CEG MSG:' + data);
    try {
        const datajson = JSON.parse(data)
        if (datajson && datajson.d) {
            if (datajson.d.data.closed === false) {
                log.debug('WS CEG data but NOT closed Candle')
            }
            if (datajson.d.data.closed === true) {
                log.info('WS CEG of CLOSED Candle:' + datajson)
                //const pairReversed = stringUtils.getSymbolForExchange(symbol, 'ceg')
                const evt_name = 'candle_' + _this.symbols + '-' + datajson.d.interval
                // adding data interval/timeframe to data candle
                datajson.d.data['timeframe'] = datajson.d.interval
                log.info(_this.symbols + ' - CANDLE close:' + JSON.stringify(datajson.d.data + ' emitting event candle:' + evt_name));
                vorpal.log(_this.symbols + ' - CANDLE close:' + JSON.stringify(datajson.d.data + ' emitting event candle:' + evt_name));
                _this.emit(evt_name, datajson.d.data);
            }
        }
    }
    catch (e) {
        console.log(e);
    }
});

You should have an error similar to SyntaxError: Unexpected token o in JSON at position 1 since you're trying to call JSON.parqe on an object instead of a string

from crypto-exchanges-gateway.

Gabri avatar Gabri commented on June 6, 2024

Ok. I tried but I couldn't see any differences.
Anyway it seems I found the solution. I don't know exactly why now works, before the client was initialized on the constructor of the class and then calling a method of the class I used "this.client...". Anyway connection worked ..but I had that problem. Removing this from constructor and initializing it directly on the method ..works. Ok :)

from crypto-exchanges-gateway.

aloysius-pgast avatar aloysius-pgast commented on June 6, 2024

The data object emitted by the library is similar to

{ pair: 'USDT-ETH',
  interval: '4h',
  data: 
   { timestamp: 1568001600,
     open: 178.25,
     close: 177.47,
     high: 179.01,
     low: 177,
     volume: 33932.89887,
     remainingTime: 2347,
     closed: false },
  exchange: 'binance' }

from crypto-exchanges-gateway.

Gabri avatar Gabri commented on June 6, 2024

P.s: before trying moving the initializing I tried the snippet you gave me on the other issue and ..it worked perfectly. So, I checked deeply the differences on my code ..so I tried in that way.
Thank you for the kindly support!

from crypto-exchanges-gateway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.