Bitcoin Forum

Economy => Service Discussion => Topic started by: sheld0n on November 17, 2017, 03:21:19 PM



Title: Open Source code to request crypto exchange data?
Post by: sheld0n on November 17, 2017, 03:21:19 PM
Not sure if it is the right place to ask. I want to ask if somebody know if there is an open source project or code snippet which let you integrate exchange prices (at least the bigger ones like Bittrex or Poloniex) into a web site, preferably coded in PHP or NodeJS? I mean something like a wrapper thats lets you request data from diverse exchange APIs easily.


Title: Re: Open Source code to request crypto exchange data?
Post by: sleepyminer on November 17, 2017, 03:53:51 PM
No sure if it is the right place to ask. I want to ask if somebody know if there is an open source project or code snippet which let you integrate exchange prices (at least the bigger ones like Bittrex or Poloniex) into a web site, preferably coded in PHP or NodeJS? I mean something like a wrapper thats lets you request data from diverse exchange APIs easily.


All exchanges usually have a public API, I dont know if there are any wrappers available as the data is pretty easy to access as it is.

PHP for bittrex, they obviously have more markets than BTC-LTC, They have another rest where you can see the markets. https://bittrex.com/home/api
This is just an example by the way, I would suggest using CURL in php instead of file_get_contents
Code:
<?php

$oBittrexObj 
json_decode(file_get_contents("https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC"), 1);

echo 
number_format($oBittrexObj['result']['Last'], 8);

Node using node-rest-client lib which you can install from npm
Code:
var Client = require('node-rest-client').Client;
var client = new Client();

var args = {
    headers: { "Content-Type": "application/json"}
};

client.get("https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC", args, function (data, response) {
   console.log(data.result.Last);
});

Also some other things to take into account. Storage for the last value, Its not always a good idea to get the data directly from the website as it may be unavailable and it uses un-needed requests. A good practice is to store the data in a db and fetch every 30 seconds or minute. If the api is unavailable at least you can still show the data from the db until the api is reachable again.



Title: Re: Open Source code to request crypto exchange data?
Post by: bL4nkcode on November 17, 2017, 03:56:43 PM
Maybe your referring like coinmarket's and cryptonator api for some cryptocurrency's price and coins volume or some rates from different exchanges.
Link
Cryptonator: https://www.cryptonator.com/api
Coinmarketcap: https://coinmarketcap.com/api/

Just correct me if I understand it mistakenly.