how to get datas from a webpage or using an API

Started by RemiD, May 03, 2021, 08:31:15

Previous topic - Next topic

RemiD

hi :)

i would like to get datas from a webpage ( coingecko.com )

i would like to get the top cryptos currencies names, their values (in USD), their marketcaps, their trading volumes.

i also see that there is an API :
coingecko.com/fr/api#explore-api

i have a good understanding on how to read / analyze / write binary files or lines and strings... but no experience on how to get such datas using 'GET'...

i see that there is a PHP code example, and i have some understanding of PHP, so i am going to study this.

but is there any way to get such datas using Blitz3d or Blitzmax ?

thanks,

Derron

libcurl should ease the pain (especially with https etc). For "curl" you then will surely find some examples on the net (so what parameters have to be set etc).

https://www.coingecko.com/fr/api#explore-api

-> go to "simple" -> "price"
-> click "try out"
-> fill in id "bitcoin"
-> fill in vs_currencies "usd"
-> scroll a bit down and click "execute"


To see what is the "id" of a coin: check the section "coin" - there is a list-sample
-> https://api.coingecko.com/api/v3/coins/list
-> btc has id "bitcoin"

To see what is a potential "vs_currencies" entry:
-> https://api.coingecko.com/api/v3/simple/supported_vs_currencies
-> dollar is "usd"


so to get the price as above
https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd
or for curl
curl -X GET "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd" -H "accept: application/json"

Response (json) is:

{
  "bitcoin": {
    "usd": 58935
  }
}


In BlitzMax NG there is text.mod/json.mod - and other stuff, easy to read then.


bye
Ron



RemiD

@Derron>>thanks for the infos.

i will have to re study / experiment with HTML, CSS, JS, PHP because i am a little rusty ::)

not urgent, on my todo list...

Derron

no need to do it with php - as stated it works "easily" in BlitzMax.


bye
Ron

Kryzon

In BlitzMax you'll have to use Brucey's libcurl module and some regex (regular expression) module to parse the response text -- unless the API gives you a simple enough data like Derron posted, that you can break it apart with only the built-in BlitzMax string functions (find, split, slice, join etc.).

You have that example I posted in the cryptocurrency thread, it uses libcurl and simple string manipulation to read the response: https://www.syntaxbomb.com/index.php/topic,3949.msg347049453.html#msg347049453

Brucey's modules are statically linked (as opposed to dynamically linked, at runtime), so it builds down to a single executable where there's no need to accompany it with any external DLLs.