coinbase / coinbase-exchange-node Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED — Use gdax-node
License: MIT License
DEPRECATED — Use gdax-node
License: MIT License
[ { id: 'BTC-USD',
base_currency: 'BTC',
quote_currency: 'USD',
base_min_size: 0.01,
base_max_size: 10000,
quote_increment: 0.01,
display_name: 'BTC/USD' } ]
Double-quotes should be used around the component names.
I tried creating an authenticated client like so:
var authedClient = new CoinbaseExchange.AuthenticatedClient(Env.ACCESS_KEY, Env.SECRET_KEY, Env.PASSPHRASE_KEY, Env.REST_URL);
Where Env.REST_URL is the url to the sandbox API:
https://api-public.sandbox.exchange.coinbase.com
When I try to get the accounts it fails with the timestamp error:
authedClient.getAccounts(function(error, response, data){
...
});
{"statusCode":400,"body":"{"message":"request timestamp expired...
Do any other options need to be set to use this with the sandbox?
Currently, the orderbook doesn't change state when connection is lost, so client code doesn't have an opportunity to reopen the connection.
Normally, this problem can be fixed by implementing simple heartbeat functionality, but it seems Coinbase websocket API doesn't yet support ping/pong events.
Hello,
I can only get {message: 'Invalid API Key'}
from the authClient.getOrders()
response body for some reason.
The returned status code is 400
Generated and copied the API key from gdax.com/settings into:
var authClient = new CoinbaseExchange.AuthenticatedClient(key, b64secret, passphrase)
My callback code looks like this:
authClient.getOrders(function(err, response, data){
if(err){
console.log("Error getting orders:", err);
}
else{
console.log("statusCode: ", response.statusCode);
console.log(data);
}
});
Public methods are working fine, such as authClient.getProductOrderBook()
.
Any ideas why this is? Am I missing something? From your docs it shows that the statusCode should be 401 not 400 for this type of response.
Thanks!
traderbot.core> ((.-getProducts (cb.PublicClient.)) (fn [_ _ _] nil))
#object[TypeError TypeError: self.makeRelativeURI is not a function]
TypeError: self.makeRelativeURI is not a function
at prototype.request (/Users/jonathan/Documents/SourceCode/traderbot/clojure/node_modules/coinbase-exchange/lib/clients/public.js:58:40)
at apply (/Users/jonathan/Documents/SourceCode/traderbot/clojure/node_modules/coinbase-exchange/node_modules/lodash.partial/node_modules/lodash._createwrapper/index.js:72:25)
at wrapper (/Users/jonathan/Documents/SourceCode/traderbot/clojure/node_modules/coinbase-exchange/node_modules/lodash.partial/node_modules/lodash._createwrapper/index.js:415:12)
at prototype.getProducts (/Users/jonathan/Documents/SourceCode/traderbot/clojure/node_modules/coinbase-exchange/lib/clients/public.js:70:26)
at eval (eval at figwheel$client$utils$eval_helper (/Users/jonathan/Documents/SourceCode/traderbot/clojure/target/server_dev/figwheel/client/utils.cljs:46:5), <anonymous>:1:140)
at eval (eval at figwheel$client$utils$eval_helper (/Users/jonathan/Documents/SourceCode/traderbot/clojure/target/server_dev/figwheel/client/utils.cljs:46:5), <anonymous>:11:3)
at eval (eval at figwheel$client$utils$eval_helper (/Users/jonathan/Documents/SourceCode/traderbot/clojure/target/server_dev/figwheel/client/utils.cljs:46:5), <anonymous>:16:4)
at figwheel$client$utils$eval_helper (/Users/jonathan/Documents/SourceCode/traderbot/clojure/target/server_dev/figwheel/client/utils.cljs:46:5)
https://github.com/coinbase/coinbase-exchange-node/blob/master/lib/orderbook_sync.js#L110
I think it will break for orders that do received => match => done because the order is not in the orderbook
edit: my bad, the maker order has to be in the book
I couldn't find any documentation for closing a websocket
I'm using Node.js. A simple example would be opening a websocket, then once the first message is received, close the connection. This would essentially mean "listen until you receive one, and only one message." Is this possible?
var CoinbaseExchange = require('coinbase-exchange');
var websocket = new CoinbaseExchange.WebsocketClient();
websocket.on('message', function(data) {
console.log(data);
websocket.done(); // or .close();
});
When the socket connection is lost, OrderbookSync ends up in a stale state (it does not attempt to re-connect and thus also stops updating the underlying orderbook).
One option would be to use / implement a reconnecting-websocket instead of using the standard WebSocket, see e.g.: https://github.com/joewalnes/reconnecting-websocket/blob/master/reconnecting-websocket.js
Hello,
how I can transfer funds via coinbase-exchange api?
Readme example of Orderbook Sync
var CoinbaseExchange = require('coinbase-exchange');
var orderbookSync = new CoinbaseExchange.OrderbookSync();
console.log(orderbookSync.book.state());
only returns { asks: [], bids: [] }
. Should it be return the snapshot of order book?
Now that gdax.com officially replace exchange.coinbase.com, we should avoid endpoint redirection on the library, and decides on the new name for this library.
Looks like the request data is already parsed by the time it hits the JSON.parse(data) call in makeRequestCallback. I am seeing it throw an exception with the following data being returned:
[ { id: 'BTC-USD',
base_currency: 'BTC',
quote_currency: 'USD',
base_min_size: 0.01,
base_max_size: 10000,
quote_increment: 0.01,
display_name: 'BTC/USD' } ]
SyntaxError: Unexpected token o
This same error is happening with all the product related API calls. Also I am using the sandbox, so not sure if it is different on the live exchange.
On the public sandbox, I was noticing that the websocket client was exiting while trying to listen to messages. By default there is a 1 minute timeout and the connection will close if no messages are sent/received over this period.
Any idea if the websocket will support ethereum prices in near future?
When using the module in node-webkit I encountered an issue related to having multiple contexts:
<html>
<body>
<script>
var coinbase = require("coinbase-exchange");
var publicClient = new coinbase.PublicClient();
publicClient.getProductTicker(function(err, resp, data){
//this anonymous callback function is created in webkit context
});
</script>
</body>
</html>
In the public client and authenticated client, for example:
..checking if the callback is an instanceof
Function
will evaluate to false
and thus throwing an error.
The explanation for this behaviour is in the nwjs docs:
https://github.com/nwjs/nw.js/wiki/Differences-of-JavaScript-contexts#working-around-differences-of-contexts
Hi,
Using help of https://github.com/coinbase/coinbase-php, i am trying to post order.
It's working correctly in my local server.
But when i upload to our server, we are getting error message 'request timestamp expired'.
Using this url(http://lazybux.com/info.php), you can see our server configuration.
require DIR . '/vendor/autoload.php';
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$configuration = Configuration::apiKey('Our API Key', 'Our API Secret');
$configuration->setApiUrl(Configuration::SANDBOX_API_URL);
$client = Client::create($configuration);
use Coinbase\Wallet\Enum\Param;
use Coinbase\Wallet\Exception\TwoFactorRequiredException;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Resource\Checkout;
use Coinbase\Wallet\Value\Money;
use Coinbase\Wallet\Resource\Order;
try {
$order = new Order([
'name' => 'Order #12',
'amount' => new Money(4, 'USD'),
]);
$client->createOrder($order);
echo $bitCoinAddress = $order->getBitcoinAddress();
$bitCoinUrl = $order->getBitcoinUri();
?>
?
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
Can you please help us to resolve this issue?
Thank you.
The ReadMe says that getProductTrades method will work without providing an argument object specifying pagination details. However, that returns an error of /coinbase-exchange/lib/clients/public.js:54 throw "Must supply a callback."
publicClient.getProductTrades(callback);
// To make paginated requests, include page parameters
publicClient.getProductTrades({'after': 1000}, callback);
This could be resolved by 1.) updating the ReadMe to remove the example in the first line above that shows it being optional, 2.) or the lib could be updated to check if type is an object or a function, if it is a function then to use a default value for the pagination.
I can submit a pull request for option 2 if this is the desired solution. Let me know.
Hello guys , i'm trying to create a real time app to track the real time bitcoin ask and bid price on coinbase , but every time my source unsync the actual price , can any one tell me what can i do to make it precise with the actual price bid and ask price, here goes my source:
`var CoinbaseExchange = require('coinbase-exchange');
var websocket = new CoinbaseExchange.WebsocketClient();
bid =0;
ask =0;
websocket.on('message', function(data) {
if(data.side == 'sell')
{
if(data.price > bid )
bid = data.price;
}else{
if(data.price > ask)
ask = data.price;
}
if(data.type == 'match')
{
ask = data.price;
bid = data.price;
}
console.log('BID:'+bid+' ASK:'+ask);
});`
i'm really confused of how to track the current bid / ask price , pelase help me
As in title says. Thanks.
OrderbookSync throws an error inside an internal callback (when the getProductOrderBook does not successfully fetch the orderbook), see e.g. the line:
throw 'Failed to load orderbook: ' + err;
in lib/orderbook_sync.js. This error is thrown, for instance, when there is no internet connection.
It is not easy to catch this kind of error in a client application. One option how to fix this problem would be to emit the error (instead of throwing it), e.g.:
self.emit('error', 'Failed to load orderbook: ' + err);
return;
Are you guy planning on updating the npm?
If I try to determine the best bid and offer (BBO) prices at a point in time that is between receiving a 'received' message and a 'match' message, I could observe a crossed order book.
For example, if we see a 'received' message for a buy order that is priced above the best offer, the bid will be added to the orderbook which will create a crossed market until we see a 'match' message (or the 'done' message that follows if we're strictly comparing prices and not excluding zero-quantity orders).
I'm not sure what the best solution is. I'm not suggesting ignoring 'received' messages because that would lead to having 'match'es involving orders you never saw. Maybe there could be some sort of pending book?
I'm taking a look at the change method in orderbook.js and it looks like its assuming that every time a change message is received, the order must be in the order book.
According to https://docs.exchange.coinbase.com/ that may not be the case: 'change messages for received but not yet open orders can be ignored when building a real-time order book.'
Am I missing something ?
Best regards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.