Crypto-toolbox / bitex

Crypto-currency Exchange API Framework
MIT License
484 stars 136 forks source link

Pair formatter, really useful? #185

Open firepol opened 6 years ago

firepol commented 6 years ago

Hi, I get the idea of this project, to have standardized methods and also standardized responses. I also like the idea to standardize the pairs, as one exchange uses BTCUSD, another BTC/USD, another btcusd etc. which is quite a mess...

What is a bit strange to me, is to have classes for pairs. I don't understand why should I use a "strong type" for something that basically is a string. I also see that in some interfaces the formatting is a bit weird and doesn't really look useful, I mean e.g.

            pair = pair.format_for(self.name)
            try:
                pair = pair.format_for(self.name)
            except AttributeError:
                pair = pair

I saw his kind of try/catch in several interfaces and I was wondering why was it like that, then I tested and noticed, that if I pass a string for the pair, it raises an exception, which was not really expected...

Why not having an extension format_for method for string, instead? This can be handy for exchanges with hundreds of pairs, like binance, bittrex. Creating all pairs as objects is not really necessary on my opinion, not even if you can automate this, as every day there are new pairs...

Ideally the formatter should convert a standard string in a string that the exchange wants.

I'd just have a formatting method expecting one of those standard way:

BASE-QUOTE, where "-" could be a different separator, like /, _ etc. like this it wouldn't be needed to create hundred of classes like this one:

class ETHBTCFormatter(PairFormatter):
    """ETH/BTC PairFormatter object."""

    def __init__(self):
        """Initialize the Formatter instance."""
        super(ETHBTCFormatter, self).__init__('ETH', 'BTC')

This looks hard to maintain, especially if you think that every week there are new pairs added to exchanges like binance, and sometimes some pairs are dropped.

A rule based method (e.g. regular expression: word[-_/]word) would allow basicallythe extracion of base and quote for any pair, without any maintenance required.

deepbrook commented 6 years ago

Hey @firepol , good thinking! The classes like ETHBTCFormatter were created for convenience, in order to have some commonly occurring pairs already provided as a formatter object.

I like the idea of extending the str class, though. If you'd like to submit a PR for this, I'd be happy to have a look at it.