How to get an average bitcoin to USD price from different sources
How to get an average bitcoin to USD price from different sources
I created a very simple php function to get the current price of bitcoin to USD here,
//get from coin market $getCoinMarketPrice = getPrice('http://ift.tt/2qLq5pu'); $btcValues[1]= $getCoinMarketPrice[0]['price_usd']; //get from bitstamp // $getBitstampPrice = getPrice('http://ift.tt/29fu7gt'); $btcValues[2] = $getBitstampPrice['last']; //get from blockchain $getBlockchainPrice = getPrice('http://ift.tt/15HYrFZ'); $btcValues[3] = $getBlockchainPrice['USD']['last']; //get from cytptonator $getCtyptonatorPrice = getPrice('http://ift.tt/2kyBpkM'); $btcValues[4] = $getCtyptonatorPrice['ticker']['price']; $total=0; for ($i=0; $i < count($btcValues[$i]); $i++) { $total +=$btcValues[$i]; } $average = $total/count($btcValues[$i]); return $average;
This Code here above will get bitcoin prices from different sources and add them together and divide them by the total number of the source it got them from e.g
bitcoin from source from blockchain and bitpay and Xapo are 6000,5689,5997 respectively, so to get the average result we add these results and divide them by 3.
This code is working perfectly, but it's making my app very slow and sometimes Timeout. Please I need it to be refined and better than this , Thanks
http://ift.tt/2AxDw0M
Comments
Post a Comment