Coder Social home page Coder Social logo

dparlevliet / node.bittrex.api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from n0mad01/node.bittrex.api

254.0 27.0 101.0 136 KB

Node Bittrex API is an asynchronous node.js library for the Bittrex API, the data can be received either via GET request or Stream.

License: MIT License

JavaScript 100.00%

node.bittrex.api's People

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node.bittrex.api's Issues

SignalR expects cookie header to be set

My code:

bittrex = require 'node.bittrex.api'

bittrex.options
  apikey: XXX
  apisecret: XXX
  inverse_callback_arguments : true
  verbose: true

bittrex.websockets.listen ->
  console.log arguments
  console.log 'listening'

I'm getting this error:

_http_outgoing.js:487
    throw new Error('"value" required in setHeader("' + name + '", value)');
    ^

Error: "value" required in setHeader("cookie", value)
  at validateHeader (_http_outgoing.js:487:11)
  at ClientRequest.setHeader (_http_outgoing.js:496:3)
  at new ClientRequest (_http_client.js:171:14)
  at Object.request (http.js:39:10)
  at Object.request (https.js:239:15)
  at Object.get (https.js:243:21)
  at negotiateProxies (/Users/realp/projects/belfort/node_modules/signalr-client/signalR.js:154:37)
  at getBindings (/Users/realp/projects/belfort/node_modules/signalr-client/signalR.js:161:5)
  at Object._client.getBinding (/Users/realp/projects/belfort/node_modules/signalr-client/signalR.js:756:9)
  at clientInterface.client.start (/Users/realp/projects/belfort/node_modules/signalr-client/signalR.js:440:17)
  at /Users/realp/projects/belfort/node_modules/node.bittrex.api/node.bittrex.api.js:166:18
  at giveResults (/Users/realp/projects/belfort/node_modules/cloudscraper/index.js:244:5)
  at Request._callback (/Users/realp/projects/belfort/node_modules/cloudscraper/index.js:109:7)
  at Request.self.callback (/Users/realp/projects/belfort/node_modules/request/request.js:188:22)
  at emitTwo (events.js:125:13)
  at Request.emit (events.js:213:7)
  at Request.<anonymous> (/Users/realp/projects/belfort/node_modules/request/request.js:1171:10)
  at emitOne (events.js:115:13)
  at Request.emit (events.js:210:7)
  at IncomingMessage.<anonymous> (/Users/realp/projects/belfort/node_modules/request/request.js:1091:12)
  at Object.onceWrapper (events.js:314:30)
  at emitNone (events.js:110:20)
  at IncomingMessage.emit (events.js:207:7)
  at endReadableNT (_stream_readable.js:1059:12)
  at _combinedTickCallback (internal/process/next_tick.js:138:11)

But if I change this line https://github.com/dparlevliet/node.bittrex.api/blob/master/node.bittrex.api.js#L153:

opts.headers = {
  cookie: response.request.headers["cookie"] || '', // protection against undefined value
  user_agent: response.request.headers["User-Agent"]
};

... it works.

So I must have gotten into a situation where Cloudscrape is not returning a cookie because I don't need it? It worked the first few times I ran it, then I just started getting this error, so I'm assuming I'm no longer hitting the Cloudflare challenge page, so I'm not getting the cookie, but SignalR doesn't seem to like headers to have undefined values. Probably should put the || '' in there or conditionally set the headers individually in the first place.

Data Timestamps timezone?

Does anybody know what's the timezone for TimeStamps?
This is the format: 2017-09-10T23:36:00
I see a discrepancy between this timestamp and what I can see in their website's graphs. I guess it's because those graphs adapt to my timezone, but the data comes from the server.

timeout

Need to wait for response less than 20 seconds. It is possible to add timeout option?
Output sample: requested from https://bittrex.com/api/v1.1/public/getorderbook?market=BTC-XEM&depth=20&type=both in: 57.362s
Sometimes it freezes for 10 minutes until I stop it. Have no idea why.

Dose this lib support cross origin?

