Search code examples
phpcurrencydogecoin-api

Convert Euro in Dogecoin


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.


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);