Get current BTC price via Sandbox Exchange API

I currently use the following PowerShell code to query for BTC prices:

$urlAPICryptoPrice = ‘https://api-public.sandbox.exchange.coinbase.com/products/BTC-USD/ticker
$CryptoCurrentPrice = ((Invoke-WebRequest $urlAPICryptoPrice | ConvertFrom-Json).price)

However, the data that’s returned is not consistent with the prices I can watch via the website. Is there a better URL/method to get up to date and accurate info? Trying to validate my code before using it against the live environment. And yes, I know that Exchange will be deprecated for Advanced Trading sometime this year.

Thanks

Hello @Charlatat!

We recommend that you get real-time updates by connecting with the WebSocket stream and listening for match messages, rather than polling.

You can check more information on websocket channels here:

Also, we would like to let you know that the Exchange APIs (FIX, REST Websocket), will continue to be available to Exchange (Institutional) clients.

We hope this helps. Please let us know if you have any questions.

Are there PowerShell code examples on how to set this up?

Hi @Charlatat

Hope you are doing good. Unfortunately, we are limited to the resources that is available in our Public documentation here.