hugues31 / coinnect

Coinnect is a Rust library aiming to provide a complete access to main crypto currencies exchanges via REST API.
MIT License
148 stars 43 forks source link

to_string and from_str for Currency and Pair #30

Closed ainestal closed 7 years ago

ainestal commented 7 years ago

This is a convenient way to convert to String and from &str to Pair and Currency.

assert_eq!(Pair::BTC_USD.to_string(), "BTC_USD".to_string());

assert_eq!(Currency::BTC.to_string(), "BTC".to_string());

This implementation is in the generic level, transforming the common names that Coinnect uses for Currency and Pair. This may differ from specific names of specific exchanges, i.e: this will convert "BTC" to Currency::BTC, it will not convert from "XBT", as Kraken calls the Bitcoin.

This is something I'm doing directly in binaries using the library but I understand it belongs in the library itself.

ainestal commented 7 years ago

I'm also introducing tests in the source files directly.

hugues31 commented 7 years ago

Hello! What is your use case ? Because your to_string() method is just a call to the format! macro. For my usage, I'm already happy with the utils mod inside each exchanges. Using this module I can retrieve the Pair (get_currency_enum) or the String (get_currency_string) according to the rules specified by the exchange (XBT for Kraken, ...)

ainestal commented 7 years ago

Hi @hugues31 . I'm using this for 2 main reasons:

Working with strings simplifies doing this second point. Instead of having lots of nested matches is possible just to split on _. I can create a PR for this second scenario