Coder Social home page Coder Social logo

Comments (4)

ainestal avatar ainestal commented on June 8, 2024

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.

hugues31 avatar hugues31 commented on June 8, 2024

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.

Peltoche avatar Peltoche commented on June 8, 2024

@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.

hugues31 avatar hugues31 commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.