I use the following code
`
const bittrex = require('node-bittrex-api')

bittrex.websockets.client(function (client) {
var websocketsclient = client
websocketsclient.serviceHandlers.messageReceived = function (message) {
console.log(message)
}
websocketsclient.serviceHandlers.onerror = function (error) {
console.log('some error occurred', error)
}
})`

in my frontend pages and open it in http://localhost:8080/#/
The browser tells me that

Failed to load https://bittrex.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
node.bittrex.api.js?f5f0:164 Cloudscraper error occurred
(anonymous) @ node.bittrex.api.js?f5f0:164
node.bittrex.api.js?f5f0:165 Object

Need more info on websockets and limit orders

Hi
I want to ask a question. Suppose I place a limit buy order for certain market. Now I get uuid in immediate response. But is there way to know when the order is actually executed by the bittrex or I have keep asking bittrex for such orders(data pull). This will be a very terrible idea and will impact the application performance.
Generally platforms provide either webhook facility or sockets to listen for such events.
In case of bittrex similar thing can be achieved using sockets or pull is the last choice we are left with.
Thanks
Sameep

Immediate or Cancel

This question was asked in the other repository, but was never resolved. Does anyone know how to make a buy/sell with Immediate or Cancel option with the unofficial v2 api? If someone could just give an example of the URL to call it manually, I could implement it myself. Thanks.

Is it possible to use Websockets with private API?

I have been taking a look at the lib and did not find any way to authenticate through websockets for example to call QueryBalanceState. Is this possible at the current state of the lib?

Thanks in advance.

Error on buylimit?

Hello

My Node has been working fine for a few days and now im getting errors on buylimit?
console.log('Sending buy order ' + mercado + " - " + ammount + " - " + marketbuy);
bittrex.buylimit({market: mercado, quantity: ammount, rate: marketbuy}, function (data2, err) {
var uuid = data2.result.uuid;
});

Sending buy order BTC-SNGLS - 1314.16837782 - 0.000051135
ERROR: TypeError: Cannot read property 'result' of null

Any ideas? i logged in and there is sufficient BTC for the trade, is the second trade i get the error.

Maintaining an order book is unclear

The entire order book for a market, say, BTC-ETH, is dozens and dozens (if not more) orders outstanding. Yet, when subscribing via websockets, you only ever get a handful of orders in the Buys and Sells. I'm assuming these are changes to the order book, yet it is unclear how to maintain the state of the entire order book for a given market.

  1. What does Type mean on the returned values for the orders (there are Rate and Quantity and Type)? What is the range of values, and what does each mean?

  2. How do you build the order book and maintain it? If I make a rest call to get the current order book, how can you correlate the data in the subscription with the order book pulled down via rest? That is, how can you determine which orders were changed (or how the order book is changed by the new data)?

I'd like to maintain an order book for a given market, but the websocket feed appears mostly to be just anonymous deltas to the order book, with no way to correlate the websocket data with the restful data.

I'm sure I'm missing something, I just don't know what. Is there any additional info someone could point me to? Or is there a simple explanation for this I am lacking?

Duplicate entries using updateExchangeState

I'm trying to make a primary key for my buy, sell changes. I'm adding the coin name with the rate for my key and inserting my buy and sell into different tables. I keep getting duplicate keys for type 0 which means to add a order. I thought the rate should be unique. Is this something to do with cloud flare serving me cached copy? Bittrex's websocket serving duplicate data?

I have the under standing that if another order comes in with the same rate as one that I've already added it ether has to be Remove : 1 or a Update 2

Here's a preview of my code just for the buys

