GithubHelp home page GithubHelp logo

jpcx / node-kraken-api Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 15.0 1020 KB

a typed REST/WS Node.JS client for the Kraken cryptocurrency exchange

License: MIT License

JavaScript 15.43% Shell 0.86% TypeScript 83.71%

node-kraken-api's People

Contributors

jpcx avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

node-kraken-api's Issues

Error when calling addOrder method with specific parameters

Context:
I am using the addOrder method from the kraken module in a Node.js environment to place orders on the Kraken exchange.

Error Message:

Uncaught RESTAPIError: ["EGeneral:Invalid arguments:volume"]
at _UTF8Receiver.finalize (~/node_modules/node-kraken-api/index.js:978:31) {
body: { error: [ 'EGeneral:Invalid arguments:volume' ] }

Reproduction Steps:

  1. Call the addOrder method with the following parameters:
    const { txid } = await kraken.addOrder({ pair: "MATIC/EUR", type: "buy", ordertype: "limit", price: "0.9237", volume: "5" });
  2. Expect the method to successfully place the order.
  3. Encounter the error message mentioned above instead.

Expected Behavior:
I expected the addOrder method to successfully place the buy order for 5 units of MATIC/EUR at a limit price of 0.9237.

Actual Behavior:
Instead, I encountered the "EGeneral:Invalid arguments:volume" error message, indicating an issue with the volume parameter.

Environment:
Node.js version: 16.14.0
node-api-kraken module version: 2.2.2
Operating System: macOs 14.2.1 (23C71)

Additional Information:
I have tried adjusting the parameters, such as converting the volume parameter to a number instead of a string, but the error persists.

Tags/Labels:
error

Subscribing to several order books takes too long

Hi,

I'm subscribing to many orderbooks at once (more than 100) using this sample code

const book100 = await kraken.ws.book({depth: 100})
// live book construction from "snapshot", "ask", and "bid" events.
.on("mirror", (mirror, pair) => console.log(mirror, pair))
.on("error", (error, pair) => console.log(error, pair))
// resubscribes if there is a checksum validation issue (emits statuses).
.on("status", (status) => console.log(status)
.subscribe("XBT/USD", "ETH/USD", .....); // subscribe to multiple pairs at once

Most of them subscribe within a few seconds, but a few take some minutes. Any idea what could be causing this delay?

Thank you

Multiple instances

I have 2 instances of an object that use this library with different api key/secret. It seems the 2nd instance overwrites the settings for the first.
So, for example, if I get balances I always get the values from the account that was initialized last even though the api/kraken object is initialized with different key/secret.

getWebSocketsToken() throwing/rejecting with Error: ["EAPI:Invalid nonce"]

Awesome strongly typed lib, Justin... thanks for this. :) Getting this Error when calling getWebSocketsToken() (line 10 in the image). Had been seeing the same with some other REST calls I'd tried as well. My work around has been to use https://www.npmjs.com/package/kraken-api ) to get the token (and other REST calls) and then provide that token to node-kraken-api private websocket connection. Privates work like a champ after that!

Is there something I'm missing that I need to do? Nonce window for my Kraken API keys is set to 0. Tips?

(node:16640) UnhandledPromiseRejectionWarning: Error: ["EAPI:Invalid nonce"] at _UTF8Receiver.finalize (E:\slab\dev\kraken-ws-rt-work\node_modules\node-kraken-api\index.js:915:31) at IncomingMessage.<anonymous> (E:\slab\dev\kraken-ws-rt-work\node_modules\node-kraken-api\index.js:1081:29

node-kraken-api-nonce-issue1
)

Unexpected behavior

Hello,

For a few days I have been receiving an error on my code which has been working for some time and I cannot find what is causing the problem

Using the exportStatus method I have a return EGeneral:Invalid arguments

the only arguments is a string report, I hardly see how I can be wrong on this arguments

here is my test code (is the same on my original code):

import { Kraken } from 'node-kraken-api'

const apikey = {
  pubKey: '************.....',
  privKey: '************.....',
}

const apiKraken = new Kraken({
  key: apikey.pubKey,
  secret: apikey.privKey
});

(async () => {
  try {
    const balance = await apiKraken.balance();
    console.log(balance) // Good
    const status = await apiKraken.exportStatus({ report: "ledgers" });
    console.log(status) // Error
  } catch (error) {
    console.error(error)
  }
})();

This is the returned error:

PS tests> node .\test.js
RESTAPIError: ["EGeneral:Invalid arguments"]
    at _UTF8Receiver.finalize (node_modules\node-kraken-api\index.js:915:23)
    at IncomingMessage.<anonymous> (node_modules\node-kraken-api\index.js:1081:21)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1334:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  body: { error: [ 'EGeneral:Invalid arguments' ] }

I specify that I made several tests with the same code by asking balance for example and using another api key, the code works well for balance and my file is saved in UTF8

Thank you for the time to see if on your side the error is also returned

Add TypeScript types

Howdy,

Sweet project! I'm just now checking it out, and have to say it would be much easier to prototype with some static TypeScript types.

Not sure if this repository is actively maintained (last commit 3 years ago), if not then DefinitelyTyped would be the best option forward

Opening this issue to track interest and any effort towards this goal

UnhandledPromiseRejection by using kraken.ws.openOrders({ token: token! }).subscribe()

Hi Justin,

Thanks for the awesome work.

When i was using subscribe function from websocket, it basically return:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
code: 'ERR_UNHANDLED_REJECTION'
}

