coinbase / coinbase-pro-trading-toolkit

DEPRECATED — The Coinbase Pro trading toolkit
Apache License 2.0
868 stars 239 forks source link

Example script fails to connect #42

Closed nick-allen closed 4 years ago

nick-allen commented 7 years ago

gdax-tt 0.1.16 node 8.3.0 typescript 2.5.3

Script pulled from example doc https://coinbase.github.io/gdax-tt/gtt_tutorials_feed.html#the-basics

import * as GTT from "gdax-trading-toolkit";
import { GDAXFeed } from "gdax-trading-toolkit/build/src/exchanges";
import { OrderbookMessage } from "gdax-trading-toolkit/build/src/core";

const logger = GTT.utils.ConsoleLoggerFactory();
const products: string[] = ["BTC-USD", "ETH-USD", "LTC-USD"];
const tallies: any = {};
products.forEach((product: string) => {
  tallies[product] = {};
});

let count = 0;

function printTallies() {}

GTT.Factories.GDAX
  .FeedFactory(logger, products)
  .then((feed: GDAXFeed) => {
    feed.on("data", (msg: OrderbookMessage) => {
      count++;
      if (!(msg as any).productId) {
        tallies.other += 1;
      } else {
        const tally = tallies[msg.productId];
        if (!tally[msg.type]) {
          tally[msg.type] = 0;
        }
        tally[msg.type] += 1;
      }
      if (count % 1000 === 0) {
        printTallies();
      }
    });
  })
  .catch((err: Error) => {
    logger.log("error", err.message);
    process.exit(1);
  });

Logs

2017-10-01T05:12:52.329Z - info: Creating new Websocket connection to wss://ws-feed.gdax.com 
2017-10-01T05:12:52.340Z - debug: Reconnecting to wss://ws-feed.gdax.com  in 0 seconds...
2017-10-01T05:12:52.340Z - debug: Closing existing socket prior to reconnecting to wss://ws-feed.gdax.com
2017-10-01T05:12:53.693Z - debug: Connection to wss://ws-feed.gdax.com  has been established.
2017-10-01T05:12:53.693Z - debug: Sending {"type":"subscribe","product_ids":["BTC-USD","ETH-USD","LTC-USD"],"channels":["level2","matches","ticker","user","heartbeat"]} message to WS server

/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Sender.js:206
      bufferUtil.mask(data, mask, outputBuffer, dataOffset, dataLength);
                ^
TypeError: Cannot read property 'mask' of undefined
    at Sender.frameAndSend (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Sender.js:206:17)
    at /app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Sender.js:126:12
    at /app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/PerMessageDeflate.js:313:5
    at afterWrite (_stream_writable.js:438:3)
    at onwrite (_stream_writable.js:429:7)
    at DeflateRaw.afterTransform (_stream_transform.js:90:3)
    at Zlib.callback (zlib.js:514:5)
nick-allen commented 7 years ago

Similar behavior when trying to use the Bitfinex feed

Logs

2017-10-01T05:16:17.082Z - info: Creating new Websocket connection to wss://api2.bitfinex.com:3000/ws 
2017-10-01T05:16:17.694Z - debug: Connection to wss://api2.bitfinex.com:3000/ws  has been established.
2017-10-01T05:16:17.694Z - debug: Sending {"event":"subscribe","channel":"ticker","pair":"btcusd"} message to WS server
2017-10-01T05:16:17.695Z - debug: Sending {"event":"subscribe","channel":"trades","pair":"btcusd"} message to WS server
2017-10-01T05:16:17.695Z - debug: Sending {"event":"subscribe","freq":"F0","channel":"book","pair":"btcusd","len":"250"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","channel":"ticker","pair":"ethusd"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","channel":"trades","pair":"ethusd"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","freq":"F0","channel":"book","pair":"ethusd","len":"250"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","channel":"ticker","pair":"ltcusd"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","channel":"trades","pair":"ltcusd"} message to WS server
2017-10-01T05:16:17.696Z - debug: Sending {"event":"subscribe","freq":"F0","channel":"book","pair":"ltcusd","len":"250"} message to WS server

/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:371
    callback(null, messageBuffer);
    ^
TypeError: Cannot read property 'isValidUTF8' of undefined
    at /app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:532:28
    at Receiver.applyExtensions (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:371:5)
    at /app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:508:14
    at Receiver.flush (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:347:3)
    at Receiver.finish (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:541:12)
    at Receiver.expectHandler (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:499:31)
    at Receiver.add (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/Receiver.js:103:24)
    at TLSSocket.realHandler (/app/node_modules/gdax-trading-toolkit/node_modules/ws/lib/WebSocket.js:825:20)
    at emitOne (events.js:115:13)
    at TLSSocket.emit (events.js:210:7)
nick-allen commented 7 years ago

With Bittrex

2017-10-01T05:18:45.395Z - debug: Connection to wss://socket.bittrex.com/signalr  has been established.
  TypeError: Cannot read property 'Nounce' of undefined
at BittrexFeed.processSnapshot (/app/node_modules/gdax-trading-toolkit/src/exchanges/bittrex/BittrexFeed.ts:223:28)
at client.call.done (/app/node_modules/gdax-trading-toolkit/src/exchanges/bittrex/BittrexFeed.ts:64:56)
at callCallbacks.(anonymous function) (/app/node_modules/signalr-client/signalR.js:429:6)
at handleCallResult (/app/node_modules/signalr-client/signalR.js:436:11)
at WebSocketConnection.<anonymous> (/app/node_modules/signalr-client/signalR.js:748:7)
at emitOne (events.js:115:13)
at WebSocketConnection.emit (events.js:210:7)
at WebSocketConnection.processFrame (/app/node_modules/websocket/lib/WebSocketConnection.js:547:26)
at /app/node_modules/websocket/lib/WebSocketConnection.js:321:40
at _combinedTickCallback (internal/process/next_tick.js:131:7)
ghost commented 7 years ago

Are you using ts-node? If not, try this:

npm -g ts-node typescript
ts-node tutorials/t001_feeds.ts

If you are, what version of ts-node? My versions are:

jackson-sandland commented 6 years ago

I was able to get this working using vanilla javascript. Try building the script one part at a time, instead of copy/paste, and make sure the individual parts work before everything is in the script. If you're familiar with javascript it's easy to 'convert' it from ts.

drewrothstein commented 4 years ago

Hi, we are closing out PRs + Issues as this project is being archived.