`bittrex.websockets.subscribe(['BTC-ETH'], function (data, client) {
if (data.M === 'updateExchangeState') {
data.A.forEach(function (data_for) {

        var buyers = data_for.Buys;
        var sellers = data_for.Sells;
        var fills = data_for.Fills;

        buyers.forEach(function (buyers) {

            type = buyers.Type;

            if (type === 0) {

                // get BTC amount for trade
                buyersRate = buyers.Rate.toFixed(8);
                id = data_for.MarketName+buyersRate;
                btc_amount = buyers.Rate * buyers.Quantity;

                record = {
                    id: id,
                    coin_id: data_for.MarketName,
                    rate: buyers.Rate,
                    quantity: buyers.Quantity,
                    btc_total: btc_amount,
                    time_stamp: buyers.TimeStamp
                };

                conn.query('INSERT INTO buy_orders SET ?', record, function (err) {
                    if (err) throw err;

                });

            } else if (type === 1) {

                 buyersRate = buyers.Rate.toFixed(8);
                id = data_for.MarketName+buyersRate;
                conn.query('DELETE FROM buy_orders WHERE id = ?', [id], function (err) {
                    if (err) throw err;
                });

            } else if (type === 2) {
                buyersRate = buyers.Rate.toFixed(8);
                id = data_for.MarketName+buyersRate;
                btc_amount = buyers.Rate * buyers.Quantity;
                conn.query('UPDATE buy_orders SET quantity = ?, btc_total = ?, time_stamp = ? WHERE id = ?', [buyers.Quantity, btc_amount, buyers.TimeStamp, id], function (err) {
                    if (err) throw err;

                });

            }
        });

    });
}

});`

Websocket disconnect

Hi, I know that there's been 2-3 previous issues with the websocket disconnecting and never retrying.

I'm still experiencing that every 2-3 hours even after trying all the suggestions.

How did you solve it?

Thanks!

Close websocket

