Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds custom Exceptions + more consistent spacing + documentation #49

Merged

Conversation

dsouzarc
Copy link
Contributor

References: #48

#47

@Jamonek
Copy link
Member

Jamonek commented Oct 26, 2017

Reviewing now!

@dsouzarc
Copy link
Contributor Author

@Jamonek I realize my formatting changes (for consistency + readability) make this PR a bit difficult to review, but my main/impacting changes were with adding custom Exceptions for invalid ticker symbols

import requests
import six

import logging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP import standard:

  1. stdlib libraries
  2. external dependencies
  3. internal imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch - just saw this here and fixed it.

I always thought it was external first so that the user/developer knew to install those first, followed by application-specific since that is next-most relevant, followed by stdlib since those were included by default.

class Bounds(Enum):
"""enum for bounds in `historicals` endpoint"""
"""
Enum for bounds in `historicals` endpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding newline for all docstrings is not required with Google/Napoleon style: http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I just did it to increase readability. Would you like me to go back and fix all of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, b/c it will make a big mess when someone comes through with sphinx to make ReadTheDocs

def logout(self):
"""logout from Robinhood
"""
Sogout from Robinhood
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - made that typo when I was using Vim

self.endpoints['instruments'],
params={'query': stock.upper()}

res = self.session.get(self.endpoints['instruments'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer old tabstop as per Kevlin Henney: https://www.youtube.com/watch?v=ZsHMHukIlJY

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as well

#Check for validity of symbol
try:
req = requests.get(url)
req.raise_for_status()
data = req.json()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace between try/except?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed --> I added it for additional readability, but I also know it's not part of the style-guide

except requests.exceptions.HTTPError:
raise NameError('Invalid Symbols: ' + ",".join(stocks)) #TODO: custom exception
raise RH_exception.InvalidTickerSymbol()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaaasss! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Finally your stamp of approval :P

interval = day + span = year
interval = week
TODO: NEEDS TESTS
def get_historical_quotes(self, stock, interval, span, bounds=Bounds.REGULAR):
Copy link
Contributor

@lockefox lockefox Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>2 args are split up b/c it's easier to add/remove/comment args in debug

Copy link
Contributor Author

@dsouzarc dsouzarc Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debatable because the line length is still under 100 characters and it's fairly easy to read/see the parameters and default parameters.

If we had more parameters or parameters with default variables or more verbose names, I would split them up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency is king. It's an easy rule to follow, and nearly every other >2 arg function looks one way.


"""

#Will be in format: 'YYYY-MM-ddTHH:mm:ss:000Z'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to Notes section in docstring instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - added

def securities_owned(self):
"""
Returns a list of symbols of securities of which there are more
than zero shares in user's portfolio.
Returns a list of symbols of securities of which there are more
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 char warning, 100 char line break. This might be too restrictive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar change --> might be more readable/concise

@lockefox
Copy link
Contributor

General notes:

@dsouzarc
Copy link
Contributor Author

Thank you for all the feedback @lockefox - I really appreciate it from a learning standpoint, and I love how attentive you are to all the details.

I implemented your changes/feedback, so please let me know what you think

@dsouzarc
Copy link
Contributor Author

@lockefox I think I fixed it now - let me know if anything else crosses your mind.

I adhered closer to: Pep 8

"""
Robinhood.py: a collection of utilities for working with Robinhood's Private API
"""
""" Robinhood.py: a collection of utilities for working with Robinhood's Private API """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note: you can do multi-line headers with RST if you want special notes

@lockefox
Copy link
Contributor

@dsouzarc your docstrings still have a leading space between """ and comments

@dsouzarc
Copy link
Contributor Author

@lockefox Okay, we should be good to go now. I didn't notice the lack of leading space as a requirement

@lockefox
Copy link
Contributor

👍

@Jamonek Jamonek merged commit 06e94c7 into robinhood-unofficial:master Nov 7, 2017
@Jamonek
Copy link
Member

Jamonek commented Nov 7, 2017

Great work !

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

Successfully merging this pull request may close these issues.

3 participants