Open extra topbar

latest price info?

If you are new here, please see some information on how to ask for support. Thank you!

latest price info?

dashed-slug.net Forums Exchange extension support latest price info?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #4631
    dynamitemedia
    Participant

    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?

    #4636
    alexg
    Keymaster

    This 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.

    #4712
    dynamitemedia
    Participant

    if 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>";
    }
    #4715
    alexg
    Keymaster

    Thank 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 write if ( ! $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

    #4718
    dynamitemedia
    Participant

    thanks! 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

    #4727
    megeanwasson
    Participant

    Nice 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. 🙂

    #4729
    dynamitemedia
    Participant

    can you share how you did it for everyone to be able to use?

    glad it was useful

    #4731
    megeanwasson
    Participant

    Work 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');
    #4756
    dynamitemedia
    Participant

    awesome job!!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.