BankersAlgo API Resources

Resources available: PHP, Python

Follow @bankersalgo

PHP - Real-time Rates API Parser

// Curl function to get the content function http_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(FALSE === ($retval = curl_exec($ch))) { error_log(curl_error($ch)); } else { return $retval; } } // Parameters $currency_base = 'EUR'; // Create some JSON $json = http_get_contents('https://bankersalgo.com/apirates2/API_KEY/API_SECRET/'.$currency_base); $obj = json_decode($json,true); // Success check $success = $obj['success']; if ($success == 'true') { // Parse date, base $date = $obj['date']; $base = $obj['base']; $rates = $obj['rates']; echo 'Date: '.$date.'</br>Base: '.$base.'</br></br>'; // Parse rates foreach($rates as $key=> $value) { // Print values print_r($key.' : '.$value.'</br>'); } // Do some conversions $usd_value = $obj['rates']['USD']; $yuan_value = $obj['rates']['CNY']; $btc_value = $obj['rates']['CRYPTO_BTC']; // 100 USD to YUAN $result = (100 * $yuan_value) / $usd_value; echo '100 USD = '.$result.' CNY</br>'; // 1 BTC to USD $result = (1 * $usd_value) / $btc_value; echo '1 BTC = '.$result.' USD</br>'; }


PHP - Real-time Calculation API Example

// Curl function to get the content function http_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(FALSE === ($retval = curl_exec($ch))) { error_log(curl_error($ch)); } else { return $retval; } } // Parameters $currency_from = 'USD'; $currency_to = 'EUR'; $amount = '150'; // Create some JSON 150 USD to EUROS $json = http_get_contents('https://bankersalgo.com/apicalc2/API_KEY/API_SECRET/'.$currency_from.'/'.$currency_to.'/'.$amount); $obj = json_decode($json,true); // Success check $success = $obj['success']; if ($success == 'true') { // Parse date and result $date = $obj['date']; $result = $obj['result']; // Print date and result echo 'Date: '.$date.'</br></br>'; echo $amount.' '.$currency_from.' = '.$result.' '.$currency_to.'</br>'; }


Python - Real-time Rates API Parser

# Import module import requests # Parameter base = 'EUR' # Set the request url url = 'https://bankersalgo.com/apirates2/API_KEY/API_SECRET/{}'.format(base) # Do the HTTP get request, verify SSL certificate response = requests.get(url, verify=True) # Decode the JSON response into a dictionary and use the data data = response.json() # Parse values if data['success'] == 'true': date = data['date'] base = data['base'] btc_value = data['rates']['CRYPTO_BTC'] usd_value = data['rates']['USD'] yuan_value = data['rates']['CNY'] print('Date:'), date print('Base:'), base print('Bitcoin rate:'), btc_value result = (100 * yuan_value) / usd_value # 100 USD to YUAN print result result = (1 * usd_value) / btc_value # 1 BTC to USD print result


Python - Real-time Calculation API Example

# Import module import requests # Parameters 150 USD to EUROS currency_from = 'USD' currency_to = 'EUR' amount = 150 # Set the request url url = 'https://bankersalgo.com/apicalc2/API_KEY/API_SECRET/{}/{}/{}'.format(currency_from,currency_to,amount) # Do the HTTP get request, verify SSL certificate response = requests.get(url, verify=True) # Decode the JSON response into a dictionary and use the data data = response.json() # Parse values if data['success'] == 'true': date = data['date'] result = data['result'] print('Date:'), date print('Result:'), result

Suggest your code

Did you code a parser for the BankersAlgo API? You can send it to us, we will share it on this page : bankersalgoapi@gmail.com

BankersAlgo, © All Right Reserved 2018 Terms of service - Privacy - Contact