Giter Site home page Giter Site logo

cw-sdk-node's People

Contributors

dbosley avatar dependabot[bot] avatar miguelcobain avatar tahoedesigner avatar vicagbasi avatar vvozibic avatar wellsjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cw-sdk-node's Issues

protobuf error

I'm getting these errors while trying to use the library with TypeScript:

node_modules/cw-sdk-node/build/websocket/types/trading.d.ts:1:10 - error TS2305: Module '"../modules/proto"' has no exported member 'ProtobufBroker'.

1 import { ProtobufBroker } from '../modules/proto';
           ~~~~~~~~~~~~~~

node_modules/cw-sdk-node/build/websocket/WebSocketClient.d.ts:3:10 - error TS2305: Module '"./modules/proto"' has no exported member 'ProtobufClient'.

3 import { ProtobufClient } from './modules/proto';
           ~~~~~~~~~~~~~~

This happens because the file at build/websocket/modules/proto/index.d.ts is being overwritten by the type definitions file generation with the following contents:

export = $root;
declare var $root: {};

That's because typescript compiler doesn't find any types on the corresponding index.js file.

Is this protobuf usage up to date?
Perhaps we should follow these instructions: https://github.com/protobufjs/protobuf.js#usage-with-typescript

Update documentation and strange behaviour

It seems there is a lot of documentation missing, I can't find what the stream pairs:*:performance does for example.

Also I only get buy trades when subscribing to :trades (tried with markets:247:trades), sell orders are empty:

2020-06-06T11:24:27.570Z MARKET UPDATE {
  market: { id: 247, exchangeID: 16, currencyPairID: 175 },
  trades: []
}
2020-06-06T11:24:29.846Z MARKET UPDATE {
  market: { id: 247, exchangeID: 16, currencyPairID: 175 },
  trades: [
    {
      externalID: 'f8a19ec3-33ab-8191-6c9e-42acc5382619',
      timestamp: 2020-06-06T11:24:29.579Z,
      side: 'buy',
      price: '9673.5',
      amount: '1'
    }
  ]
}

And I experience the same as described in #14

Support inherited child logger instance

Right now Winston is initialized with a custom format for logging, it would be more usable and ops-friendly if we could supply StreamClient and RESTClient Constructors with a winston child-logger instance that utilizes logger format (such as JSON/Logstash/...) to avoid these issues:

[cw-sdk-node] sending auth message
[cw-sdk-node] authenticated
[cw-sdk-node] State change: [ 'connected' ]
{"component":"bot","level":"info","message":"Datasource State Update","state":1,"timestamp":"2022-07-27T06:30:48.408Z"}
{"component":"bot","level":"info","message":"Datasource State Update","state":2,"timestamp":"2022-07-27T06:30:48.615Z"}

As you can see from this example the cw-sdk-node logs would completely break logparsing and ingestion (or rather, it would be silently dropped) as they do not conform to JSON standard. Important error-logs could be lost making debugging something like fortune reading out of coffee tailings...

Please allow an option, similar to logLevel, that directly supplies a winston childlogger instance to use instead.

using patch-package you can apply this patch and utilize a logger opt for WS and REST clients:

diff --git a/node_modules/cw-sdk-node/build/util/logger.d.ts b/node_modules/cw-sdk-node/build/util/logger.d.ts
index 5972013..bc0c4d6 100644
--- a/node_modules/cw-sdk-node/build/util/logger.d.ts
+++ b/node_modules/cw-sdk-node/build/util/logger.d.ts
@@ -3,6 +3,7 @@ declare class Logger {
     private logger;
     private level;
     constructor(level: LogLevel | undefined);
+    setLogger(child: any): void;
     setLevel(newLevel: LogLevel | undefined): void;
     disable(): void;
     error(message: string, ...meta: any[]): void;
diff --git a/node_modules/cw-sdk-node/build/util/logger.js b/node_modules/cw-sdk-node/build/util/logger.js
index f9678eb..bd2c973 100644
--- a/node_modules/cw-sdk-node/build/util/logger.js
+++ b/node_modules/cw-sdk-node/build/util/logger.js
@@ -30,6 +30,10 @@ class Logger {
             ]
         });
     }
+    setLogger(child) {
+        this.level = 'debug'
+        this.logger = child
+    }
     setLevel(newLevel) {
         this.level = newLevel || defaultLevel;
     }