Hi, actually i use
var websocketsclient = bittrex.websockets.listen(function(data) {

I'm looking for a simple way for kill this. I want stop the connection and restart when I want.

Possible to add this ? or MP for help me ?

Error 503

I'm running bittrex.websockets.subscribe.example without touching anything and I'm getting:

Error Message:  Negotiate Unknown
Exception:  undefined
Error Data:  503

Any idea on what's going on?

Thanks!

More Hub Events

Hi guys, correct me if I'm wrong: but, looking at https://bittrex.com/signalr/hubs I can see some interestingly events that I can subscribe (?) to be notified about user balance or order closes?

I'm looking for a way to implement this events, but I'm studying how signalr works, so, someone can take a look to see if is possible to implement this events on node.bittrex.api?

I think this is the same events that notify user on top-right popup when a order is filled. I'm right?

Minimal NodeJS version

In package.json it has a target version of node as 0.10+. Are we really should support such old engine version?

bittrex.tradesell is not a function ??

I got : TypeError: bittrex.tradesell is not a function

When i try to call

var bittrex = require('node.bittrex.api'); bittrex.tradesell({ MarketName: DesiredPair, OrderType: 'LIMIT', Quantity: amount, Rate: rate, TimeInEffect: 'GOOD_TIL_CANCELLED', // 'IMMEDIATE_OR_CANCEL', 'GOOD_TIL_CANCELLED', 'FILL_OR_KILL' ConditionType: 'NONE', // supported options are 'NONE', 'GREATER_THAN', 'LESS_THAN' Target: 0, // used in conjunction with ConditionType }, function( data, err ) { console.log( data ); });

getbalances work fine, i dont understand

Intermittent failure to connect

This seems to have stopped working sometimes. I'm intermittently getting

Error Message:  Negotiate Unknown
Exception:  undefined
Error Data:  503

and

start::unknown (503)

This is both locally and on vultr. It happens with both the version in npm, and this git version.

I'm using the code from the example, which was working fine a few days ago:

bittrex.websockets.listen(function (data, client) {
	if (data.M === 'updateSummaryState') {
		data.A.forEach(function (data_for) {
			data_for.Deltas.forEach(function (marketsDelta) {
				console.log('Ticker Update for ' + marketsDelta.MarketName, marketsDelta);
			});
		});
	}
});

and

bittrex.websockets.subscribe(['BTC-ZEN'], function(data, client) {
  if (data.M === 'queryExchangeState') {
    data.A.forEach(function(data_for) {
      console.log('Market Update for '+ data_for.MarketName, data_for);
    });
  }
});

and

bittrex.websockets.client(function() {
  console.log('Websocket connected');
  bittrex.websockets.subscribe(['BTC-ETH'], function(data) {
    if (data.M === 'updateExchangeState') {
      data.A.forEach(function(data_for) {
        console.log('Market Update for '+ data_for.MarketName, data_for);
      });
    }
  });
});

If I keep repeatedly trying to run it, it eventually connects.

Related to #2 ?

Creating multiple websockets

Hello!

I am looking for a way to create separated readers for 'market' and 'global' queue. As far as I understand node.bittrex.api use single wsclient.
Is there any reason to choose such design over creating multiple clients?

Thanks

Timeout API requests

Any way we can put a time-out on the API requests?

requested from https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-NEO in: 0.865s write point success getmarketsummary requested from https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-NEO in: 370.385s write point success getmarketsummary

This one took quite long, is it possible to stop waiting for the request and run into a time-out?

buylimit returns null

Hi guys, I'm trying to make a standard buy trade and getting null in response.
getbalances and getticker calls work great.
API permissions all enabled.
Tried also v2 tradebuy with the same result.

Thanks in advance.

`
const bittrex = require('node.bittrex.api');

bittrex.buylimit({
market : 'BTC-LTC',
quantity: 1.2,
rate: 1.3
}, (data) => {
console.log(data); // Output: null
});
`

Cannot get data from bittrex.getbalances (0.7.6)

When I call getbalances I'm getting err message like below. Any help is appreciated.

yarn add node-bittrex-api
var bittrex = require('node-bittrex-api');

bittrex.options({
    'apikey' : '...',
    'apisecret' : '...'    
});

bittrex.getbalances( function( data, err ) {
     _this.balances = JSON.stringify(err);
});

output

{"success":false,"message":"URL request error","error":{}}

corehub.SubscribeToExchangeDeltas

There was an error invoking Hub method 'corehub.SubscribeToExchangeDeltas'.
Just got this. Is this a general problem, or is it just me?

Connection aborted?

Hey,

Before you made the fork i had the following code

websocketsclient.serviceHandlers.disconnected = function (websocket) { setImmediate(function () { console.log("trying to reconnect"); websocketsclient.start(); }); };

now it tells me websocketsclient is undefined and my connection gets aborted and i am not able to reconnect it

Returning data from getmarketsummary

Silly question and I am new to JS so please forgive me, but when I run the following, it keeps giving me undefined:

`var LTCdata = bittrex.getmarketsummary( { market : 'BTC-LTC'}, function( data, err ) {
return data;
});

console.log(LTCdata);`

I want to append the LTC market data to array LTCdata - how would I go about doing that?

Thanks.

Making bittrex websocket api work in python

Hello. Sorry if this is out of place. I tried emailing n0mad01 and he suggested i ask here. I am trying to get the websocket api working in python as that is the language i'm working with. Mostly, i want to get a live orderbook feed working. I am using 'signalr-client'(https://pypi.python.org/pypi/signalr-client/0.0.7). I have looked at the bittrex docx but i can't get it working.

from requests import Session
from signalr import Connection
import time

markets = ['BTC-DGB', 'BTC-STRAT']

with Session() as session:
	connection = Connection('http://socket.bittrex.com/signalr', session)

	corehub = connection.register_hub('coreHub')
	connection.start()

	#create new chat message handler
	def print_received_message(data):
		print(data)
		# if data['Nounce'] is not None:
		# 	print('Nounce', data['Nounce'])

		# if data['Deltas'] is not None:
		# 	for value in data['Deltas']:
		# 		print(value)

	#create error handler
	def print_error(error):
		print('error: ', error)

	# debug information, show all data
	def print_raw_data(*args, **kwargs):
		print (args, kwargs)

	connection.received += print_raw_data

	with connection:
		corehub.server.invoke('SubscribeToExchangeDeltas', ['BTC-ETH'])

	corehub.client.on('updateSummaryState', print_received_message)

	connection.error += print_error

	connection.wait(1)
 
while True:
	pass

Understanding Tick Values

When I request tick data, one of the values that bittrex.websockets.listen returns is:

[...]
market: 
  ...
  Volume: 47443.44238722,
  BaseVolume: 3351.7937059,
  ...
[...]

I don't really understand these 2 values. They don't change much overtime.

I'm trying to parse this tick data into OHLCV data.
The OHLC part I got it covered,
but the Volume part is still a mistery to me.
I'm not sure how to calculate the total volume traded for in a given minute based on the Volume and BaseVolume values provided.

Thanks

getOrderHistory method not working

I'm using getorderhistory method, but I get an error 404.

It seems that the method is using baseUrl=v2.0 and there's nothing on v2 with that method name.
for v1.1 it works.

You can try the url below with your apiKey
https://bittrex.com/api/v2.0/account/getorderhistory?apikey=xxxxxxxxXXXXxxxxx&nonce=1505344665

Thoughts?

What if Cloudflare cookie is expired?

In my experience Bittrex resets CloudFlare's cookie every few hours. Did you test this? May be we need to renew the cookie after disconnection.

Btw // seems like they disabled CloudFlare for now.

Error: "value" required in setHeader("cookie", value)

node bittrex.websockets.listen.example.js

Connecting ....
_http_outgoing.js:502
throw new Error('"value" required in setHeader("' + name + '", value)');
^

Error: "value" required in setHeader("cookie", value)
at validateHeader (_http_outgoing.js:502:11)
at ClientRequest.setHeader (_http_outgoing.js:511:3)
at new ClientRequest (_http_client.js:171:14)
at Object.request (http.js:39:10)
at Object.request (https.js:233:15)
at Object.get (https.js:237:21)
at negotiateProxies (/private/tmp/node.bittrex.api/node_modules/signalr-client/signalR.js:154:37)
at getBindings (/private/tmp/node.bittrex.api/node_modules/signalr-client/signalR.js:161:5)
at Object._client.getBinding (/private/tmp/node.bittrex.api/node_modules/signalr-client/signalR.js:756:9)
at clientInterface.client.start (/private/tmp/node.bittrex.api/node_modules/signalr-client/signalR.js:440:1

Any ways to get fresh data every given period?

I'm trying to get fresh data of all the markets (highest, lowest, actual) but at every given period, is there any way to achieve this? By using websocket or api calls? Thanks a lot.
I've tryeid something like this:

setInterval(function(){
	console.log("---");
	bittrex.websockets.listen( function( data ) {
		  if (data.M === 'updateSummaryState') {
			data.A.forEach(function(data_for) {
			  data_for.Deltas.forEach(function(marketsDelta) {
				console.log('Ticker Update for '+ marketsDelta.MarketName, marketsDelta);
			  });
			});
		  }
		});
},300000);

but once is triggered it keeps on dumping data, I need latest fresh data but only every 5 minutes..

Subscribing to a single market

Hi,

from the README:

This will subscribe to both the global and the specified market data. To build your candle data, order book and market history, etc. you will need to subscribe to the individual markets you wish to watch

How would you subscribe to an individual market and have the callback only receive that market?

I have something like this:

bittrex.subscribe(['BTC-ETH', function(data) {

});

But data will have markets from the other subscriptions.

Thanks!

What are the limits of this API?

What are the connections limit by api keys?

If im making a platform to connect multiple users with their apikeys.

Is there a limit of connections that i can use?

How can get all order history

I used bittrex.getorderhistory('', function(data1, err ) { // do somethings }); to get order history. But it just return 9 records. How can I fetch all order history?

ESOCKETTIMEDOUT randomly

Hello since yesterday i have a lot of ESOCKETTIMEDOUT error.

I search a lot but cant find answer did they change something to the API ?

Full log here
log.txt

Thx for you're help

onDisconnect not firing

First of all, thank you for sharing this module! I am experiencing an issue where onDisconnect is not triggered when I loose my internet connection (test by unplugging computer from the internet). Also when I turn on the verbose option there is no message notifying me about the loss of connection.

Overwriting serviceHandlers.connectionLost or serviceHandlers.disconnected doesn't work for me either. Is there something I am doing wrong?

`bittrex.options({

	'apikey' : 'key',
	'apisecret' : 'secret', 
	'inverse_callback_arguments': true,
	'verbose': true,
	'websockets': {
		
		onDisconnect: function() {
  			
  			console.log('Init: websocket disconnected not triggered');
		},
	},
});`

Thank you! Joe

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.