Example #1
0
    def quote(self, displayPercent=False, token=None):

        # Setup parameters
        params = {'displayPercent': displayPercent, 'token': token}
        params = {k: param_bool(v) for k, v in params.items() if v}
        if displayPercent and type(displayPercent) != bool:
            raise ValueError("displayPercent must be bool")
        if token and type(token) != str:
            raise ValueError("token must be str")

        return self._get("quote", params=params)
Example #2
0
    def chart(self,
              range='1m',
              chartByDay=None,
              chartSimplify=None,
              chartInterval=None,
              chartCloseOnly=None,
              token=None):
        """
            Args:
                range - what range of data to retrieve. The variable 'CHART_RANGES'
                        has possible values in addition to a date.
        """

        # Setup parameters
        params = {
            'chartByDay': chartByDay,
            'chartSimplify': chartSimplify,
            'chartInterval': chartInterval,
            'chartCloseOnly': chartCloseOnly,
            'token': token
        }
        params = {k: param_bool(v) for k, v in params.items() if v}
        if chartByDay and type(chartByDay) != bool:
            raise ValueError("chartByDay must be bool")
        if chartSimplify and type(chartSimplify) != bool:
            raise ValueError("chartSimplify must be bool")
        if chartInterval and type(chartInterval) != int:
            raise ValueError("chartInterval must be int")
        if chartCloseOnly and type(chartCloseOnly) != bool:
            raise ValueError("chartCloseOnly must be bool")
        if token and type(token) != str:
            raise ValueError("token must be str")

        # Validate range is appropriate
        validate_range_set(range, CHART_RANGES)

        # date match
        date_match = re.match('^[0-9]{8}$', range)

        if date_match:
            range = parse_date(range)
            url = f"chart/date/{range}"
        else:
            url = f"chart/{range}"

        return self._get(url, params=params)
Example #3
0
 def quote(self, displayPercent=False):
     return self._get("quote",
                      params={"displayPercent": param_bool(displayPercent)})