Question

SO I am going to integrate the dogecoin in to the my busniess website. My Products are avilable to purchase in EURO currency and for avilable to provide it in doecoin I need to convert the EURO to Dogecoin.

What I have DID: I have found the DOGECOIN API (https://www.dogeapi.com) in php. i have found that we can convert the DOGECOIN in BTC or USD. Using this :

https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1000

The above URL gives me the total USD from DOGE AMOUNT.output is : 1.13949000

My Question is : How Can i convert the EURO in DOGEAMOUNT ? I have search alot and not found any solution . please help. Thanks in Advance.

Was it helpful?

Solution

A bit messy but does the work (it uses another url to get exchanges for USD,EUR)

$doge2usd = file_get_contents("https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1");
echo sprintf("1 dogecoin => %f usd",$doge2usd);   // 1 DOGE => USD 0.00115078

$eur2usd = file_get_contents("http://rate-exchange.appspot.com/currency?from=EUR&to=USD");
$j = json_decode($eur2usd,TRUE);
$doge2eur = $doge2usd * (1 / $j["rate"]);        // 1 DOGE => 0.00083941557920536 EUR
echo sprintf("<br>1 dogecoins => %f euro, 5 dogecoins => %f euro",$doge2eur,$doge2eur*5);

$eur2doge = 1 / $doge2eur;  // 1 EUR => DOGE 1197.29
echo sprintf("<br>1 euro => %f dogecoins, 5 euro => %f dogecoins",$eur2doge,$eur2doge*5);

OTHER TIPS

The dogeapi.com API can only give you the exchange rate in BTC or USD. To get the exchange rate from XDG (is that the inofficial three-letter-code for Dogecoin? Let's just assume that) to EUR, you'll have to take two steps:

  1. Get the exchange rate from XDG to USD.
  2. Get the exchange rate from USD to EUR.

For the first one, we have DogeAPI. For the second one, I'm going to use Yahoo's API.

<?php

// how much is 1 dogecoin worth in USD?
$xdgusd = (double)file_get_contents("https://www.dogeapi.com/wow/?a=get_current_price&convert_to=USD&amount_doge=1");

// how much is 1 EUR worth in USD?
$yahoo_result = json_decode(file_get_contents("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20=%20%22EURUSD%22&format=json&env=store://datatables.org/alltableswithkeys&callback="));
$eurusd = (double)$yahoo_result->query->results->rate->Rate;

// how much is 1 dogecoin worth in EUR?
$xdgeur = $xdgusd / $eurusd;

echo "Doge in USD: " . $xdgusd . "\n";
echo "EUR in USD: " . $eurusd . "\n";
echo "Doge in EUR: " . $xdgeur . "\n";

This prints:

Doge in USD: 0.00113941
EUR in USD: 1.3713
Doge in EUR: 0.00083089768832495

Please note that this example doesn't cover details like bis/ask spread. Also, in a real system, you shouldn't query the web services with every request, but cache the result on your machine. And check if you got sane values back from the APIs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top