コード例 #1
0
ファイル: order.py プロジェクト: shiyanshi124/stocklook
    def update(self, data=None):
        """
        Updates GdaxOrder class properties
        using data provided when calling the function
        or called automatically by the API.
        :param data: (dict)
            Should contain fields such as id, price, size,
            side, order_type, time_in_force, etc.
        :return: (None)
        """
        if data is None:
            if self.id is None:
                raise Exception("Order has no ID and "
                                "no data was provided to update.")
            data = self.gdax.get_orders(self.id)

        self.id = data.get('id')
        self.price = float(data.get('price', 0))
        self.size = float(data.get('size', 0))
        self.side = data.get('side')
        self.order_type = data.get('type')
        self.time_in_force = data.get('time_in_force')
        self.post_only = data.get('post_only')
        self.created_at = timestamp_from_utc(data.get('created_at'))
        self.funds = float(data.get('funds', 0))
        self.fill_fees = float(data.get('fill_fees', 0))
        self.filled_size = float(data.get('filled_size', 0))
        self.executed_value = float(data.get('executed_value', 0))
        self.status = data.get('status')
        self.settled = data.get('settled')
コード例 #2
0
    def get_candles(self,
                    product,
                    start,
                    end,
                    granularity=60,
                    convert_dates=False,
                    to_frame=False):
        """
        Historic rates for a product.
        Rates are returned in grouped buckets based on requested granularity.

        PARAMETERS
        Param	         Description
        start	         Start time in ISO 8601
        end	             End time in ISO 8601
        granularity	     Desired timeslice in seconds

        NOTES
        Historical rate data may be incomplete.
        No data is published for intervals where there are no ticks.
        Historical rates should not be polled frequently.
        If you need real-time information, use the trade and book endpoints along with the websocket feed.

        :return:
        Each bucket is an array of the following information:
        time               bucket start time
        low                lowest price during the bucket interval
        high               highest price during the bucket interval
        open               opening price (first trade) in the bucket interval
        close              closing price (last trade) in the bucket interval
        volume             volume of trading activity during the bucket interval
        """
        self._validate_product(product)

        if not isinstance(start, str):
            start = timestamp_to_iso8601(start)

        if not isinstance(end, str):
            end = timestamp_to_iso8601(end)

        ext = 'products/{}/candles'.format(product)
        params = dict(start=start, end=end, granularity=granularity)

        res = self.get(ext, params=params).json()

        if convert_dates:
            for row in res:
                row[0] = timestamp_from_utc(row[0])

        if to_frame:
            columns = ['time', 'low', 'high', 'open', 'close', 'volume']
            res = pd.DataFrame(columns=columns,
                               data=res,
                               index=range(len(res)))

        return res
コード例 #3
0
ファイル: api.py プロジェクト: zbarge/stocklook
def polo_return_chart_data(currency_pair,
                           start_unix=None,
                           end_unix=None,
                           period_unix=14400,
                           format_dates=True,
                           to_frame=True):
    """
    Returns public exchange data for the given
    currency_pair between the start_unix and end_unix
    timeframes.

    :param currency_pair: The curreny pair
    :param start_unix: (int, str) unix timestamp corresponding to the start date/time.
    :param end_unix: (int, str) unix timestamp corresponding to the end date/time.
    :param period_unix: (int, str) unix timestamp corresponding to the start period.
    :param format_dates: (bool, default True)
        True formats the 'date' values into pandas.Timestamp rather than unix date/times.
    :param to_frame: (bool, default True)
        True returns a pandas.DataFrame with the data contained
        False returns a list of dictionary objects containing the data for each period.
    :return:
        - close (float)
        - date (pd.Timestamp)
        - high (float)
        - low (float)
        - open (float)
        - quoteVolume (float)
        - volume (float)
        - weightedAverage (float)
    """

    if not start_unix:
        start_unix = timestamp_to_utc(datetime.now() - pd.DateOffset(years=10))

    if not end_unix:
        end_unix = timestamp_to_utc(datetime.now())

    params = {
        'currencyPair': currency_pair,
        'start': start_unix,
        'end': end_unix,
        'period': str(period_unix)
    }

    res = requests.get(
        'https://poloniex.com/public?'
        'command=returnChartData',
        params=params).json()

    if hasattr(res, 'get'):
        error = res.get('error', None)
        if error:
            raise Exception('{}: {}'.format(error, currency_pair))

    if format_dates is True and not isinstance(res, str):
        for r in res:
            r[DATE] = timestamp_from_utc(r[DATE])

    if to_frame is True and not isinstance(res, str):
        res = pd.DataFrame(data=res, index=range(len(res)))

    return res