n0mad01 / node.bittrex.api

No longer maintained
MIT License
183 stars 187 forks source link

I catch "Unhandled stream error in pipe" sometimes #1

Closed NeXTs closed 7 years ago

NeXTs commented 9 years ago

I can not determine the method in which it occurs, but sometimes node.js crashes with this message.

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: Unexpected "h" at position 1 in state START
    at Parser.proto.charError (/home/trader/node_modules/node.bittrex.api/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js:84:16)
    at Parser.proto.write (/home/trader/node_modules/node.bittrex.api/node_modules/JSONStream/node_modules/jsonparse/jsonparse.js:112:23)
    at Stream.<anonymous> (/home/trader/node_modules/node.bittrex.api/node_modules/JSONStream/index.js:21:12)
    at Stream.stream.write (/home/trader/node_modules/node.bittrex.api/node_modules/JSONStream/node_modules/through/index.js:26:11)
    at Request.ondata (stream.js:51:26)
    at Request.emit (events.js:95:17)
    at IncomingMessage.<anonymous> (/home/trader/node_modules/node.bittrex.api/node_modules/request/request.js:1263:12)
    at IncomingMessage.emit (events.js:95:17)
    at IncomingMessage.<anonymous> (_stream_readable.js:764:14)
    at IncomingMessage.emit (events.js:92:17)

My options are as follows

bittrexApi.options({
        'apikey': config.bittrex_public_key,
        'apisecret': config.bittrex_private_key,
        'stream': true,
        'verbose': false,
        'cleartext': false
    });

List of requests I made

client.sendCustomRequest('https://bittrex.com/api/v1.1/account/getorderhistory?market='+marketId+'&count=10', function(){
}, true);

client.getmarketsummaries(function(data) {
});

client.getbalances(function (data) {
});

client.getorderbook({market: marketId, depth: 15, type: 'both'}, function(data) {
});

client.sendCustomRequest('https://bittrex.com/api/v1.1/market/getopenorders?market='+marketId, function( data ) {
}, true);

Any ideas why this is happening ?

rebrec commented 7 years ago

I am experiencing the same issue, is there a solution for this issue or you just simply closed it ?

n0mad01 commented 7 years ago

this is an issue with the JSONStream library, it's about what can be considered a JSON object, the strings start/end parseability.

i changed the way data gets parsed by JSONStream so it only returns text now - but you have to parse the returned text by yourself!

i bumped the github & npmjs version, so try if it works now, if not then consider to relinquish the stream api and use the simple request calls.

also consider to like/star projects you use.