Crypto-toolbox / bitex

Crypto-currency Exchange API Framework
MIT License
483 stars 134 forks source link

Formatter implementation using delegation (with example on bitfinex). #140

Closed bebosudo closed 6 years ago

bebosudo commented 6 years ago

Implementation of formatters (issue #129) using containment and delegation instead of inheritance. The key is in the __getattr__ method of the AbstractFormattedResponse (bitex/formatters/base.py).

Usage example:

>>> from bitex import Bitfinex
>>> resp = Bitfinex().ticker("btcusd")
>>> resp.formatted
FormattedResponse(bid=Decimal('14661.0'), ask=Decimal('14676.0'), high=Decimal('14961.0'), low=Decimal('11730.0'), last=Decimal('14661.0'), volume=Decimal('85803.14989423'), timestamp=datetime.datetime(2017, 12, 23, 16, 40, 51, 487780))
deepbrook commented 6 years ago

I'll add the final fixes today - thanks for the work you've done!

bebosudo commented 6 years ago

Replace Decimal with str in JSON parser

I'm working on that.

From #129:

I'll implement the received_at attributes inside FormattedResponse, using str as parser.

I'm also working on that ;-) I'm a bit busy with study ATM.

In the next days I'll try adding a couple more commits to solve this.

deepbrook commented 6 years ago

@bebosudo , sorry, I already added those! But have a look at the implementation, I've altered it slightly (namedtuple is now simply instantiated on the fly, and the formatting methods are no longer properties)