• Resolved donk3y

    (@donk3y)


    Dear Alex,

    first of all great plugin. I’m trying to figure out how to get exchange rates data to my custom plugin I’m developing for a client, and despite the detailed documentation, I got lost, I looked around in the forum but found no leads, and going through your whole plugin, would take precious time, which I don’t have a lot at this moment.

    So far I got to the point that my plugin works, I don’t get reference errors, and the appropriate currencies are loaded (via dsWallets.vs_currencies). now I’m trying to figure out how to get and display the conversion rates (example BTC – USD) on the public front-end and use the exchange rate values to do some form calculations thus I can’t rely on the shortcode. Do you have any tips on how should I proceed?

    Thanks for your kind help in advance.

    Daniel

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author dashed-slug.net

    (@dashedslug)

    Hello,

    Let’s take for example BTC:

    1. Go to the currency that represents BTC, and ensure that the Coingecko ID is set correctly (bitcoin) in this case.
    2. Go to SettingsBitcoin & Altcoin WalletsExchange Rates and select USD. This indicates that you are interested in the exchange rates of various currencies against USD. These are the “VS Currencies”.
    3. Now the cron jobs, if running, will keep the exchange rates for bitcoin updated. You can verify if the cron jobs are running from DashboardBitcoin and Altcoin WalletsDebugCron jobs last ran on. You can also check to see the exchange rates in the Currency editor.
    4. Use the [wallets_rates] shortcode to display a list of currencies enabled on your system, which should include BTC. Clicking on the exchange rate will rotate between the exchange rates to the various VS currencies.
    5. In other UIs, wherever there is a value for Bitcoin, there will also be a gray value in italics below it. This is also clickable, and will rotate between all the VS Currencies that are enabled. This way the user can select to see amounts both as they are, and converted to the currency that the user is comfortable with.
    6. It is also possible to retrieve the exchange rates via the plugin’s WP-REST API for use in JavaScript. The endpoints that retrieve currencies (e.g. /dswallets/v1/currencies) will also retrieve the exchange rates of the currencies against all VS Currencies. Let me know if you need any help with this. The documentation for accessing the WP-REST API is at: Wallets Admin DocsDeveloper ReferenceWallet APIsWP-REST-API.

    Hope this helps. Please do ask me here again, if you need anything else about exchange rates. If you have a question about a separate topic, please open a new thread.

    with regards,

    Alex

    Thread Starter donk3y

    (@donk3y)

    Dear Alex,

    Thank you for your quick response and helpful answers! My inquiry is focused more on your 6th point: WP-REST API. Now, I’m still in the process of getting a grasp of REST API, not going to lie. But here’s what I’m trying to do:

    • User the API to get current BTC – EUR and BTC – USD Exchange rates
    • Use these rates and insert them to my form and perform calculations with it.
    • Store these forms.

    and…as I’m writing this I figured it out…You’re documentation was in fact excellent and led me to the right direction. However, I’ll just note it down anyway, how I got it working in case someone else is stuck:

    jQuery.ajax( {
    url:
    ${dsWallets.rest.url}dswallets/v1/users/${dsWallets.user.id}/currencies,
    cache: false,
    method: 'GET',
    headers: {
    'X-WP-Nonce': dsWallets.rest.nonce,
    },
    success: function( response ) {
    console.log( response );
    // TODO do your thing here with the response
    // For getting Euro exchange rates:
    console.log(response[0].rates['eur'])
    },
    } );

    this will be the JS file. And the object you’re looking for is in ‘response’. in my case it was response[0].rates[‘eur’].

    Thank you again Alex, you were a great help!

    Best regards,

    Daniel

    Plugin Author dashed-slug.net

    (@dashedslug)

    Hello Daniel,

    Glad you figured it out. I am closing this topic as resolved. Just a few notes:

    • You may be interested in the /dswallets/v1/currencies endpoint rather than the /dswallets/v1/users/N/currencies endpoint, if you don’t need the user balances. Computing balances takes some non-trivial time (and some extra space in the responses).
    • The Bitcoin currency may not always be the first element in the responsearray, so it’s safer to loop over the array elements and look for the BTC ticker symbol.

    Contact me again if you have any more questions about the plugin.

    with regards

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