schtunt / rh

A PoC suite of utilities to interface Robinhood and possibly other stock exchange APIs
0 stars 0 forks source link

Creating new columns should be done in one place #1

Open nima opened 3 years ago

nima commented 3 years ago

Right now, to add a new column, code has to be updated in too many different areas.

  1. In the API multiplexor module:

    api.py:marketcap = market_cap
  2. Twice in main, one where it's added to a "view", and another for pre-display formatting:

    rh.py:            'marketcap',
    rh.py:    'marketcap': util.color.mulla,
  3. Twice in in the slurp module, where it's both defined and typecast.

    slurp.py:        marketcap=D,
    slurp.py:                marketcap=stock.marketcap,
  4. Finally in the Stock class

    stocks.py:    def marketcap(self):
    stocks.py:        return D(api.marketcap(self.ticker))

This task is to see if the process can be made a little more lightweight and intuitive.

nima commented 3 years ago

Fields can now be defined in fields.py. The only other place that they must be referenced now, is in the views that wish to display them. This has only been tested on one randomly selected field (market cap), but enough to prove the point.

nima commented 3 years ago

Existing fields need to be migrated to the new pattern. Will keep this open as a reminder for that work.