예제 #1
0
    def candles(self, pair: str, granularity: str) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(granularity, str))

        # Only these granularities are supported by OKEX API
        granularity_in_seconds = {
            "1min": 60,
            "3min": 180,
            "5min": 300,
            "15min": 900,
            "30min": 1800,
            "1day": 3600 * 24,
            "3day": 3600 * 24 * 3,
            "1week": 3600 * 24 * 7,
            "1hour": 3600,
            "2hour": 3600 * 2,
            "4hour": 3600 * 4,
            "6hour": 3600 * 6,
            "12hour": 3600 * 12
        }
        assert (granularity in granularity_in_seconds)

        result = self._http_get(
            f"/api/spot/v3/instruments/{pair}/candles",
            f"granularity={granularity_in_seconds[granularity]}")

        return list(
            map(
                lambda item: Candle(timestamp=int(
                    dateutil.parser.isoparse(item[0]).timestamp()),
                                    open=Wad.from_number(item[1]),
                                    high=Wad.from_number(item[2]),
                                    low=Wad.from_number(item[3]),
                                    close=Wad.from_number(item[4]),
                                    volume=Wad.from_number(item[5])), result))
예제 #2
0
    def candles(self, pair: str, granularity: int, count: int) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(granularity, int))

        assert (granularity in (1, 3, 5, 10, 15, 30, 60, 240))

        response = requests.get(
            f"https://crix-api-endpoint.upbit.com/v1/crix/candles/minutes/{granularity}?"
            f"code=CRIX.UPBIT.{pair}&count={count}",
            timeout=self.timeout)

        if not response.ok:
            raise Exception(
                f"Invalid response from the Upbit API: {response.status_code} {response.reason}"
            )

        return list(
            map(
                lambda item: Candle(timestamp=int(
                    dateutil.parser.parse(item['candleDateTime']).timestamp()),
                                    open=Wad.from_number(item['openingPrice']),
                                    close=Wad.from_number(item['tradePrice']),
                                    high=Wad.from_number(item['highPrice']),
                                    low=Wad.from_number(item['lowPrice']),
                                    volume=Wad.from_number(item[
                                        'candleAccTradeVolume'])),
                response.json()))
예제 #3
0
    def candles(self, pair: str, granularity: int) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(granularity, int))

        assert (granularity in (60, 300, 900, 3600, 21600, 86400))

        result = requests.get(
            f"{self.api_server}/products/{pair}/candles?"
            f"granularity={granularity}",
            timeout=self.timeout)

        if not result.ok:
            raise Exception(
                f"GDAX API invalid HTTP response: {http_response_summary(result)}"
            )

        try:
            data = result.json()
        except Exception:
            raise Exception(
                f"GDAX API invalid JSON response: {http_response_summary(result)}"
            )

        if 'message' in data:
            raise Exception(
                f"GDAX API negative response: {http_response_summary(result)}")

        return list(
            map(
                lambda item: Candle(timestamp=int(item[0]),
                                    open=Wad.from_number(item[3]),
                                    close=Wad.from_number(item[4]),
                                    high=Wad.from_number(item[2]),
                                    low=Wad.from_number(item[1]),
                                    volume=Wad.from_number(item[5])), data))
예제 #4
0
    def candles(self, pair: str, granularity: int) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(granularity, int))

        assert (granularity in (60, 300, 900, 3600, 21600, 86400))

        result = requests.get(
            f"{self.api_server}/products/{pair}/candles?"
            f"granularity={granularity}",
            timeout=self.timeout).json()

        return list(
            map(
                lambda item: Candle(timestamp=int(item[0]),
                                    open=Wad.from_number(item[3]),
                                    close=Wad.from_number(item[4]),
                                    high=Wad.from_number(item[2]),
                                    low=Wad.from_number(item[1]),
                                    volume=Wad.from_number(item[5])), result))
예제 #5
0
    def candles(self, pair: str, timeframe: str, limit: int) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(timeframe, str))
        assert (isinstance(limit, int))

        assert (timeframe in ('1m', '5m', '15m', '30m', '1h', '3h', '6h',
                              '12h', '1D', '7D', '14D', '1M'))

        result = self._http_get(f"/v2/candles/trade:{timeframe}:t{pair}/hist",
                                f"limit={limit}")

        return list(
            map(
                lambda item: Candle(timestamp=int(item[0] / 1000),
                                    open=Wad.from_number(item[1]),
                                    close=Wad.from_number(item[2]),
                                    high=Wad.from_number(item[3]),
                                    low=Wad.from_number(item[4]),
                                    volume=Wad.from_number(item[5])), result))
예제 #6
0
파일: okex.py 프로젝트: frrp/pyexchange
    def candles(self, pair: str, type: str, size: int) -> List[Candle]:
        assert (isinstance(pair, str))
        assert (isinstance(type, str))
        assert (isinstance(size, int))

        assert (type
                in ("1min", "3min", "5min", "15min", "30min", "1day", "3day",
                    "1week", "1hour", "2hour", "4hour", "6hour", "12hour"))

        result = self._http_get("/api/v1/kline.do",
                                f"symbol={pair}&type={type}&size={size}",
                                False)

        return list(
            map(
                lambda item: Candle(timestamp=int(item[0] / 1000),
                                    open=Wad.from_number(item[1]),
                                    close=Wad.from_number(item[4]),
                                    high=Wad.from_number(item[2]),
                                    low=Wad.from_number(item[3]),
                                    volume=Wad.from_number(item[5])), result))