ecklf / coingecko-rs

Rust library for the CoinGecko V3 API
https://crates.io/crates/coingecko
MIT License
17 stars 18 forks source link

Raw Json #5

Closed GerhardLiebenberg closed 2 years ago

GerhardLiebenberg commented 2 years ago

Hi, Is it possible for a function like token_price() to return the json received from CoinGecko, instead of the entire price struct?

ecklf commented 2 years ago

Hi, does this help? https://docs.serde.rs/serde_json/#creating-json-by-serializing-data-structures

GerhardLiebenberg commented 2 years ago

I only need one of the items in the price struct. The other 244 items can be ignored. How much does their inclusion in the struct slow down the response?

ecklf commented 2 years ago

Not sure if I can follow. Could you give me an example request?

GerhardLiebenberg commented 2 years ago

I am just running your token_price() example.

This is the output I need: data: Ok({"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": usd: Some(1.003)})

This is what I get: data: Ok({"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": Price { btc: None, btc_market_cap: None, btc24_h_vol: None, btc24_h_change: None, eth: None, eth_market_cap: None, eth24_h_vol: None, eth24_h_change: None, ltc: None, ltc_market_cap: None, ltc24_h_vol: None, ltc24_h_change: None, bch: None, bch_market_cap: None, bch24_h_vol: None, bch24_h_change: None, bnb: None, bnb_market_cap: None, bnb24_h_vol: None, bnb24_h_change: None, eos: None, eos_market_cap: None, eos24_h_vol: None, eos24_h_change: None, xrp: None, xrp_market_cap: None, xrp24_h_vol: None, xrp24_h_change: None, xlm: None, xlm_market_cap: None, xlm24_h_vol: None, xlm24_h_change: None, link: None, link_market_cap: None, link24_h_vol: None, link24_h_change: None, dot: None, dot_market_cap: None, dot24_h_vol: None, dot24_h_change: None, yfi: None, yfi_market_cap: None, yfi24_h_vol: None, yfi24_h_change: None, usd: Some(1.003), usd_market_cap: None, usd24_h_vol: None, usd24_h_change: None, aed: None, aed_market_cap: None, aed24_h_vol: None, aed24_h_change: None, ars: None, ars_market_cap: None, ars24_h_vol: None, ars24_h_change: None, aud: None, aud_market_cap: None, aud24_h_vol: None, aud24_h_change: None, bdt: None, bdt_market_cap: None, bdt24_h_vol: None, bdt24_h_change: None, bhd: None, bhd_market_cap: None, bhd24_h_vol: None, bhd24_h_change: None, bmd: None, bmd_market_cap: None, bmd24_h_vol: None, bmd24_h_change: None, brl: None, brl_market_cap: None, brl24_h_vol: None, brl24_h_change: None, cad: None, cad_market_cap: None, cad24_h_vol: None, cad24_h_change: None, chf: None, chf_market_cap: None, chf24_h_vol: None, chf24_h_change: None, clp: None, clp_market_cap: None, clp24_h_vol: None, clp24_h_change: None, cny: None, cny_market_cap: None, cny24_h_vol: None, cny24_h_change: None, czk: None, czk_market_cap: None, czk24_h_vol: None, czk24_h_change: None, dkk: None, dkk_market_cap: None, dkk24_h_vol: None, dkk24_h_change: None, eur: None, eur_market_cap: None, eur24_h_vol: None, eur24_h_change: None, gbp: None, gbp_market_cap: None, gbp24_h_vol: None, gbp24_h_change: None, hkd: None, hkd_market_cap: None, hkd24_h_vol: None, hkd24_h_change: None, huf: None, huf_market_cap: None, huf24_h_vol: None, huf24_h_change: None, idr: None, idr_market_cap: None, idr24_h_vol: None, idr24_h_change: None, ils: None, ils_market_cap: None, ils24_h_vol: None, ils24_h_change: None, inr: None, inr_market_cap: None, inr24_h_vol: None, inr24_h_change: None, jpy: None, jpy_market_cap: None, jpy24_h_vol: None, jpy24_h_change: None, krw: None, krw_market_cap: None, krw24_h_vol: None, krw24_h_change: None, kwd: None, kwd_market_cap: None, kwd24_h_vol: None, kwd24_h_change: None, lkr: None, lkr_market_cap: None, lkr24_h_vol: None, lkr24_h_change: None, mmk: None, mmk_market_cap: None, mmk24_h_vol: None, mmk24_h_change: None, mxn: None, mxn_market_cap: None, mxn24_h_vol: None, mxn24_h_change: None, myr: None, myr_market_cap: None, myr24_h_vol: None, myr24_h_change: None, ngn: None, ngn_market_cap: None, ngn24_h_vol: None, ngn24_h_change: None, nok: None, nok_market_cap: None, nok24_h_vol: None, nok24_h_change: None, nzd: None, nzd_market_cap: None, nzd24_h_vol: None, nzd24_h_change: None, php: None, php_market_cap: None, php24_h_vol: None, php24_h_change: None, pkr: None, pkr_market_cap: None, pkr24_h_vol: None, pkr24_h_change: None, pln: None, pln_market_cap: None, pln24_h_vol: None, pln24_h_change: None, rub: None, rub_market_cap: None, rub24_h_vol: None, rub24_h_change: None, sar: None, sar_market_cap: None, sar24_h_vol: None, sar24_h_change: None, sek: None, sek_market_cap: None, sek24_h_vol: None, sek24_h_change: None, sgd: None, sgd_market_cap: None, sgd24_h_vol: None, sgd24_h_change: None, thb: None, thb_market_cap: None, thb24_h_vol: None, thb24_h_change: None, try_field: None, try_market_cap: None, try24_h_vol: None, try24_h_change: None, twd: None, twd_market_cap: None, twd24_h_vol: None, twd24_h_change: None, uah: None, uah_market_cap: None, uah24_h_vol: None, uah24_h_change: None, vef: None, vef_market_cap: None, vef24_h_vol: None, vef24_h_change: None, vnd: None, vnd_market_cap: None, vnd24_h_vol: None, vnd24_h_change: None, zar: None, zar_market_cap: None, zar24_h_vol: None, zar24_h_change: None, xdr: None, xdr_market_cap: None, xdr24_h_vol: None, xdr24_h_change: None, xag: None, xag_market_cap: None, xag24_h_vol: None, xag24_h_change: None, xau: None, xau_market_cap: None, xau24_h_vol: None, xau24_h_change: None, bits: None, bits_market_cap: None, bits24_h_vol: None, bits24_h_change: None, sats: None, sats_market_cap: None, sats24_h_vol: None, sats24_h_change: None, last_updated_at: None }})

Can I replace the Price struct somehow to get only the data I need?

ecklf commented 2 years ago

Can I replace the Price struct somehow to get only the data I need?

A macro would be needed to skip serde deserialization if the Option is None. However, the current way is done intentionally so there is a possibility of error handling.

How much does their inclusion in the struct slow down the response?

It doesn't slow down the request itself, serde_json is super fast so I doubt it makes a crazy difference.

It is fast. You should expect in the ballpark of 500 to 1000 megabytes per second deserialization and 600 to 900 megabytes per second serialization, depending on the characteristics of your data