Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Pair formatter, really useful? #185

Open
firepol opened this issue Apr 25, 2018 · 1 comment
Open

Pair formatter, really useful? #185

firepol opened this issue Apr 25, 2018 · 1 comment

Comments

@firepol
Copy link

firepol commented Apr 25, 2018

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
Copy link
Collaborator

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants