Comments (4)
In my mind I had the first option because it allows the user to handle everything and coinnect just encapsulates the exchange.
But I like the performance improvements that would arise from connecting to the exchanges in parallel, isolating the threading from the user.
from coinnect.
In your first example, the for loop:
for client in clients {
println!("res: {}", client.ticker());
}
could be made parallel easily using Futures (issue #9)
I don't see this
res = clients.ticker()
.from(Exchange::Bitstamps)
.from(Exchange::Kraken)
.exec()
.unwrap();
very convenient to use (at least for my use, I am making a trading bot, pulling public data and making private requests).
But maybe we are missing a util function that return a list of mutable Coinnect
default structs. So looping as you write:
let markets = vec!{Exchange::Bitstamp, Exchange::Kraken, Exchange::Poloniex};
for market in markets {
clients.push(Coinnect::new(market, "key", "secret", None).unwrap());
}
is not as convenient as it could be (for an application that synthesize the global market for example)
from coinnect.
@hugues31 the main goal is to avoid the use of Futures for users which could simplify a lot the code for them.
For me there is a limited number of case where the asynchronous is interesting and we can handle them in the lib like the multi-call in parallel (it's probably the only one). So exposing Futures for users is adding useless complexity. But I don't know all the use cases and this is correct only if the user want to work with synchronous code.
So yeah, finally this is a solution only if we choose not to return Futures in APIs.
from coinnect.
Did you mean (second example)
clients.add(market, "key", "secret", None).unwrap());
instead of ?
Coinnect::add(market, "key", "secret", None).unwrap())
Anyway, if I understand correctly, the generic_api.rs example becomes (with ticker returning a Future) :
fn main() {
let mut client = Coinnect::new();
client.add(Exchange::Kraken, "key", "secret", None).unwrap());
res = client.ticker(ETC_BTC)
.from(Exchange::Kraken)
.exec()
.unwrap();
println!("ETC_BTC last trade price is {}.",
res.wait().unwrap()[0].last_trade_price); // if ticker returns a Vec, since we only have 1 exchange
}
Instead of this deadly simple synchronous call:
fn main() {
let mut my_api = Coinnect::new(Kraken, "api_key", "api_secret", None).unwrap();
let ticker = my_api.ticker(ETC_BTC);
println!("ETC_BTC last trade price is {}.",
ticker.unwrap().last_trade_price);
}
As @crackcomm said in #9 the core could be asynchronous and all methods can return Future. To make it synchronous, the user just have to call wait(), it's yet simple but remains asynchronous for those who want that.
res = clients.ticker()
.from(Exchange::Bitstamps)
.from(Exchange::Kraken)
.exec()
.unwrap();
is finally no more than a wrapper around multiple asynchronous ticker and returns only when all ticker are received, so that ticker() is synchronous for the user but benefits from the asynchronous performance improvements (in case of course of multiple requests).
I think this issue should mature some more time for now
from coinnect.
Related Issues (20)
- Fix credentials format HOT 2
- Establish some workflows HOT 19
- Moving Currency and Pair to Types so all the types live under the same module HOT 5
- Use RustCrypto instead of rust-crypto HOT 4
- BTC fork HOT 3
- temporarily bypass the call rate limit in public query? HOT 10
- Prices in decimal instead of f64 HOT 8
- Replace the time library for chrono HOT 2
- block_or_continue doesn't wait the correct time
- OpenAPI & codegen HOT 7
- Improve configuration and credentials system
- Docs on docs.rs do not work anymore HOT 9
- Proposal to implement async API (Futures) HOT 37
- Next exchange to include? HOT 15
- Bitstamp API methods that require POST parameters are broken HOT 2
- Update TravisCI Rust version HOT 1
- Order type for Poloniex HOT 1
- Return type of return_order_book should not be a Map HOT 4
- Poloniex returnChartData parse error HOT 2
- Error: hmac
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coinnect.