dashed-slug.net › Forums › Exchange extension support › latest price info?
Tagged: exhange, rate, woocommerce
- This topic has 8 replies, 3 voices, and was last updated 6 years, 2 months ago by Anonymous.
-
AuthorPosts
-
October 4, 2018 at 1:25 am #4631AnonymousInactive
what is the best way to pull the latest price from the exchange?
i think it would be great to use with the woocommerce plugin that it will check latest price for example.
but i would also like to use it for just a small widget.
do you suggest a Mysql call?
October 4, 2018 at 8:01 am #4636alexgKeymasterThis is something that I plan to implement in the future.
The exchange could present an exchange rates provider to the parent plugin.
Other than that, you can get the last market price with the
wallets_api_market_summary
filter.See the accompanying phpdoc for an example of how to call it.
October 5, 2018 at 12:26 am #4712AnonymousInactiveif anyone is interested and wants to clean it up some more
$market_summary = apply_filters( 'wallets_api_market_summary', null, array( 'base_symbol' => 'BTC', 'quote_symbol' => 'TPWR', // < ----- change your coin info here ) ); // var_dump($market_summary); $ask = $market_summary->min_ask; if ($ask == " ") { echo "There are no Bids at this time. <br><br>"; } else { echo "This is the asking price : " . $ask . " BTC <br><br>"; } $bid = $market_summary->min_bid; if ($bid = " ") { echo "There are no Bids at this time. <br><br>"; } else { echo "This is the bidding price : " . $bid . " BTC <br><br>"; }
October 5, 2018 at 2:50 pm #4715alexgKeymasterThank you for sharing your code. This is indeed how you would use the exchange’s PHP API to pull the minimum bid and maximum ask prices for a market. You can also have access to the latest price exchanged with
$market_summary->last_price
.Once quick comment, you are checking for
if ($ask == " ") {
. This might work, but to be safe, I would writeif ( ! $ask ) {
. You are not interested in whether$ask
is empty but whether it is truthy or falsy. (See http://php.net/manual/en/language.types.boolean.php)kind regards
October 5, 2018 at 9:12 pm #4718AnonymousInactivethanks! yeh it was coming back “null” and that didnt work so i did that, great catch never even thought of that when i tossed it together lol
October 7, 2018 at 5:10 pm #4727megeanwassonParticipantNice bit of code 🙂
Have adapted it into a shortcode on my site and works great to display anywhere on the site where the price is needed. 🙂October 7, 2018 at 7:11 pm #4729AnonymousInactivecan you share how you did it for everyone to be able to use?
glad it was useful
October 8, 2018 at 4:59 am #4731megeanwassonParticipantWork In Progress, just taken your idea and suggestion by Alex and wrapped into a plugin.
Save into file called showcoinlastprice.php put into a folder called showcoinlastprice and zip it, then install just like you do any other plugin.
Use shortcode where ever you want last price for your coin to be shown.<?php /* Plugin Name: Show Coin Last Price Plugin URI: https://www.africawebsolutions.org Description: Show Primary Coin Last Price Version: Ver 0.001 Author: Megan Wasson Author URI: https://www.africawebsolutions.org License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html Text Domain: showcoinlastprice showcoinlastprice is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version. showcoinlastprice is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with showcoinlastprice. If not, see https://www.gnu.org/licenses/gpl-2.0.html. */ // Use ShortCode [showCOINBTCPrice] where ever you want your coins last price to show. function showCOINBTCPrice_shortcode($atts = [], $coinlastprice = null) { $market_summary = apply_filters( 'wallets_api_market_summary', null, array( 'base_symbol' => 'BTC', // < ----- change to your Base Coin Symbol info here 'quote_symbol' => 'COIN', // < ----- change to your Coin Symbol info here ) ); $coinlastprice = $market_summary->last_price; // always return return $coinlastprice; } add_shortcode('showCOINBTCPrice', 'showCOINBTCPrice_shortcode');
October 8, 2018 at 5:55 pm #4756AnonymousInactiveawesome job!!
-
AuthorPosts
- You must be logged in to reply to this topic.