Skip to content

Commit

Permalink
added usage examples for bitcoinaverage NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
goraniliev committed Jun 14, 2017
1 parent e19f675 commit 8323e62
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 0 deletions.
29 changes: 29 additions & 0 deletions node_npm_examples/constants.js
@@ -0,0 +1,29 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var restClient = ba.restfulClient(publicKey, secretKey);

restClient.allSymbols(function (response) {
console.log(response);
});

restClient.symbolsLocal(function (response) {
console.log(response);
});

restClient.symbolsGlobal(function(response) {
console.log(response);
});

restClient.exchangeRatesLocal(function(response) {
console.log(response);
});

restClient.exchangeRatesGlobal(function(response) {
console.log(response);
});

restClient.serverTime(function(response) {
console.log(response);
});
26 changes: 26 additions & 0 deletions node_npm_examples/conversions.js
@@ -0,0 +1,26 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var restClient = ba.restfulClient(publicKey, secretKey);

// Convert from ETH to USD
var from = 'ETH', to = 'USD', amount = 3;
restClient.performConversionLocal(from, to, amount, function (response) {
response = JSON.parse(response);
console.log("At time " + response.time + " the cost of " + amount + " " + from + " is " + response.price + " " + to);
});

// Convert EUR to LTC
var fromFiat = 'EUR', toCrypto = 'LTC';
restClient.performConversionLocal(fromFiat, toCrypto, amount, function (response) {
response = JSON.parse(response);
console.log("At time " + response.time + " the cost of " + amount + " " + fromFiat + " is " + response.price + " " + toCrypto);
});

// Get price when given hash was mined
var hash = 'f854aebae95150b379cc1187d848d58225f3c4157fe992bcd166f58bd5063449';
restClient.blockchainTxPrice('BTCUSD', hash, function (response) {
response = JSON.parse(response);
console.log("1 BTC was worth " + response.average + " when the transaction of the hash " + hash + " was conducted");
});
44 changes: 44 additions & 0 deletions node_npm_examples/exchanges.js
@@ -0,0 +1,44 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var restClient = ba.restfulClient(publicKey, secretKey);

// Works only for Enterprise users
restClient.allExchangesData('BTC', 'USD', function(response) {
console.log(response);
});

// Works only for Enterprise users
restClient.allExchangeDataForSymbol('BTCUSD', function(response) {
console.log(response);
});

restClient.perExchangeData('gdax', function(response) {
console.log(response);
});


restClient.exchangeCount(function(response) {
console.log(response);
});

restClient.outlierExchanges(function(response) {
console.log(response);
});

restClient.ignoredExchanges(function(response) {
console.log(response);
});

restClient.inactiveExchanges(function(response) {
console.log(response);
});

restClient.currencyWeights(function(response) {
console.log(response);
});

restClient.exchangeWeights(function(response) {
console.log(response);
});
41 changes: 41 additions & 0 deletions node_npm_examples/history.js
@@ -0,0 +1,41 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var restClient = ba.restfulClient(publicKey, secretKey);

restClient.historyLocal('BTCUSD', 'daily', function(response) {
console.log(response);
});

restClient.historyGlobal('BTCUSD', 'daily', function (response) {
console.log(response);
});


// Getting the Unix timestamp for the moment in time 10 minutes ago from now
var now = new Date();
var minutesAgo = 10;
var tenMinutesAgo = new Date(now.getTime() - minutesAgo * 60000);
var timestamp = parseInt(tenMinutesAgo.getTime() / 1000);

// Get local history for last 10 minutes
restClient.dataSinceTimestampLocal('BTCUSD', timestamp, function (response) {
console.log(response);
});

// Get global history for last 10 minutes
restClient.dataSinceTimestampGlobal('BTCUSD', timestamp, function (response) {
console.log(response);
});

// Get the local price at the moment closest to the specified timestamp
restClient.priceAtTimestampLocal('BTCEUR', timestamp, function (response) {
console.log(response);
});

