UNPKG

korea-crypto-exchange

Version:

한국의 주요 암호화폐 거래소(업비트, 빗썸) API를 쉽게 구현할 수 있도록 도와주는 TypeScript 라이브러리

182 lines (181 loc) 6.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpbitQuotation = void 0; const axios_1 = __importDefault(require("axios")); class UpbitQuotation { constructor(config) { this.config = config; } async getMarkets(isDetails = false) { try { const url = `${this.config.serverUrl}/v1/market/all${isDetails ? '?is_details=true' : ''}`; const response = await axios_1.default.get(url); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch markets: ${error.response?.data?.message || error.message}`); } throw error; } } async getSecondCandles(params) { if (params.count && (params.count < 1 || params.count > 200)) { throw new Error('Count must be between 1 and 200'); } try { const url = `${this.config.serverUrl}/v1/candles/seconds`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch second candles: ${error.response?.data?.message || error.message}`); } throw error; } } async getMinuteCandles(unit, params) { if (![1, 3, 5, 15, 10, 30, 60, 240].includes(unit)) { throw new Error('Unit must be one of: 1, 3, 5, 15, 10, 30, 60, 240'); } if (params.count && (params.count < 1 || params.count > 200)) { throw new Error('Count must be between 1 and 200'); } try { const url = `${this.config.serverUrl}/v1/candles/minutes/${unit}`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch minute candles: ${error.response?.data?.message || error.message}`); } throw error; } } async getDayCandles(params) { if (params.count && (params.count < 1 || params.count > 200)) { throw new Error('Count must be between 1 and 200'); } try { const url = `${this.config.serverUrl}/v1/candles/days`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch day candles: ${error.response?.data?.message || error.message}`); } throw error; } } async getWeekCandles(params) { if (params.count && (params.count < 1 || params.count > 200)) { throw new Error('Count must be between 1 and 200'); } try { const url = `${this.config.serverUrl}/v1/candles/weeks`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch week candles: ${error.response?.data?.message || error.message}`); } throw error; } } async getYearCandles(params) { if (params.count && (params.count < 1 || params.count > 200)) { throw new Error('Count must be between 1 and 200'); } try { const url = `${this.config.serverUrl}/v1/candles/years`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch year candles: ${error.response?.data?.message || error.message}`); } throw error; } } async getTradeTicks(params) { if (params.days_ago && (params.days_ago < 1 || params.days_ago > 7)) { throw new Error('days_ago must be between 1 and 7'); } try { const url = `${this.config.serverUrl}/v1/trades/ticks`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch trade ticks: ${error.response?.data?.message || error.message}`); } throw error; } } async getTickers(params) { try { const url = `${this.config.serverUrl}/v1/ticker`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch tickers: ${error.response?.data?.message || error.message}`); } throw error; } } async getTickersAll(params) { try { const url = `${this.config.serverUrl}/v1/ticker/all`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch all tickers: ${error.response?.data?.message || error.message}`); } throw error; } } async getOrderbook(params) { try { const url = `${this.config.serverUrl}/v1/orderbook`; const response = await axios_1.default.get(url, { params }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch orderbook: ${error.response?.data?.message || error.message}`); } throw error; } } async getSupportedLevels(params) { try { const url = `${this.config.serverUrl}/v1/orderbook/supported_levels`; const response = await axios_1.default.get(url, { params: { markets: params.markets.join(',') } }); return response.data; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to fetch supported levels: ${error.response?.data?.message || error.message}`); } throw error; } } } exports.UpbitQuotation = UpbitQuotation;