Even adding catch() doesn't help on this case.

Any help would be appreciated

WS OHLC subscribe does not return all informations

Hi I notice that subscribing on ohlc using web socket does not return all data.

this.krakenClient.ws.ohlc({interval: topic.interval})
        .on('update', (update, pair) => {
          this.processOhlcMessage(update, pair)
        })
        .on('status', (status) => {
          this.logger.log(`${status.event}, ${status.channelName} for pair ${status.pair} = ${status.status}`)
        })
        .on('error', (error, pair) => {
          this.logger.error(`Unable to get ohlc data from Kraken for pair: ${pair.pair}`, error.stack)
        })
        .subscribe(...topic.pairs)

on update event will return array of data and pair defined here https://docs.kraken.com/websockets/#message-ohlc but it will not return channel name. Chanell name is important because we can extract interval from it, for example ohlc5-1440, we know that this is update for interval 1440.
It is even better if we can have third parameter return on update event for ohlc which is interval specified for which we are getting response, or simply return channel name with array and pairs.

get balance example

hi there,

I am calling the api with the following code, but get the error :
Error: EAPI:Invalid nonce

Can you please point out what I am doing incorrectly ?

#!/usr/bin/env node
const fs = require('fs');

const kraken = require('node-kraken-api');

const api = kraken({
  key: fs.readFileSync('creds.key').toString('utf8'),
  secret: fs.readFileSync('creds.private').toString('utf8')
});

// api.call('Depth', { pair: 'XXBTZUSD', count: 1 })
//   .then(data => console.log(data))
//   .catch(err => console.error(err))

  api.call('Balance')
    .then(data => console.log(data))
    .catch(err => console.error(err))

Websocket only fires once

Hi!

I try to use the websockets to fetch some data from Kraken, but after the subscribe function runs properly, I don't receive any further messages. This is my code:

const kraken = new Kraken();
const subscribers: Record<string, KrakenSubscriberType> = {};

const subscribe = async (pair: string) => {
	if (typeof subscribers[pair] != 'undefined') {
		Logger.warn(`You are already subscribed for kraken's '${pair}' ticker channel!`);
		return;
	}

	subscribers[pair] = await kraken.ws
		.ohlc({ interval: 1 })
		.on('payload', (payload, pair) => Logger.info('payload', payload, pair))
		.on('update', (update, pair) => Logger.info('update', update, pair))
		.on('error', (error, pair) => Logger.info('error', error, pair))
		.on('status', status => Logger.info('status', status))
		.subscribe(pair);

	Logger.info(`Successfully subscribed to the '${pair}' kraken ticker channel!`);
};

Sample output:

[2023-06-27 21:06:17] (INFO): status {"channelID":4247,"channelName":"ohlc-1","event":"subscriptionStatus","pair":"TBTC/EUR","reqid":1687892776395,"status":"subscribed","subscription":{"interval":1,"name":"ohlc"}}
[2023-06-27 21:06:17] (INFO): Successfully subscribed to the 'TBTC/EUR' kraken ticker channel!
[2023-06-27 21:06:17] (INFO): update ["1687874734.507294","1687874760.000000","27700.00000","27700.00000","27700.00000","27700.00000","27700.00000","0.00025000",1] TBTC/EUR
[2023-06-27 21:06:17] (INFO): payload [4247,["1687874734.507294","1687874760.000000","27700.00000","27700.00000","27700.00000","27700.00000","27700.00000","0.00025000",1],"ohlc-1","TBTC/EUR"] {"channelID":4247,"channelName":"ohlc-1","event":"subscriptionStatus","pair":"TBTC/EUR","reqid":1687892776395,"status":"subscribed","subscription":{"interval":1,"name":"ohlc"}}

staking asset does not require a method param

Hi bro, i was trying to use the stake function, but it has a required param called "method", i was searching in to Kraken API documentation but i didn't find something about it.
I think in an older version it was required but now i tried removing it from the required params and it worked.

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.