diff --git a/node_modules/cw-sdk-node/build/websocket/StreamClient.js b/node_modules/cw-sdk-node/build/websocket/StreamClient.js
index 28f21cb..bde82c0 100644
--- a/node_modules/cw-sdk-node/build/websocket/StreamClient.js
+++ b/node_modules/cw-sdk-node/build/websocket/StreamClient.js
@@ -10,7 +10,11 @@ const proto_2 = tslib_1.__importDefault(require("./proto"));
 const WebSocketClient_1 = tslib_1.__importDefault(require("./WebSocketClient"));
 class StreamClient extends WebSocketClient_1.default {
     constructor(opts) {
-        logger_1.default.setLevel(opts.logLevel);
+        if( opts.logger ) {
+            logger_1.default.setLogger(opts.logger);
+        } else {
+            logger_1.default.setLevel(opts.logLevel);
+        }
         const streamOpts = credentials_1.loadStreamCredentials(opts);
         super(streamOpts);
         if (Array.isArray(streamOpts.subscriptions) && streamOpts.subscriptions.length > 0) {
diff --git a/node_modules/cw-sdk-node/build/websocket/WebSocketClient.js b/node_modules/cw-sdk-node/build/websocket/WebSocketClient.js
index 11175e2..7c92eb0 100644
--- a/node_modules/cw-sdk-node/build/websocket/WebSocketClient.js
+++ b/node_modules/cw-sdk-node/build/websocket/WebSocketClient.js
@@ -33,7 +33,11 @@ class WebSocketClient extends events_1.EventEmitter {
     // Default to defaultOptions
     constructor(opts) {
         super();
-        logger_1.default.setLevel(opts.logLevel);
+        if( opts.logger ) {
+            logger_1.default.setLogger(opts.logger);
+        } else {
+            logger_1.default.setLevel(opts.logLevel);
+        }
         if (!opts.creds.apiKey) {
             throw new Error('Missing credential apiKey');
         }
diff --git a/node_modules/cw-sdk-node/build/websocket/types/client.d.ts b/node_modules/cw-sdk-node/build/websocket/types/client.d.ts
index c5f36d8..15d45f7 100644
--- a/node_modules/cw-sdk-node/build/websocket/types/client.d.ts
+++ b/node_modules/cw-sdk-node/build/websocket/types/client.d.ts
@@ -4,6 +4,7 @@ export interface WebSocketOpts {
     creds: Credentials;
     reconnect: ReconnectOpts;
     logLevel?: LogLevel;
+    logger?: any;
     nonce?: string;
 }
 export interface ReconnectOpts {

Note, the debug level is being enforced because child-logger has it's own detached level handling which may not be in-sync with the loglevel specified in the lib. So we shoot all logs to winston and let it decide whether to post them or not.

markerUpdate.side is almost always buy

On some of the trades that I do subscribe to (for example: exchanges:3:trades). There are only 'buy' trades received onMarketUpdate event and no 'sell' trades.

How can I resolve this issue?

Type mismatch between Period and getOHLC response.

When I accessed getOHLC response with period option values, I got an implicit any error.
Example code:

      const xxxUsdtOhlc = await cwClient.getOHLC('xxx', `xxxusdt`, {
        before: 1615523000,
        after: 1615523000,
        periods: '3600',
      });
     console.log(xxxUsdtOhlc['3600'][0].closePrice); // Implicit any error at ['3600']

It looks like there are mismatch between type Period and getOHLC response.
The current type Period definition and getOHLC response are following.

Type definitions:

getOHLC(exchangeSymbol: string, pairSymbol: string, options?: OHLCOptions): Promise<MarketOHLC>;

export declare type MarketOHLC = {
    [period in Period]: CandleData[];
};

export declare type Period = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '12h' | '1d' | '3d' | '1w_Thursday' | '1w_Monday';

getOHLC response:

{
 3600: [{
  closePrice: '130' 
  closeTime: 1615523000 
  highPrice: '131'
  lowPrice: '129'
  openPrice: '130'
  quoteVolume: '19609000'
  volume: '150513'
 }],
 ...
}

Is it possible to create orders with this API?

I didn't see this on the docs, but is it possible to create orders with this API? I'm looking create orders on kraken based on market data. For example i'd like to make orders based on SMA and EMA.

Additionally, is it possible to enable discussions on this project to encourage sharing?

marketData.intervals are always empty

I'd like to get latest candlestick data.
https://docs.cryptowat.ch/websocket-api/data-subscriptions/ohlc-candlesticks

When I subscript the ohlc, marketData.intervals are always empty.
So I cannot receive any ohlc data.

import { StreamClient, RESTClient } from 'cw-sdk-node';
const rc = new RESTClient();
const streamClient = new StreamClient({
  creds: {
    // These can also be read from ~/.cw/credentials.yml
    apiKey: '<your api key>',
    secretKey: '<your secret key>'
  },
  subscriptions: [
    ''markets:579:ohlc'
  ]
});

async function run() {
  const markets = await rc.getMarkets();
  const marketCache = {};
  markets.forEach((market) => {
    marketCache[market.id] = market; // Cache all market identifiers
  });

  // Listen for received trades and print them
  streamClient.onMarketUpdate((marketData) => {
      if (marketData.intervals) {
        // XXX always empty ???
        console.log('marketData.intervals', JSON.stringify(marketData.intervals, null, 2))
      }
  });

  // Connect to stream
  streamClient.connect();
}

run().catch((e) => {
  console.error(e);
});

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.