OpenBB-finance / OpenBB

Investment Research for Everyone, Everywhere.
https://openbb.co
Other
32.78k stars 3k forks source link

[FR] API #96

Closed kn0ll closed 2 years ago

kn0ll commented 3 years ago

What's the problem of not having this feature? GamestonkTerminal has collected a ton of useful scripts and code, but it is all directly coupled to the command line program. it would be nice to have extensible ways to create other types of visualizations or clients.

Describe the solution you would like I think the simplest and most robust near term solution would be to:

  1. pull the core data fetching logic out out of the command methods
  2. publish the package so people can tap into it programatically

fortunately, the well structured code means these types of changes are as minor as they can get. if we take stocktwits_api.py for example, you can see we never need to change code, only slightly reorganize it:

def get_messages(s_ticker):
    return requests.get(f"https://api.stocktwits.com/api/2/streams/symbol/{s_ticker}.json")

this method could now still be used by the internal messages() andbullbear() without more changes, but can also be consumed and reformatted by other programs.

Describe alternatives you've considered currently i am just maintaining a separate fork where i am extracting all these methods out. the speed at which the project is moving suggests this is not a tenable solution though.

i could also try parsing the string based output of the program, but please don't make me.

Additional information when i say "publish the package" i say this because i was unable to include GamestonkTerminal as an external package, even when using a git remote. but Python is not my native home so maybe i was doing something wrong. in any case, even if this is oversight on my part, it would still require the data fetching methods to be abstracted out before it was super useful.

while this "feature" would be useful for any program, i am personally using it to create a GraphQL API so i can power any number of other clients:

Screenshot from 2021-03-05 09-39-49

if you think this is a viable suggestion, i'd be happy to contribute to a solution. and it would enable me to separately publish the GraphQL API i made. :)

kn0ll commented 3 years ago

also, what command do i use to figure out why all my stocks are tanking right now?

aia commented 3 years ago

API is a must have for several reasons. I was also thinking about GraphQL.

aia commented 3 years ago

also, what command do i use to figure out why all my stocks are tanking right now?

You would want to look at cyclical performance. I.e. compare stock performance March 2019 to March 2020 to March 2021.

Also compare the behavior of different industries at different stages of the business life cycle. Compare the behavior of growth stocks to value stocks. Stock market vs Bonds vs Commodities.

I will be adding portfolio analysis and modeling features.

bfxavier commented 3 years ago

What if we add a boolean flag to the methods like returnRaw and if its true, just return the responses?

This way, we can keep the same code, the same logic and just check for that on every method.

kn0ll commented 3 years ago

to be totally frank...your proposal would introduce new branches to every single one of those functions. if it was my library, i'd avoid those branches at all costs. if you let me tap in at a lower level, there is no branching for you to manage.

that said, that's definitely a personal "code quality" type metric. meaning, your proposal would definitely solve my problem and enable me to do what i want! so if you are comfortable with that, so am i. :)

kn0ll commented 3 years ago

one big benefit to your solution, which mine does not support, is that you could expose returnRaw as an option from the command line as well, if you so pleased.

aia commented 3 years ago

I think logic should be decoupled from presentation.

Decoupling logic from presentation will streamline testing too.

I started doing that https://github.com/DidierRLopes/GamestonkTerminal/blob/main/gamestonk_terminal/fundamental_analysis/market_watch_api.py#L191.

We need to formalize a convention.

WP-LKL commented 3 years ago

The development going into this, is not fully harnessed unless it can be coupled to performing actual trades or provide an interface; whatever is be a locally hosted flask/django server with sqlite database or something more serious. Remember that the Bloomberg terminal isn't really a "terminal" - it is much more than that.

ChristopherJohnson25 commented 3 years ago

This would be epic. Any progress? Would love to hit this from a frontend.

DidierRLopes commented 3 years ago

Not yet, we are still adding features + refactoring code for the time being. Slowly and steady we'll get there :)

peterclemenko commented 3 years ago

Dumping to file and possibly elastic would be a killer feature as well. Being able to run it programmatically and dump to file and ES would empower a lot of options.

DidierRLopes commented 3 years ago

@kn0ll we've done a big refactoring, I think the _model.py files pretty much have the behaviour you described here.

kn0ll commented 3 years ago

@DidierRLopes awesome! i notice in the behavior directory only contains _views though, and code similar to when i submitted. is this just because they haven't been refactored yet? great work thanks!

DidierRLopes commented 3 years ago

@DidierRLopes awesome! i notice in the behavior directory only contains _views though, and code similar to when i submitted. is this just because they haven't been refactored yet? great work thanks!

Argghh was expecting you to not notice 😄 Yes, we're only missing behavioural analysis, government, and prediction technqiues I believe!

jmaslek commented 3 years ago

@DidierRLopes awesome! i notice in the behavior directory only contains _views though, and code similar to when i submitted. is this just because they haven't been refactored yet? great work thanks!

This one in particular should be done by this weekend

kn0ll commented 3 years ago

awesome, no worries! just wanted to make sure i understood what was going on. thank you all again.

piiq commented 2 years ago

This https://github.com/GamestonkTerminal/GamestonkTerminal/pull/1170 starts to address the issue

DidierRLopes commented 2 years ago

Closing this based on #1170 and subsequent work on this direction!

Looking forward to how you will make the most of our API :)