GithubHelp home page GithubHelp logo

bitcoinaverage / api-integration-examples Goto Github PK

View Code? Open in Web Editor NEW
63.0 10.0 35.0 29 KB

Bitcoin and Ethereum price API integration examples in csharp, java, nodejs, golang, python, php and ruby

Home Page: https://apiv2.bitcoinaverage.com/

JavaScript 34.28% Python 32.28% Java 6.73% PHP 2.25% Ruby 0.83% Go 3.35% C# 20.28%
exchange-data ticker-data bitcoin ethereum python orderbook csharp javascript rest-api websocket-api

api-integration-examples's Introduction

BitcoinAverage API integration examples

Examples of how to integrate with our API in various langauges

BitcoinAverage Packages

We have published our own npm and pip packages that do the heavy lifting for you (authentication, handling requests, remembering the full urls).

NPM Package

This library enables quick and easy access to our Bitcoin, Ethereum, Litecoin, Ripple and other cryptocurrency exchange rates.

Install

npm install bitcoinaverage

Setup

Get your public and private keys from our website and you are ready to run these examples.

const ba = require('bitcoinaverage');

var publicKey = 'yourPublicKey';
var secretKey = 'yourSecretKey';

var restClient = ba.restfulClient(publicKey, secretKey);
var wsClient = ba.websocketClient(publicKey, secretKey);

Ticker Data

The response received by https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD.

The symbol_set can be one of: local, global, crypto and tokens.

The symbol can be any pair from our Full symbol list

var symbol_set = 'global';
var symbol = 'BTCUSD';

restClient.getTickerDataPerSymbol('global', 'BTCUSD', function(response) {
    console.log(response);
}, function(error){
    console.log(error);
}) ;

Exchange Data

All price data from single exchange

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

Data from all exchanges for one symbol

restClient.allExchangeDataForSymbol('BTCGBP',
    function(response){
        console.log(response);
    },
    function(err){
        console.log(err);
    });

Websocket

Connect to one of our websocket endpoints and get real-time updates for the Bitcoin Global Price Index.

Ticker websocket

wsClient.connectToTickerWebsocket('global', 'BTCUSD', function(response) {
    console.log(response);
}, function(error){
    console.log(error)
}, function(){
    console.log("websocket closed");
});

Orderbook websocket

The orderbook channel starts by sending a "snapshot" message with the current state of the orderbook. Then it is followed by "update" messages that represent the changes in the orderbook.

If the amount for an order is 0, the order has been completed, so it needs to be removed from the orderbook.

If the amount is greater than 0 then we just update value.

var symbols = ['BTCUSD', 'ETHUSD'];
var exchange = 'bitfinex';
var ORDERBOOKS = {
    BTCUSD: {},
    ETHUSD: {}
};
var symbol = '';
wsClient.connectToOrderbookWebsocket(exchange, symbols, function(response){
    symbol = respnose.data.symbol;
    if(response.data.type === "snapshot"){
        ORDERBOOKS[symbol].asks = response.data.asks;
        ORDERBOOKS[symbol].bids = response.data.bids;
     }else{
       console.log(response.data.updates);
       for (var i = 0; i < response.data.updates.length; i++){
          var item = response.data.updates[i];
         if(item.amount === 0){
            delete(ORDERBOOKS[symbol][item.side][item.price]);
         }else{
           ORDERBOOKS[symbol][item.side][item.price] = item;
         }
       }
     }
}, function(err){
console.log(err);
});

Python PIP Package

pip install bitcoinaverage

Setup

from bitcoinaverage import RestfulClient
restful_client = RestfulClient("<secret key>", "<public key>")

Ticker data

ticker_global = restful_client.ticker_all_global(crypto="ETH", fiat="USD,EUR")
print(ticker_global)

Exchange data

all_bitstamp_data = restful_client.per_exchange_data('bitstamp')
all_coinbase_data = restful_client.per_exchange_data('gdax')

all_exchange_data_gbp_brl = restful_client.all_exchange_data(crypto='BTC', fiat='GBP,BRL')

api-integration-examples's People

Contributors

carloscarvallo avatar goraniliev avatar kolevdarko 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-integration-examples's Issues

Websocket API V2

Hi all,

I try to use bitcoinaverage from NPM to using V2 method.
When I call API for get ticket by this URL: https://apiv2.bitcoinaverage.com/websocket/v2/get_ticket

and set header according to this docs https://apiv2.bitcoinaverage.com/?shell#requests

but it just take response to long and get bad gateway.

I read some notes from the docs for V2, it says:

This is an integer value representing the unix epoch. This needs to be no more than 15 seconds different than our server time for the request to pass. This prevents replay attacks. If you wish to check our server time please use the "/constants/time" endpoint.

After I follow the instruction, and test run, it just get same response (BAD GATEWAY).

Please help.

Unable to build with webpack

ERROR in ./node_modules/node-gyp-build/index.js
Module not found: Error: Can't resolve 'fs' in '/pcn/node_modules/node-gyp-build'
@ ./node_modules/node-gyp-build/index.js 1:9-22
@ ./node_modules/bufferutil/index.js
@ ./node_modules/bitcoinaverage/node_modules/ws/lib/buffer-util.js
@ ./node_modules/bitcoinaverage/node_modules/ws/lib/receiver.js
@ ./node_modules/bitcoinaverage/node_modules/ws/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/pcn/node_modules/request/lib'
@ ./node_modules/request/lib/har.js 3:9-22
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in '/pcn/node_modules/forever-agent'
@ ./node_modules/forever-agent/index.js 6:10-24
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in '/pcn/node_modules/tough-cookie/lib'
@ ./node_modules/tough-cookie/lib/cookie.js 32:10-24
@ ./node_modules/request/lib/cookies.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in '/pcn/node_modules/tunnel-agent'
@ ./node_modules/tunnel-agent/index.js 3:10-24
@ ./node_modules/request/lib/tunnel.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/pcn/node_modules/forever-agent'
@ ./node_modules/forever-agent/index.js 7:10-24
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in '/pcn/node_modules/tunnel-agent'
@ ./node_modules/tunnel-agent/index.js 4:10-24
@ ./node_modules/request/lib/tunnel.js
@ ./node_modules/request/request.js
@ ./node_modules/request/index.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/common.js
@ ./node_modules/bitcoinaverage/bitcoinaverage/clients/websocket-client.js
@ ./node_modules/bitcoinaverage/index.js
@ ./resources/assets/js/fx.js
@ multi ./resources/assets/js/fx.js

Example websocket for javascript or C#

Hi There,

I just open an example for JS and C#. And I there is no an example line of code how to use the classes or object for socket.

Im not expert on JS or C#, but can you give me complete example how to call the object or class?

Thank you

Keeping an up-to-date orderbook

that program which is given to keep an up-to-date orderbook is wrong as in the first message we receive the snapshot of the whole orderbook then we modify according to the msg received... But we actually store snapshot as an array at first(with index from 0 to 1000) and then store the price as index itself.. so the output what i m getting is wrong... what can be done?
Screenshot from 2019-10-10 17-31-13

Example code for Dart

I'm using Flutter framework with programming language Dart. Hope will see an example in that language.

Breaking change in itsdangerous lib causes problems with the PIP library

There is a breaking change in itsdangnerous 1.1 (released on Oct 26, 2018). Namely, there is no SigningAlgorithm anymore, which is used by bitcoinaverage PIP lib (_base_client.py).

Users can install an older version (itsdangerous==0.24 for instance) and that would fix the problem. However, this needs to be fixed in the library as well.

Cheers!

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.