// Get the global price at the moment closest to the specified timestamp
restClient.priceAtTimestampGlobal('BTCEUR', timestamp, function (response) {
console.log(response);
});

95 changes: 95 additions & 0 deletions node_npm_examples/ticker.js
@@ -0,0 +1,95 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var restClient = ba.restfulClient(publicKey, secretKey);

// Get local ticker for BTCUSD and ETHUSD
restClient.tickerAllLocal('BTC,ETH', 'USD', function (response) {
console.log(response);
});

// Get global ticker for BTCUSD and BTCEUR
restClient.tickerAllGlobal('BTC', 'USD,EUR', function(response) {
console.log(response);
});

// Get local ticker for BTCUSD
restClient.tickerLocalPerSymbol('BTCUSD', function (response) {
console.log(response);
});

// Get global ticker for BTCGBP
restClient.tickerGlobalPerSymbol('BTCGBP', function (response) {
console.log(response);
});


// 4 examples for short ticker using the local market:
// 1. Get local short ticker for BTCUSD and BTCEUR
restClient.tickerShortLocal('BTC', 'USD,EUR', function (response) {
console.log(response);
});

// 2. Get local short ticker for BTC and all supported fiat currencies
restClient.tickerShortLocal('BTC', '', function (response) {
console.log(response);
});

// 3. Get local short ticker for all crypto currencies, represented in USD
restClient.tickerShortLocal('', 'USD', function (response) {
console.log(response);
});

// 4. Get local short ticker for all available crypto-fiat pairs
restClient.tickerShortLocal('', '', function (response) {
console.log(response);
});


// 4 examples for short ticker using the global market:
// 1. Get global short ticker for BTCUSD and BTCEUR
restClient.tickerShortGlobal('BTC', 'USD,EUR', function (response) {
console.log(response);
});

// 2. Get global short ticker for BTC and all supported fiat currencies
restClient.tickerShortGlobal('BTC', '', function (response) {
console.log(response);
});

// 3. Get global short ticker for all crypto currencies, represented in USD
restClient.tickerShortGlobal('', 'USD', function (response) {
console.log(response);
});

// 4. Get global short ticker for all available crypto-fiat pairs
restClient.tickerShortGlobal('', '', function (response) {
console.log(response);
});

// Custom ticker
// Generate price index for BTCUSD based only on the data from Bitstamp and Kraken
restClient.tickerCustomInclude('BTCUSD', 'bitstamp,kraken', function (response) {
console.log(response);
});

// Generate price index for BTCUSD based on the data from all exchanges except Bitstamp and Kraken
restClient.tickerCustomExclude('BTCUSD', 'bitstamp,kraken', function (response) {
console.log(response);
});

// Get ticker and changes for all supported symbols
restClient.tickerChangesAllLocal(function(response) {
console.log(response);
});

// Get Local Ticker and changes only for BTCUSD
restClient.tickerChangesLocal('BTCUSD', function (response) {
console.log(response);
});

// Get Global Ticker and changes only for ETHUSD
restClient.tickerChangesGlobal('ETHUSD', function (response) {
console.log(response);
});
10 changes: 10 additions & 0 deletions node_npm_examples/websocket/exchangeWebsocket.js
@@ -0,0 +1,10 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var ws = ba.websocketClient(publicKey, secretKey);

// Connecting to the Exchange websocket and printing Bitstamp data
ws.connectToExchangeWebsocket('bitstamp', function (response) {
console.log(JSON.stringify(response, null, 4));
});
10 changes: 10 additions & 0 deletions node_npm_examples/websocket/tickerWebsocket.js
@@ -0,0 +1,10 @@
const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';
var ws = ba.websocketClient(publicKey, secretKey);

// Connecting to the local ticker and printing BTCEUR price data; you can try it with 'global'
ws.connectToTickerWebsocket('local', 'BTCEUR', function (response) {
console.log(JSON.stringify(response, null, 4));
});

0 comments on commit 8323e62

Please sign in to comment.