├── .gitignore ├── container ├── candles │ ├── MinutesCandle.ts │ ├── WeekCandleMonth.ts │ ├── DayCandle.ts │ ├── MinutesCandle.js │ ├── WeekCandleMonth.js │ └── DayCandle.js ├── Order.ts ├── Order.js ├── OrderBook.ts ├── Trade.ts ├── Candle.ts ├── OrderBook.js ├── Trade.js ├── Candle.js ├── Market.ts └── Market.js ├── package.json ├── LICENSE ├── test ├── test.ts └── test.js ├── README-KR.md ├── index.ts ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | ./idea/* 2 | ./node_modules/* -------------------------------------------------------------------------------- /container/candles/MinutesCandle.ts: -------------------------------------------------------------------------------- 1 | import Candle from '../Candle'; 2 | 3 | export default class MinutesCandle extends Candle { 4 | 5 | private _unit: number; 6 | 7 | 8 | get unit(): number { 9 | return this._unit; 10 | } 11 | 12 | set unit(value: number) { 13 | this._unit = value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /container/candles/WeekCandleMonth.ts: -------------------------------------------------------------------------------- 1 | import Candle from '../Candle'; 2 | 3 | export default class WeekMonthCandle extends Candle { 4 | 5 | private _firstDayOfPeriod: string; 6 | 7 | 8 | get firstDayOfPeriod(): string { 9 | return this._firstDayOfPeriod; 10 | } 11 | 12 | set firstDayOfPeriod(value: string) { 13 | this._firstDayOfPeriod = value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /container/Order.ts: -------------------------------------------------------------------------------- 1 | export default class { 2 | 3 | private _price: number; 4 | private _size: number; 5 | 6 | constructor(price, size) { 7 | this._price = price; 8 | this._size = size; 9 | } 10 | 11 | get price(): number { 12 | return this._price; 13 | } 14 | 15 | set price(value: number) { 16 | this._price = value; 17 | } 18 | 19 | get size(): number { 20 | return this._size; 21 | } 22 | 23 | set size(value: number) { 24 | this._size = value; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /container/Order.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var default_1 = /** @class */ (function () { 4 | function default_1(price, size) { 5 | this._price = price; 6 | this._size = size; 7 | } 8 | Object.defineProperty(default_1.prototype, "price", { 9 | get: function () { 10 | return this._price; 11 | }, 12 | set: function (value) { 13 | this._price = value; 14 | }, 15 | enumerable: false, 16 | configurable: true 17 | }); 18 | Object.defineProperty(default_1.prototype, "size", { 19 | get: function () { 20 | return this._size; 21 | }, 22 | set: function (value) { 23 | this._size = value; 24 | }, 25 | enumerable: false, 26 | configurable: true 27 | }); 28 | return default_1; 29 | }()); 30 | exports.default = default_1; 31 | -------------------------------------------------------------------------------- /container/candles/DayCandle.ts: -------------------------------------------------------------------------------- 1 | import Candle from '../Candle'; 2 | 3 | export default class DayCandle extends Candle { 4 | private _prevClosingPrice: number; 5 | private _convertedTradePrice: number; 6 | private _changePrice: number; 7 | private _changeRate: number; 8 | get changeRate(): number { 9 | return this._changeRate; 10 | } 11 | 12 | set changeRate(value: number) { 13 | this._changeRate = value; 14 | } 15 | 16 | get changePrice(): number { 17 | return this._changePrice; 18 | } 19 | 20 | set changePrice(value: number) { 21 | this._changePrice = value; 22 | } 23 | 24 | get convertedTradePrice(): number { 25 | return this._convertedTradePrice; 26 | } 27 | 28 | set convertedTradePrice(value: number) { 29 | this._convertedTradePrice = value; 30 | } 31 | 32 | get prevClosingPrice(): number { 33 | return this._prevClosingPrice; 34 | } 35 | 36 | set prevClosingPrice(value: number) { 37 | this._prevClosingPrice = value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "upbit-api", 3 | "version": "0.10.4", 4 | "description": "This is an API that makes Upbit OpenAPI easy to use.", 5 | "main": "index.js", 6 | "keywords": [ 7 | "backend", 8 | "api", 9 | "upbit", 10 | "cryptocurrency", 11 | "exchange", 12 | "업비트", 13 | "코인", 14 | "암호화폐", 15 | "library" 16 | ], 17 | "scripts": { 18 | "test": "node test/test.js" 19 | }, 20 | "author": { 21 | "name": "Shin-JaeHeon", 22 | "email": "shinjaeheon520614@gmail.com", 23 | "url": "https://shinjaeheon.tistory.com" 24 | }, 25 | "bug": { 26 | "url": "https://github.com/Shin-JaeHeon/upbit-api/issues", 27 | "email": "shinjaeheon520614@gmail.com" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/Shin-JaeHeon/upbit-api.git" 32 | }, 33 | "license": "MIT", 34 | "dependencies": { 35 | "request": "2.88.2" 36 | }, 37 | "devDependencies": { 38 | "@types/node": "^10.5.1" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Shin-JaeHeon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/test.ts: -------------------------------------------------------------------------------- 1 | import upbit from '../index'; 2 | 3 | upbit.ticker(['KRW-BTC']).then(v => { 4 | const KRWBTC = v[0]; 5 | console.log(KRWBTC); 6 | upbit.autoMarketUpdate(KRWBTC, 5000, e => console.error(e), market => console.log(market)); 7 | }); 8 | 9 | upbit.orderBook("KRW-XRP").then(v => { 10 | console.log(v); 11 | v.forEach(v => upbit.autoOrderBookUpdate(v, 5000, e => console.error(e), orderBook => console.log(orderBook))); 12 | }).catch(e => console.error(e)); 13 | 14 | upbit.ticks('KRW-XRP').then(tradeList => { 15 | tradeList.forEach(v => console.log(v)); 16 | }).catch(err => console.log(err)); 17 | 18 | upbit.candlesMinutes('KRW-XRP', 1).then(tradeList => tradeList.forEach(candle => console.log(candle))).catch(err => console.log(err)); 19 | upbit.candlesDay('KRW-XRP', 1).then(tradeList => tradeList.forEach(candle => console.log(candle))).catch(err => console.log(err)); 20 | upbit.candlesWeek('KRW-XRP', 1).then(tradeList => tradeList.forEach(candle => console.log(candle))).catch(err => console.log(err)); 21 | upbit.candlesMonth('KRW-XRP', 1).then(tradeList => tradeList.forEach(candle => console.log(candle))).catch(err => console.log(err)); 22 | upbit.allMarket().then(marketList => console.log(marketList)).catch(err => console.error(err)); 23 | -------------------------------------------------------------------------------- /container/OrderBook.ts: -------------------------------------------------------------------------------- 1 | import Order from "./Order"; 2 | 3 | export default class { 4 | private readonly _market: string; 5 | private readonly _coin: string; 6 | private _lastUpdate: Date; 7 | private _askList: Array; 8 | private _bidList: Array; 9 | private _totalAsk: number; 10 | private _totalBid: number; 11 | 12 | constructor(market, coin) { 13 | this._market = market; 14 | this._coin = coin; 15 | } 16 | 17 | get marketCode(): string { 18 | return `${this._market}-${this._coin}`; 19 | } 20 | 21 | get market(): string { 22 | return this._market; 23 | } 24 | 25 | get coin(): string { 26 | return this._coin; 27 | } 28 | 29 | get lastUpdate(): Date { 30 | return this._lastUpdate; 31 | } 32 | 33 | set lastUpdate(value: Date) { 34 | this._lastUpdate = value; 35 | } 36 | 37 | get askList(): Array { 38 | return this._askList; 39 | } 40 | 41 | set askList(value: Array) { 42 | this._askList = value; 43 | } 44 | 45 | get bidList(): Array { 46 | return this._bidList; 47 | } 48 | 49 | set bidList(value: Array) { 50 | this._bidList = value; 51 | } 52 | 53 | get totalBid(): number { 54 | return this._totalBid; 55 | } 56 | 57 | set totalBid(value: number) { 58 | this._totalBid = value; 59 | } 60 | 61 | get totalAsk(): number { 62 | return this._totalAsk; 63 | } 64 | 65 | set totalAsk(value: number) { 66 | this._totalAsk = value; 67 | } 68 | } -------------------------------------------------------------------------------- /container/candles/MinutesCandle.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | if (typeof b !== "function" && b !== null) 11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 12 | extendStatics(d, b); 13 | function __() { this.constructor = d; } 14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 15 | }; 16 | })(); 17 | Object.defineProperty(exports, "__esModule", { value: true }); 18 | var Candle_1 = require("../Candle"); 19 | var MinutesCandle = /** @class */ (function (_super) { 20 | __extends(MinutesCandle, _super); 21 | function MinutesCandle() { 22 | return _super !== null && _super.apply(this, arguments) || this; 23 | } 24 | Object.defineProperty(MinutesCandle.prototype, "unit", { 25 | get: function () { 26 | return this._unit; 27 | }, 28 | set: function (value) { 29 | this._unit = value; 30 | }, 31 | enumerable: false, 32 | configurable: true 33 | }); 34 | return MinutesCandle; 35 | }(Candle_1.default)); 36 | exports.default = MinutesCandle; 37 | -------------------------------------------------------------------------------- /container/candles/WeekCandleMonth.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | if (typeof b !== "function" && b !== null) 11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 12 | extendStatics(d, b); 13 | function __() { this.constructor = d; } 14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 15 | }; 16 | })(); 17 | Object.defineProperty(exports, "__esModule", { value: true }); 18 | var Candle_1 = require("../Candle"); 19 | var WeekMonthCandle = /** @class */ (function (_super) { 20 | __extends(WeekMonthCandle, _super); 21 | function WeekMonthCandle() { 22 | return _super !== null && _super.apply(this, arguments) || this; 23 | } 24 | Object.defineProperty(WeekMonthCandle.prototype, "firstDayOfPeriod", { 25 | get: function () { 26 | return this._firstDayOfPeriod; 27 | }, 28 | set: function (value) { 29 | this._firstDayOfPeriod = value; 30 | }, 31 | enumerable: false, 32 | configurable: true 33 | }); 34 | return WeekMonthCandle; 35 | }(Candle_1.default)); 36 | exports.default = WeekMonthCandle; 37 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var index_1 = require("../index"); 4 | index_1.default.ticker(['KRW-BTC']).then(function (v) { 5 | var KRWBTC = v[0]; 6 | console.log(KRWBTC); 7 | index_1.default.autoMarketUpdate(KRWBTC, 5000, function (e) { return console.error(e); }, function (market) { return console.log(market); }); 8 | }); 9 | index_1.default.orderBook("KRW-XRP").then(function (v) { 10 | console.log(v); 11 | v.forEach(function (v) { return index_1.default.autoOrderBookUpdate(v, 5000, function (e) { return console.error(e); }, function (orderBook) { return console.log(orderBook); }); }); 12 | }).catch(function (e) { return console.error(e); }); 13 | index_1.default.ticks('KRW-XRP').then(function (tradeList) { 14 | tradeList.forEach(function (v) { return console.log(v); }); 15 | }).catch(function (err) { return console.log(err); }); 16 | index_1.default.candlesMinutes('KRW-XRP', 1).then(function (tradeList) { return tradeList.forEach(function (candle) { return console.log(candle); }); }).catch(function (err) { return console.log(err); }); 17 | index_1.default.candlesDay('KRW-XRP', 1).then(function (tradeList) { return tradeList.forEach(function (candle) { return console.log(candle); }); }).catch(function (err) { return console.log(err); }); 18 | index_1.default.candlesWeek('KRW-XRP', 1).then(function (tradeList) { return tradeList.forEach(function (candle) { return console.log(candle); }); }).catch(function (err) { return console.log(err); }); 19 | index_1.default.candlesMonth('KRW-XRP', 1).then(function (tradeList) { return tradeList.forEach(function (candle) { return console.log(candle); }); }).catch(function (err) { return console.log(err); }); 20 | index_1.default.allMarket().then(function (marketList) { return console.log(marketList); }).catch(function (err) { return console.error(err); }); 21 | -------------------------------------------------------------------------------- /container/Trade.ts: -------------------------------------------------------------------------------- 1 | export default class Trade { 2 | private readonly _market: string; 3 | private readonly _coin: string; 4 | private _tradeTime: Date; 5 | private _price: number; 6 | private _volume: number; 7 | private _prev_closing_price: number; 8 | private _change_price: number; 9 | private _isAsk: boolean; 10 | private _lastUpdate: Date; 11 | private _sequential_id: string; 12 | 13 | constructor(market, coin) { 14 | this._market = market; 15 | this._coin = coin; 16 | } 17 | 18 | get coin(): string { 19 | return this._coin; 20 | } 21 | 22 | get market(): string { 23 | return this._market; 24 | } 25 | 26 | get marketCode(): string { 27 | return `${this._market}-${this._coin}`; 28 | } 29 | 30 | get price(): number { 31 | return this._price; 32 | } 33 | 34 | set price(value: number) { 35 | this._price = value; 36 | } 37 | 38 | get lastUpdate(): Date { 39 | return this._lastUpdate; 40 | } 41 | 42 | set lastUpdate(value: Date) { 43 | this._lastUpdate = value; 44 | } 45 | 46 | get tradeTime(): Date { 47 | return this._tradeTime; 48 | } 49 | 50 | set tradeTime(value: Date) { 51 | this._tradeTime = value; 52 | } 53 | 54 | get volume(): number { 55 | return this._volume; 56 | } 57 | 58 | set volume(value: number) { 59 | this._volume = value; 60 | } 61 | 62 | get prev_closing_price(): number { 63 | return this._prev_closing_price; 64 | } 65 | 66 | set prev_closing_price(value: number) { 67 | this._prev_closing_price = value; 68 | } 69 | 70 | get change_price(): number { 71 | return this._change_price; 72 | } 73 | 74 | set change_price(value: number) { 75 | this._change_price = value; 76 | } 77 | 78 | get sequential_id(): string { 79 | return this._sequential_id; 80 | } 81 | 82 | set sequential_id(value: string) { 83 | this._sequential_id = value; 84 | } 85 | 86 | get isAsk(): boolean { 87 | return this._isAsk; 88 | } 89 | 90 | set isAsk(value: boolean) { 91 | this._isAsk = value; 92 | } 93 | } -------------------------------------------------------------------------------- /container/Candle.ts: -------------------------------------------------------------------------------- 1 | export default class Candle { 2 | private readonly _market: string; 3 | private readonly _coin: string; 4 | private _timestamp: number; 5 | private _candleDateTimeUTC: Date; 6 | private _candleDateTimeKST: Date; 7 | private _price: number; 8 | private _open: number; 9 | private _high: number; 10 | private _low: number; 11 | private _accTradePrice: number; 12 | private _accTradeVolume: number; 13 | private _lastUpdate: Date; 14 | 15 | constructor(market, coin) { 16 | this._market = market; 17 | this._coin = coin; 18 | 19 | } 20 | 21 | get marketCode(): string { 22 | return `${this._market}-${this._coin}`; 23 | } 24 | 25 | get coin(): string { 26 | return this._coin; 27 | } 28 | 29 | get market(): string { 30 | return this._market; 31 | } 32 | 33 | get candleDateTimeUTC(): Date { 34 | return this._candleDateTimeUTC; 35 | } 36 | 37 | set candleDateTimeUTC(value: Date) { 38 | this._candleDateTimeUTC = value; 39 | } 40 | 41 | get price(): number { 42 | return this._price; 43 | } 44 | 45 | set price(value: number) { 46 | this._price = value; 47 | } 48 | 49 | get candleDateTimeKST(): Date { 50 | return this._candleDateTimeKST; 51 | } 52 | 53 | set candleDateTimeKST(value: Date) { 54 | this._candleDateTimeKST = value; 55 | } 56 | 57 | get open(): number { 58 | return this._open; 59 | } 60 | 61 | set open(value: number) { 62 | this._open = value; 63 | } 64 | 65 | get high(): number { 66 | return this._high; 67 | } 68 | 69 | set high(value: number) { 70 | this._high = value; 71 | } 72 | 73 | get low(): number { 74 | return this._low; 75 | } 76 | 77 | set low(value: number) { 78 | this._low = value; 79 | } 80 | 81 | get timestamp(): number { 82 | return this._timestamp; 83 | } 84 | 85 | set timestamp(value: number) { 86 | this._timestamp = value; 87 | } 88 | 89 | get accTradePrice(): number { 90 | return this._accTradePrice; 91 | } 92 | 93 | set accTradePrice(value: number) { 94 | this._accTradePrice = value; 95 | } 96 | 97 | get accTradeVolume(): number { 98 | return this._accTradeVolume; 99 | } 100 | 101 | set accTradeVolume(value: number) { 102 | this._accTradeVolume = value; 103 | } 104 | 105 | get lastUpdate(): Date { 106 | return this._lastUpdate; 107 | } 108 | 109 | set lastUpdate(value: Date) { 110 | this._lastUpdate = value; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /container/candles/DayCandle.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | if (typeof b !== "function" && b !== null) 11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 12 | extendStatics(d, b); 13 | function __() { this.constructor = d; } 14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 15 | }; 16 | })(); 17 | Object.defineProperty(exports, "__esModule", { value: true }); 18 | var Candle_1 = require("../Candle"); 19 | var DayCandle = /** @class */ (function (_super) { 20 | __extends(DayCandle, _super); 21 | function DayCandle() { 22 | return _super !== null && _super.apply(this, arguments) || this; 23 | } 24 | Object.defineProperty(DayCandle.prototype, "changeRate", { 25 | get: function () { 26 | return this._changeRate; 27 | }, 28 | set: function (value) { 29 | this._changeRate = value; 30 | }, 31 | enumerable: false, 32 | configurable: true 33 | }); 34 | Object.defineProperty(DayCandle.prototype, "changePrice", { 35 | get: function () { 36 | return this._changePrice; 37 | }, 38 | set: function (value) { 39 | this._changePrice = value; 40 | }, 41 | enumerable: false, 42 | configurable: true 43 | }); 44 | Object.defineProperty(DayCandle.prototype, "convertedTradePrice", { 45 | get: function () { 46 | return this._convertedTradePrice; 47 | }, 48 | set: function (value) { 49 | this._convertedTradePrice = value; 50 | }, 51 | enumerable: false, 52 | configurable: true 53 | }); 54 | Object.defineProperty(DayCandle.prototype, "prevClosingPrice", { 55 | get: function () { 56 | return this._prevClosingPrice; 57 | }, 58 | set: function (value) { 59 | this._prevClosingPrice = value; 60 | }, 61 | enumerable: false, 62 | configurable: true 63 | }); 64 | return DayCandle; 65 | }(Candle_1.default)); 66 | exports.default = DayCandle; 67 | -------------------------------------------------------------------------------- /container/OrderBook.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var default_1 = /** @class */ (function () { 4 | function default_1(market, coin) { 5 | this._market = market; 6 | this._coin = coin; 7 | } 8 | Object.defineProperty(default_1.prototype, "marketCode", { 9 | get: function () { 10 | return this._market + "-" + this._coin; 11 | }, 12 | enumerable: false, 13 | configurable: true 14 | }); 15 | Object.defineProperty(default_1.prototype, "market", { 16 | get: function () { 17 | return this._market; 18 | }, 19 | enumerable: false, 20 | configurable: true 21 | }); 22 | Object.defineProperty(default_1.prototype, "coin", { 23 | get: function () { 24 | return this._coin; 25 | }, 26 | enumerable: false, 27 | configurable: true 28 | }); 29 | Object.defineProperty(default_1.prototype, "lastUpdate", { 30 | get: function () { 31 | return this._lastUpdate; 32 | }, 33 | set: function (value) { 34 | this._lastUpdate = value; 35 | }, 36 | enumerable: false, 37 | configurable: true 38 | }); 39 | Object.defineProperty(default_1.prototype, "askList", { 40 | get: function () { 41 | return this._askList; 42 | }, 43 | set: function (value) { 44 | this._askList = value; 45 | }, 46 | enumerable: false, 47 | configurable: true 48 | }); 49 | Object.defineProperty(default_1.prototype, "bidList", { 50 | get: function () { 51 | return this._bidList; 52 | }, 53 | set: function (value) { 54 | this._bidList = value; 55 | }, 56 | enumerable: false, 57 | configurable: true 58 | }); 59 | Object.defineProperty(default_1.prototype, "totalBid", { 60 | get: function () { 61 | return this._totalBid; 62 | }, 63 | set: function (value) { 64 | this._totalBid = value; 65 | }, 66 | enumerable: false, 67 | configurable: true 68 | }); 69 | Object.defineProperty(default_1.prototype, "totalAsk", { 70 | get: function () { 71 | return this._totalAsk; 72 | }, 73 | set: function (value) { 74 | this._totalAsk = value; 75 | }, 76 | enumerable: false, 77 | configurable: true 78 | }); 79 | return default_1; 80 | }()); 81 | exports.default = default_1; 82 | -------------------------------------------------------------------------------- /container/Trade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Trade = /** @class */ (function () { 4 | function Trade(market, coin) { 5 | this._market = market; 6 | this._coin = coin; 7 | } 8 | Object.defineProperty(Trade.prototype, "coin", { 9 | get: function () { 10 | return this._coin; 11 | }, 12 | enumerable: false, 13 | configurable: true 14 | }); 15 | Object.defineProperty(Trade.prototype, "market", { 16 | get: function () { 17 | return this._market; 18 | }, 19 | enumerable: false, 20 | configurable: true 21 | }); 22 | Object.defineProperty(Trade.prototype, "marketCode", { 23 | get: function () { 24 | return this._market + "-" + this._coin; 25 | }, 26 | enumerable: false, 27 | configurable: true 28 | }); 29 | Object.defineProperty(Trade.prototype, "price", { 30 | get: function () { 31 | return this._price; 32 | }, 33 | set: function (value) { 34 | this._price = value; 35 | }, 36 | enumerable: false, 37 | configurable: true 38 | }); 39 | Object.defineProperty(Trade.prototype, "lastUpdate", { 40 | get: function () { 41 | return this._lastUpdate; 42 | }, 43 | set: function (value) { 44 | this._lastUpdate = value; 45 | }, 46 | enumerable: false, 47 | configurable: true 48 | }); 49 | Object.defineProperty(Trade.prototype, "tradeTime", { 50 | get: function () { 51 | return this._tradeTime; 52 | }, 53 | set: function (value) { 54 | this._tradeTime = value; 55 | }, 56 | enumerable: false, 57 | configurable: true 58 | }); 59 | Object.defineProperty(Trade.prototype, "volume", { 60 | get: function () { 61 | return this._volume; 62 | }, 63 | set: function (value) { 64 | this._volume = value; 65 | }, 66 | enumerable: false, 67 | configurable: true 68 | }); 69 | Object.defineProperty(Trade.prototype, "prev_closing_price", { 70 | get: function () { 71 | return this._prev_closing_price; 72 | }, 73 | set: function (value) { 74 | this._prev_closing_price = value; 75 | }, 76 | enumerable: false, 77 | configurable: true 78 | }); 79 | Object.defineProperty(Trade.prototype, "change_price", { 80 | get: function () { 81 | return this._change_price; 82 | }, 83 | set: function (value) { 84 | this._change_price = value; 85 | }, 86 | enumerable: false, 87 | configurable: true 88 | }); 89 | Object.defineProperty(Trade.prototype, "sequential_id", { 90 | get: function () { 91 | return this._sequential_id; 92 | }, 93 | set: function (value) { 94 | this._sequential_id = value; 95 | }, 96 | enumerable: false, 97 | configurable: true 98 | }); 99 | Object.defineProperty(Trade.prototype, "isAsk", { 100 | get: function () { 101 | return this._isAsk; 102 | }, 103 | set: function (value) { 104 | this._isAsk = value; 105 | }, 106 | enumerable: false, 107 | configurable: true 108 | }); 109 | return Trade; 110 | }()); 111 | exports.default = Trade; 112 | -------------------------------------------------------------------------------- /container/Candle.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Candle = /** @class */ (function () { 4 | function Candle(market, coin) { 5 | this._market = market; 6 | this._coin = coin; 7 | } 8 | Object.defineProperty(Candle.prototype, "marketCode", { 9 | get: function () { 10 | return this._market + "-" + this._coin; 11 | }, 12 | enumerable: false, 13 | configurable: true 14 | }); 15 | Object.defineProperty(Candle.prototype, "coin", { 16 | get: function () { 17 | return this._coin; 18 | }, 19 | enumerable: false, 20 | configurable: true 21 | }); 22 | Object.defineProperty(Candle.prototype, "market", { 23 | get: function () { 24 | return this._market; 25 | }, 26 | enumerable: false, 27 | configurable: true 28 | }); 29 | Object.defineProperty(Candle.prototype, "candleDateTimeUTC", { 30 | get: function () { 31 | return this._candleDateTimeUTC; 32 | }, 33 | set: function (value) { 34 | this._candleDateTimeUTC = value; 35 | }, 36 | enumerable: false, 37 | configurable: true 38 | }); 39 | Object.defineProperty(Candle.prototype, "price", { 40 | get: function () { 41 | return this._price; 42 | }, 43 | set: function (value) { 44 | this._price = value; 45 | }, 46 | enumerable: false, 47 | configurable: true 48 | }); 49 | Object.defineProperty(Candle.prototype, "candleDateTimeKST", { 50 | get: function () { 51 | return this._candleDateTimeKST; 52 | }, 53 | set: function (value) { 54 | this._candleDateTimeKST = value; 55 | }, 56 | enumerable: false, 57 | configurable: true 58 | }); 59 | Object.defineProperty(Candle.prototype, "open", { 60 | get: function () { 61 | return this._open; 62 | }, 63 | set: function (value) { 64 | this._open = value; 65 | }, 66 | enumerable: false, 67 | configurable: true 68 | }); 69 | Object.defineProperty(Candle.prototype, "high", { 70 | get: function () { 71 | return this._high; 72 | }, 73 | set: function (value) { 74 | this._high = value; 75 | }, 76 | enumerable: false, 77 | configurable: true 78 | }); 79 | Object.defineProperty(Candle.prototype, "low", { 80 | get: function () { 81 | return this._low; 82 | }, 83 | set: function (value) { 84 | this._low = value; 85 | }, 86 | enumerable: false, 87 | configurable: true 88 | }); 89 | Object.defineProperty(Candle.prototype, "timestamp", { 90 | get: function () { 91 | return this._timestamp; 92 | }, 93 | set: function (value) { 94 | this._timestamp = value; 95 | }, 96 | enumerable: false, 97 | configurable: true 98 | }); 99 | Object.defineProperty(Candle.prototype, "accTradePrice", { 100 | get: function () { 101 | return this._accTradePrice; 102 | }, 103 | set: function (value) { 104 | this._accTradePrice = value; 105 | }, 106 | enumerable: false, 107 | configurable: true 108 | }); 109 | Object.defineProperty(Candle.prototype, "accTradeVolume", { 110 | get: function () { 111 | return this._accTradeVolume; 112 | }, 113 | set: function (value) { 114 | this._accTradeVolume = value; 115 | }, 116 | enumerable: false, 117 | configurable: true 118 | }); 119 | Object.defineProperty(Candle.prototype, "lastUpdate", { 120 | get: function () { 121 | return this._lastUpdate; 122 | }, 123 | set: function (value) { 124 | this._lastUpdate = value; 125 | }, 126 | enumerable: false, 127 | configurable: true 128 | }); 129 | return Candle; 130 | }()); 131 | exports.default = Candle; 132 | -------------------------------------------------------------------------------- /container/Market.ts: -------------------------------------------------------------------------------- 1 | export default class { 2 | 3 | private readonly _market: string; 4 | private readonly _coin: string; 5 | private _tradeTime: Date; 6 | private _price: number; 7 | private _open: number; 8 | private _high: number; 9 | private _low: number; 10 | private _prevClose: number; 11 | private _change: string; 12 | private _changePrice: number; 13 | private _changeRate: number; 14 | private _signedChangePrice: number; 15 | private _signedChangeRate: number; 16 | private _tradeVolume: number; 17 | private _accTradePrice: number; 18 | private _accTradePrice24: number; 19 | private _accTradeVolume: number; 20 | private _accTradeVolume24: number; 21 | private _high52wPrice: number; 22 | private _high52wDate: Date; 23 | private _low52wPrice: number; 24 | private _low52wDate: Date; 25 | private _lastUpdate: Date; 26 | 27 | constructor(market, coin) { 28 | this._market = market; 29 | this._coin = coin; 30 | 31 | } 32 | 33 | get marketCode(): string { 34 | return `${this._market}-${this._coin}`; 35 | } 36 | 37 | get coin(): string { 38 | return this._coin; 39 | } 40 | 41 | get market(): string { 42 | return this._market; 43 | } 44 | 45 | get tradeTime(): Date { 46 | return this._tradeTime; 47 | } 48 | 49 | set tradeTime(value: Date) { 50 | this._tradeTime = value; 51 | } 52 | 53 | get price(): number { 54 | return this._price; 55 | } 56 | 57 | set price(value: number) { 58 | this._price = value; 59 | } 60 | 61 | get open(): number { 62 | return this._open; 63 | } 64 | 65 | set open(value: number) { 66 | this._open = value; 67 | } 68 | 69 | get high(): number { 70 | return this._high; 71 | } 72 | 73 | set high(value: number) { 74 | this._high = value; 75 | } 76 | 77 | get low(): number { 78 | return this._low; 79 | } 80 | 81 | set low(value: number) { 82 | this._low = value; 83 | } 84 | 85 | get prevClose(): number { 86 | return this._prevClose; 87 | } 88 | 89 | set prevClose(value: number) { 90 | this._prevClose = value; 91 | } 92 | 93 | get change(): string { 94 | return this._change; 95 | } 96 | 97 | set change(value: string) { 98 | this._change = value; 99 | } 100 | 101 | get changePrice(): number { 102 | return this._changePrice; 103 | } 104 | 105 | set changePrice(value: number) { 106 | this._changePrice = value; 107 | } 108 | 109 | get changeRate(): number { 110 | return this._changeRate; 111 | } 112 | 113 | set changeRate(value: number) { 114 | this._changeRate = value; 115 | } 116 | 117 | get signedChangePrice(): number { 118 | return this._signedChangePrice; 119 | } 120 | 121 | set signedChangePrice(value: number) { 122 | this._signedChangePrice = value; 123 | } 124 | 125 | get signedChangeRate(): number { 126 | return this._signedChangeRate; 127 | } 128 | 129 | set signedChangeRate(value: number) { 130 | this._signedChangeRate = value; 131 | } 132 | 133 | get tradeVolume(): number { 134 | return this._tradeVolume; 135 | } 136 | 137 | set tradeVolume(value: number) { 138 | this._tradeVolume = value; 139 | } 140 | 141 | get accTradePrice(): number { 142 | return this._accTradePrice; 143 | } 144 | 145 | set accTradePrice(value: number) { 146 | this._accTradePrice = value; 147 | } 148 | 149 | get accTradePrice24(): number { 150 | return this._accTradePrice24; 151 | } 152 | 153 | set accTradePrice24(value: number) { 154 | this._accTradePrice24 = value; 155 | } 156 | 157 | get accTradeVolume(): number { 158 | return this._accTradeVolume; 159 | } 160 | 161 | set accTradeVolume(value: number) { 162 | this._accTradeVolume = value; 163 | } 164 | 165 | get accTradeVolume24(): number { 166 | return this._accTradeVolume24; 167 | } 168 | 169 | set accTradeVolume24(value: number) { 170 | this._accTradeVolume24 = value; 171 | } 172 | 173 | get high52wPrice(): number { 174 | return this._high52wPrice; 175 | } 176 | 177 | set high52wPrice(value: number) { 178 | this._high52wPrice = value; 179 | } 180 | 181 | get high52wDate(): Date { 182 | return this._high52wDate; 183 | } 184 | 185 | set high52wDate(value: Date) { 186 | this._high52wDate = value; 187 | } 188 | 189 | get low52wPrice(): number { 190 | return this._low52wPrice; 191 | } 192 | 193 | set low52wPrice(value: number) { 194 | this._low52wPrice = value; 195 | } 196 | 197 | get low52wDate(): Date { 198 | return this._low52wDate; 199 | } 200 | 201 | set low52wDate(value: Date) { 202 | this._low52wDate = value; 203 | } 204 | 205 | get lastUpdate(): Date { 206 | return this._lastUpdate; 207 | } 208 | 209 | set lastUpdate(value: Date) { 210 | this._lastUpdate = value; 211 | } 212 | } -------------------------------------------------------------------------------- /container/Market.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var default_1 = /** @class */ (function () { 4 | function default_1(market, coin) { 5 | this._market = market; 6 | this._coin = coin; 7 | } 8 | Object.defineProperty(default_1.prototype, "marketCode", { 9 | get: function () { 10 | return this._market + "-" + this._coin; 11 | }, 12 | enumerable: false, 13 | configurable: true 14 | }); 15 | Object.defineProperty(default_1.prototype, "coin", { 16 | get: function () { 17 | return this._coin; 18 | }, 19 | enumerable: false, 20 | configurable: true 21 | }); 22 | Object.defineProperty(default_1.prototype, "market", { 23 | get: function () { 24 | return this._market; 25 | }, 26 | enumerable: false, 27 | configurable: true 28 | }); 29 | Object.defineProperty(default_1.prototype, "tradeTime", { 30 | get: function () { 31 | return this._tradeTime; 32 | }, 33 | set: function (value) { 34 | this._tradeTime = value; 35 | }, 36 | enumerable: false, 37 | configurable: true 38 | }); 39 | Object.defineProperty(default_1.prototype, "price", { 40 | get: function () { 41 | return this._price; 42 | }, 43 | set: function (value) { 44 | this._price = value; 45 | }, 46 | enumerable: false, 47 | configurable: true 48 | }); 49 | Object.defineProperty(default_1.prototype, "open", { 50 | get: function () { 51 | return this._open; 52 | }, 53 | set: function (value) { 54 | this._open = value; 55 | }, 56 | enumerable: false, 57 | configurable: true 58 | }); 59 | Object.defineProperty(default_1.prototype, "high", { 60 | get: function () { 61 | return this._high; 62 | }, 63 | set: function (value) { 64 | this._high = value; 65 | }, 66 | enumerable: false, 67 | configurable: true 68 | }); 69 | Object.defineProperty(default_1.prototype, "low", { 70 | get: function () { 71 | return this._low; 72 | }, 73 | set: function (value) { 74 | this._low = value; 75 | }, 76 | enumerable: false, 77 | configurable: true 78 | }); 79 | Object.defineProperty(default_1.prototype, "prevClose", { 80 | get: function () { 81 | return this._prevClose; 82 | }, 83 | set: function (value) { 84 | this._prevClose = value; 85 | }, 86 | enumerable: false, 87 | configurable: true 88 | }); 89 | Object.defineProperty(default_1.prototype, "change", { 90 | get: function () { 91 | return this._change; 92 | }, 93 | set: function (value) { 94 | this._change = value; 95 | }, 96 | enumerable: false, 97 | configurable: true 98 | }); 99 | Object.defineProperty(default_1.prototype, "changePrice", { 100 | get: function () { 101 | return this._changePrice; 102 | }, 103 | set: function (value) { 104 | this._changePrice = value; 105 | }, 106 | enumerable: false, 107 | configurable: true 108 | }); 109 | Object.defineProperty(default_1.prototype, "changeRate", { 110 | get: function () { 111 | return this._changeRate; 112 | }, 113 | set: function (value) { 114 | this._changeRate = value; 115 | }, 116 | enumerable: false, 117 | configurable: true 118 | }); 119 | Object.defineProperty(default_1.prototype, "signedChangePrice", { 120 | get: function () { 121 | return this._signedChangePrice; 122 | }, 123 | set: function (value) { 124 | this._signedChangePrice = value; 125 | }, 126 | enumerable: false, 127 | configurable: true 128 | }); 129 | Object.defineProperty(default_1.prototype, "signedChangeRate", { 130 | get: function () { 131 | return this._signedChangeRate; 132 | }, 133 | set: function (value) { 134 | this._signedChangeRate = value; 135 | }, 136 | enumerable: false, 137 | configurable: true 138 | }); 139 | Object.defineProperty(default_1.prototype, "tradeVolume", { 140 | get: function () { 141 | return this._tradeVolume; 142 | }, 143 | set: function (value) { 144 | this._tradeVolume = value; 145 | }, 146 | enumerable: false, 147 | configurable: true 148 | }); 149 | Object.defineProperty(default_1.prototype, "accTradePrice", { 150 | get: function () { 151 | return this._accTradePrice; 152 | }, 153 | set: function (value) { 154 | this._accTradePrice = value; 155 | }, 156 | enumerable: false, 157 | configurable: true 158 | }); 159 | Object.defineProperty(default_1.prototype, "accTradePrice24", { 160 | get: function () { 161 | return this._accTradePrice24; 162 | }, 163 | set: function (value) { 164 | this._accTradePrice24 = value; 165 | }, 166 | enumerable: false, 167 | configurable: true 168 | }); 169 | Object.defineProperty(default_1.prototype, "accTradeVolume", { 170 | get: function () { 171 | return this._accTradeVolume; 172 | }, 173 | set: function (value) { 174 | this._accTradeVolume = value; 175 | }, 176 | enumerable: false, 177 | configurable: true 178 | }); 179 | Object.defineProperty(default_1.prototype, "accTradeVolume24", { 180 | get: function () { 181 | return this._accTradeVolume24; 182 | }, 183 | set: function (value) { 184 | this._accTradeVolume24 = value; 185 | }, 186 | enumerable: false, 187 | configurable: true 188 | }); 189 | Object.defineProperty(default_1.prototype, "high52wPrice", { 190 | get: function () { 191 | return this._high52wPrice; 192 | }, 193 | set: function (value) { 194 | this._high52wPrice = value; 195 | }, 196 | enumerable: false, 197 | configurable: true 198 | }); 199 | Object.defineProperty(default_1.prototype, "high52wDate", { 200 | get: function () { 201 | return this._high52wDate; 202 | }, 203 | set: function (value) { 204 | this._high52wDate = value; 205 | }, 206 | enumerable: false, 207 | configurable: true 208 | }); 209 | Object.defineProperty(default_1.prototype, "low52wPrice", { 210 | get: function () { 211 | return this._low52wPrice; 212 | }, 213 | set: function (value) { 214 | this._low52wPrice = value; 215 | }, 216 | enumerable: false, 217 | configurable: true 218 | }); 219 | Object.defineProperty(default_1.prototype, "low52wDate", { 220 | get: function () { 221 | return this._low52wDate; 222 | }, 223 | set: function (value) { 224 | this._low52wDate = value; 225 | }, 226 | enumerable: false, 227 | configurable: true 228 | }); 229 | Object.defineProperty(default_1.prototype, "lastUpdate", { 230 | get: function () { 231 | return this._lastUpdate; 232 | }, 233 | set: function (value) { 234 | this._lastUpdate = value; 235 | }, 236 | enumerable: false, 237 | configurable: true 238 | }); 239 | return default_1; 240 | }()); 241 | exports.default = default_1; 242 | -------------------------------------------------------------------------------- /README-KR.md: -------------------------------------------------------------------------------- 1 | # upbit-api 2 | [![npm](https://img.shields.io/npm/v/upbit-api.svg?style=flat-square)](https://www.npmjs.com/package/upbit-api) 3 | [![npm](https://img.shields.io/npm/dt/upbit-api.svg?style=flat-square)](https://www.npmjs.com/package/upbit-api) 4 | [![npm](https://img.shields.io/npm/l/upbit-api.svg?registry_uri=https%3A%2F%2Fregistry.npmjs.com&style=flat-square)](https://opensource.org/licenses/MIT) 5 | [![npm](https://img.shields.io/badge/Readme-English-lightgray.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README.md) 6 | [![npm](https://img.shields.io/badge/Readme-한국어-blue.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-KR.md) 7 | [![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-JP.md) 8 | [![npm](https://img.shields.io/badge/Readme-汉语-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-CN.md) 9 | 10 | upbit-api는 업비트의 Open API를 좀 더 쉽게 사용할 수 있도록 만든 node.js용 라이브러리입니다. 11 | 12 | 타입스크립트로 작성되어 있으며, es2017로 컴파일 되어있습니다. 13 | 14 | Restful API와 WebSocket API를 모두 지원하는 것이 목표입니다. 15 | ## 커버리지 테이블 16 | **§** 심볼은 `autoMarketUpdate` 또는 `autoOrderBookUpdate`가 있습니다. 17 | 18 | | 메소드 | Upbit | upbit-api | 지원 버전 | 19 | |--------|-----------------------|----------------|-----------------| 20 | | GET | /ticker | ticker **§** | 0.0.1 이상 | 21 | | GET | /orderbook | orderBook **§**| 0.2.0 이상 | 22 | | GET | /trades/ticks | ticks | 0.5.0 이상 | 23 | | GET | /candles/minutes/unit | candlesMinutes | 0.6.0 이상 | 24 | | GET | /market/all | allMarket | 0.7.0 이상 | 25 | | GET | /candles/days | candlesDay | 0.9.0 이상 | 26 | | GET | /candles/weeks | candlesWeek | 0.10.0 이상 | 27 | | GET | /candles/months | candlesMonth | 0.10.0 이상 | 28 | | GET | /accounts | 미지원 | 적어도 0.11.0 | 29 | | GET | /orders/chance | 미지원 | 적어도 0.11.0 | 30 | | GET | /order | 미지원 | 적어도 0.11.0 | 31 | | GET | /orders | 미지원 | 적어도 0.11.0 | 32 | | POST | /orders | 미지원 | 적어도 0.11.0 | 33 | | DELETE | /order | 미지원 | 적어도 0.11.0 | 34 | | GET | /withdraws | 미지원 | 적어도 0.11.0 | 35 | | GET | /withdraw | 미지원 | 적어도 0.11.0 | 36 | | GET | /withdraws/chance | 미지원 | 적어도 0.11.0 | 37 | | POST | /withdraws/coin | 미지원 | 적어도 0.11.0 | 38 | | POST | /withdraws/krw | 미지원 | 적어도 0.11.0 | 39 | | GET | /deposits | 미지원 | 적어도 0.11.0 | 40 | | 웹소켓 | ticker | 미지원 | 적어도 0.11.0 | 41 | | 웹소켓 | trade | 미지원 | 적어도 0.11.0 | 42 | | 웹소켓 | orderbook | 미지원 | 적어도 0.11.0 | 43 | ## ticker(market) 44 | `Market` 오브젝트(KRW-BTC 같은 것을 일컫습니다.) 배열을 생성합니다. 45 | 46 | | 매개변수 | 타입 | 설명 | 47 | |----------|-----------------------------|---------------------------------------| 48 | | market | string 또는 Array\ | 'KRW-BTC' 또는 ['KRW-BTC', 'KRW-XRP'] | 49 | 50 | ### Market 클래스 51 | | 이름 | 타입 | 설명 | 52 | |-------------------|--------|------------------------------------| 53 | | market | string | ex) KRW, BTC, USDT ... | 54 | | coin | string | ex) BTC, ETH, XRP ... | 55 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 56 | | tradeTime | `Date` | 거래 시간 | 57 | | price | number | 가격 | 58 | | open | number | 시가 | 59 | | high | number | 고가 | 60 | | low | number | 저가 | 61 | | prevClose | number | 전일 종가 | 62 | | change | number | EVEN(보합), RISE(상승), FALL(하락) | 63 | | changePrice | number | 변화액의 절대값 | 64 | | changeRate | number | 변화율의 절대값 | 65 | | signedChangePrice | number | 부호가 있는 변화액 | 66 | | signedChangeRate | number | 부호가 있는 변화율 | 67 | | tradeVolume | number | 가장 최근 거래량 | 68 | | accTradePrice | number | 누적 거래대금(UTC 0시 기준) | 69 | | accTradePrice24 | number | 24시간 누적 거래대금 | 70 | | accTradeVolume | number | 누적 거래량(UTC 0시 기준) | 71 | | accTradeVolume24 | number | 24시간 누적 거래대금 | 72 | | high52wPrice | number | 52주 신고가 | 73 | | high52wDate | `Date` | 52주 신고가 달성일 | 74 | | low52wPrice | number | 52주 신저가 | 75 | | low52wDate | `Date` | 52주 신저가 달성일 | 76 | | lastUpdate | `Date` | 이 객체가 업데이트된 시간 | 77 | 78 | ## autoMarketUpdate(market, time , errorHandler, callback?) 79 | `Market` 오브젝트를 일정 `time`마다 업데이트 합니다. 80 | 81 | | 매개변수 | 타입 | 설명 | 82 | |--------------|-------------------------------|-------------------------------------------------| 83 | | market | `Market` 또는 Array\ | 업데이트 될 `Market` 오브젝트 | 84 | | time | number | 업데이트 주기 (밀리초) | 85 | | errorHandler | function, (error) => any | 에러 핸들러 | 86 | | callback | function, (market) => any | 선택사항, 오브젝트가 업데이트 될 때 호출됩니다. | 87 | 88 | ## OrderBook(string 또는 Array\) 89 | `OrderBook` 오브젝트 배열을 반환합니다. 90 | 91 | | 매개변수 | 타입 | 설명 | 92 | |----------------|--------------------------- |-------------------------------------| 93 | | market | string 또는 Array\ | 'KRW-BTC' 또는 ['KRW-BTC', 'KRW-XRP'] | 94 | 95 | ### OrderBook class 96 | | 매개변수 | 타입 | 설명 | 97 | |------------|------------------|---------------------------| 98 | | market | string | ex) KRW, BTC, USDT ... | 99 | | coin | string | ex) BTC, ETH, XRP ... | 100 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 101 | | lastUpdate | `Date` | 이 객체가 업데이트된 시간 | 102 | | askList | Array\<`Order`\> | Ask 오더 리스트 | 103 | | bidList | Array\<`Order`\> | Bid 오더 리스트 | 104 | | totalAsk | number | 토탈 ask | 105 | | totalBid | number | 토탈 bid | 106 | 107 | ### Order class 108 | | 매개변수 | 타입 | 설명 | 109 | |----------|--------|--------| 110 | | price | number | 가격 | 111 | | size | number | 주문량 | 112 | 113 | ## autoOrderBookUpDate(orderBook, time , errorHandler, callback?) 114 | `OrderBook` 오브젝트를 일정 시간마다 업데이트 합니다. 115 | 116 | | 매개변수 | 타입 | 설명 | 117 | |----------------|--------------------------- |---------------------------------------| 118 | | orderBook | `OrderBook` 또는 Array\ |업데이트 될 `OrderBook` 오브젝트 | 119 | | time | number | 업데이트 주기 (밀리초) | 120 | | errorHandler | function, (error) => any | 에러 핸들러 | 121 | | callback | function, (orderBook) => any | 선택사항, 오브젝트가 업데이트 될 때 호출됩니다. | 122 | 123 | ## ticks(market) 124 | `Trade` 오브젝트 배열을 반환합니다. 125 | 126 | | 매개변수 | 타입 | 설명 | 127 | |----------|-----------------------------|---------------------------------------| 128 | | params | string 또는 Array\ | 'KRW-BTC' 또는 ['KRW-BTC', 'KRW-XRP'] | 129 | | count | number | count | 130 | | to | string | HHmmss 또는 HH:mm:ss | 131 | | cursor | number | sequential_id | 132 | 133 | ### Trade class 134 | | 이름 | 타입 | 설명 | 135 | |--------------------|---------|---------------------------| 136 | | market | string | ex) KRW, BTC, USDT ... | 137 | | coin | string | ex) BTC, ETH, XRP ... | 138 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 139 | | lastUpdate | `Date` | 이 객체가 업데이트된 시간 | 140 | | tradeTime | `Date` | 체결 시간 | 141 | | price | number | 체결 가격 | 142 | | volume | number | 체결 거래량 | 143 | | prev_closing_price | number | 전일 종가 | 144 | | change_price | number | 변화량 | 145 | | isAsk | boolean | 매도/매수 | 146 | | sequential_id | number | 체결 번호(Unique) | 147 | 148 | ## candlesMinutes(market, unit?, count?, to?) 149 | `Candle` 오브젝트 배열을 반환합니다. 150 | 151 | | 매개변수 | 타입 | 설명 | 152 | |----------------|--------------------------- |-------------------------------------| 153 | | market | string or Array\ | 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] | 154 | | unit | number | 1, 3, 5, 15, 10, 30, 60, 240 | 155 | | count | number | 갯수 | 156 | | to | string | yyyy-MM-dd'T'HH:mm:ssXXX | 157 | 158 | ### Candle class 159 | | 이름 | 타입 | 설명 | 160 | |-------------------|--------|---------------------------| 161 | | market | string | ex) KRW, BTC, USDT ... | 162 | | coin | string | ex) BTC, ETH, XRP ... | 163 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 164 | | timestamp | number | 마지막 틱이 저장된 시각 | 165 | | candleDateTimeUTC | `Date` | 캔들 기준 시각(UTC 기준) | 166 | | candleDateTimeKST | `Date` | 캔들 기준 시각(KST 기준) | 167 | | open | number | 시가 | 168 | | high | number | 고가 | 169 | | low | number | 저가 | 170 | | accTradePrice | number | 누적 거래대금 | 171 | | accTradeVolume | number | 누적 거래대금 수량 | 172 | | lastUpdate | `Date` | 이 객체가 업데이트된 시간 | 173 | 174 | #### MinutesCandle class 175 | `MinutesCandle` extends `Candle` 176 | | 이름 | 타입 | 설명 | 177 | |------|--------|---------------------------------------------| 178 | | unit | number | 분, 가능한 분: 1, 3, 5, 15, 10, 30, 60, 240 | 179 | #### DayCandle class 180 | `DayCandle` extends `Candle` 181 | 182 | | 이름 | 타입 | 설명 | 183 | |---------------------|--------|---------------------------------------| 184 | | prevClosingPrice | number | 전일 종가(UTC 0시 기준) | 185 | | convertedTradePrice | number | 종가 환산 화폐 단위로 환산된 가격(요청에 convertingPriceUnit 파라미터 없을 시 해당 필드 undefined) | 186 | | changePrice | number | 전일 종가 대비 변화 금액 | 187 | | changeRate | number | 전일 종가 대비 변화량 | 188 | #### WeekMonthCandle class 189 | `WeekMonthCandle` extends `Candle` 190 | 191 | | Name | Type | Description | 192 | |------------------|--------|------------------------| 193 | | firstDayOfPeriod | number | 캔들 기간의 가장 첫 날 | 194 | ## allMarket() 195 | 업비트에서 거래 가능한 마켓 목록 196 | 197 | 매개변수가 없습니다. 198 | 199 | | 이름 | 타입 | 설명 | 200 | |--------------|--------|---------------------------------------------------| 201 | | market | string | 업비트에서 제공하는 마켓 정보 예) BTC-XRP | 202 | | korean_name | string | 한국어 이름 예) 비트코인 | 203 | | english_name | string | 영어 이름 예) Bitcoin | 204 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import Market from "./container/Market"; 2 | import OrderBook from "./container/OrderBook"; 3 | import Order from "./container/Order"; 4 | import Trade from "./container/Trade"; 5 | import Candle from "./container/Candle"; 6 | import MinutesCandle from "./container/candles/MinutesCandle"; 7 | import DayCandle from "./container/candles/DayCandle"; 8 | import WeekMonthCandle from "./container/candles/WeekCandleMonth"; 9 | 10 | const request = require("request"); 11 | 12 | function setMarketData(market, v) { 13 | market.tradeTime = new Date(v['trade_timestamp']); 14 | market.price = v['trade_price']; 15 | market.open = v['opening_price']; 16 | market.high = v['high_price']; 17 | market.low = v['low_price']; 18 | market.prevClose = v['prev_closing_price']; 19 | market.change = v['change']; 20 | market.changePrice = v['change_price']; 21 | market.changeRate = v['change_rate']; 22 | market.signedChangePrice = v['signed_change_price']; 23 | market.signedChangeRate = v['signed_change_rate']; 24 | market.tradeVolume = v['trade_volume']; 25 | market.accTradePrice = v['acc_trade_price']; 26 | market.accTradePrice24 = v['acc_trade_price_24h']; 27 | market.accTradeVolume = v['acc_trade_volume']; 28 | market.accTradeVolume24 = v['acc_trade_volume_24h']; 29 | market.high52wPrice = v['highest_52_week_price']; 30 | market.high52wDate = new Date(v['highest_52_week_date']); 31 | market.low52wPrice = v['lowest_52_week_price']; 32 | market.low52wDate = new Date(v['lowest_52_week_date']); 33 | market.lastUpdate = new Date(); 34 | } 35 | 36 | /** 37 | * Create new Market object arrays. 38 | * @param market example: ['KRW-BTC', 'KRW-XRP'] 39 | */ 40 | function ticker(market: Array): Promise> { 41 | return new Promise((resolve, reject) => { 42 | const options = { 43 | method: 'GET', 44 | url: 'https://api.upbit.com/v1/ticker', 45 | qs: {markets: market.toString()} 46 | }; 47 | request(options, (error, response, body) => { 48 | if (error) reject(error); 49 | else { 50 | const data = []; 51 | body = JSON.parse(body.toString()); 52 | body.forEach(v => { 53 | const market = new Market(v['market'].split('-')[0], v['market'].split('-')[1]); 54 | setMarketData(market, v); 55 | data.push(market); 56 | }); 57 | resolve(data); 58 | } 59 | }); 60 | }); 61 | } 62 | 63 | /** 64 | * Updates object [market] every specified [time] time. 65 | * @param market An object or an Array to update 66 | * @param time update interval(ms) 67 | * @param {(error) => any} errorHandler 68 | * @param {(market) => any} callback called when updated, optional 69 | */ 70 | function autoMarketUpdate(market: any, time: number, errorHandler: (error) => any, callback?: (market) => any): void { 71 | const run = market => setInterval(() => { 72 | const options = { 73 | method: 'GET', url: 'https://api.upbit.com/v1/ticker', qs: {markets: `${market.market}-${market.coin}`} 74 | }; 75 | request(options, (error, response, body) => { 76 | if (error) errorHandler(error); 77 | else { 78 | body = JSON.parse(body.toString())[0]; 79 | setMarketData(market, body); 80 | if (callback) callback(market); 81 | } 82 | }); 83 | }, time); 84 | if (Array.isArray(market)) market.forEach(v => run(v)); 85 | else run(market); 86 | 87 | } 88 | 89 | function setOrderBookData(v, orderBook: OrderBook): OrderBook { 90 | const ask = []; 91 | const bid = []; 92 | v['orderbook_units'].forEach(v => { 93 | ask.push(new Order(v['ask_price'], v['ask_size'])); 94 | bid.push(new Order(v['bid_price'], v['bid_size'])); 95 | }); 96 | orderBook.askList = ask; 97 | orderBook.bidList = bid; 98 | return orderBook; 99 | } 100 | 101 | function autoOrderBookUpdate(orderBook: any, time: number, errorHandler: (error) => any, callback?: (orderBook) => any): void { 102 | const run = orderBook => setInterval(() => { 103 | request({ 104 | method: 'GET', 105 | url: 'https://api.upbit.com/v1/orderbook', 106 | qs: {markets: `${orderBook.market}-${orderBook.coin}`} 107 | }, (error, response, body) => { 108 | if (error) errorHandler(error); 109 | body = JSON.parse(body); 110 | setOrderBookData(body[0], orderBook); 111 | if (callback) callback(orderBook); 112 | }); 113 | }, time); 114 | if (Array.isArray(orderBook)) orderBook.forEach(v => run(v)); 115 | else run(orderBook); 116 | 117 | } 118 | 119 | /** 120 | * Load the order book. 121 | * @param market 122 | */ 123 | function orderBook(market: any): Promise> { 124 | return new Promise((resolve, reject) => { 125 | request({ 126 | method: 'GET', 127 | url: 'https://api.upbit.com/v1/orderbook', 128 | qs: {markets: market.toString()} 129 | }, (error, response, body) => { 130 | if (error) reject(error); 131 | body = JSON.parse(body); 132 | resolve(body.map(v => setOrderBookData(v, new OrderBook(v['market'].split('-')[0], v['market'].split('-')[1])))); 133 | }); 134 | }); 135 | } 136 | 137 | function setTradeData(v, trade: Trade): Trade { 138 | trade.tradeTime = new Date(v['timestamp']); 139 | trade.price = v['trade_price']; 140 | trade.volume = v['trade_volume']; 141 | trade.prev_closing_price = v['prev_closing_price']; 142 | trade.change_price = v['change_price']; 143 | trade.sequential_id = v['sequential_id']; 144 | trade.isAsk = v['ask_bid'] === 'ASK'; 145 | trade.lastUpdate = new Date(); 146 | return trade; 147 | } 148 | 149 | /** 150 | * ticks 151 | * @param {string | Array}market ex) KRW-XRP 152 | * @param {number} count 153 | * @param {string} to HHmmss or HH:mm:ss 154 | * @param {number} cursor sequential_id 155 | */ 156 | function ticks(market: string | Array, count: number = 1, to?: string, cursor?: number): Promise> { 157 | return new Promise((resolve, reject) => { 158 | const options = { 159 | method: 'GET', 160 | url: 'https://api.upbit.com/v1/trades/ticks', 161 | qs: { 162 | market: market.toString(), 163 | count: count, 164 | } 165 | }; 166 | // @ts-ignore 167 | if (to) options.qs.to = to; 168 | // @ts-ignore 169 | if (cursor) options.qs.cursor = curosr; 170 | request(options, (error, response, body) => { 171 | if (error) reject(error); 172 | else resolve(JSON.parse(body.toString()).map(v => 173 | setTradeData(v, new Trade(v['market'].split('-')[0], v['market'].split('-')[1])))); 174 | 175 | }); 176 | }); 177 | } 178 | 179 | function setCandle(v, candle: Candle, type = 0): Candle { 180 | candle.accTradePrice = v.candle_acc_trade_volume; 181 | candle.accTradePrice = v.candle_acc_trade_price; 182 | candle.price = v['trade_price']; 183 | candle.high = v['high_price']; 184 | candle.low = v['low_price']; 185 | candle.open = v['opening_price']; 186 | candle.candleDateTimeUTC = new Date(`${v['candle_date_time_utc']}+0000`); 187 | candle.candleDateTimeKST = new Date(`${v['candle_date_time_kst']}+0900`); 188 | candle.timestamp = v['timestamp']; 189 | if (type === 0) setMinutesCandle(v, candle); 190 | if (type === 1) setDayCandle(v, candle); 191 | if (type === 2) setWeekMonthCandle(v, candle); 192 | return candle; 193 | } 194 | 195 | function setMinutesCandle(v, candle: MinutesCandle): MinutesCandle { 196 | candle.unit = v.unit; 197 | return candle; 198 | } 199 | 200 | function setWeekMonthCandle(v, candle: WeekMonthCandle): WeekMonthCandle { 201 | console.log(v); 202 | candle.firstDayOfPeriod = v.first_day_of_period; 203 | return candle; 204 | } 205 | 206 | function setDayCandle(v, candle: DayCandle): DayCandle { 207 | candle.changePrice = v.change_price; 208 | candle.changeRate = v.change_rate; 209 | candle.convertedTradePrice = v.converted_trade_price; 210 | candle.prevClosingPrice = v.prev_closing_price; 211 | return candle; 212 | } 213 | 214 | /** 215 | * get minutes candles 216 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 217 | * @param unit 1, 3, 5, 15, 10, 30, 60, 240 218 | * @param count count of candles 219 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 220 | */ 221 | function candlesMinutes(market: string | Array, unit: number, count?: number, to?: string): Promise> { 222 | return new Promise((resolve, reject) => { 223 | const options = { 224 | method: 'GET', 225 | url: `https://api.upbit.com/v1/candles/minutes/${unit}`, 226 | qs: { 227 | market: market.toString(), 228 | } 229 | }; 230 | // @ts-ignore 231 | if (count) options.qs.count = count; 232 | // @ts-ignore 233 | if (to) options.qs.to = to; 234 | request(options, (error, response, body) => { 235 | if (error) reject(error); 236 | else resolve(JSON.parse(body.toString()).map(v => 237 | setCandle(v, new Candle(v['market'].split('-')[0], v['market'].split('-')[1])))); 238 | }); 239 | }); 240 | } 241 | 242 | /** 243 | * get days candles 244 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 245 | * @param count count of candles 246 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 247 | * @param convertingPriceUnit default : KRW 248 | */ 249 | function candlesDay(market: string | Array, count?: number, to?: string, convertingPriceUnit?: string): Promise> { 250 | return new Promise((resolve, reject) => { 251 | const options = { 252 | method: 'GET', 253 | url: `https://api.upbit.com/v1/candles/days`, 254 | qs: { 255 | market: market.toString(), 256 | } 257 | }; 258 | // @ts-ignore 259 | if (count) options.qs.count = count; 260 | // @ts-ignore 261 | if (to) options.qs.to = to; 262 | // @ts-ignore 263 | if (convertingPriceUnit) options.qs.convertingPriceUnit = convertingPriceUnit; 264 | request(options, (error, response, body) => { 265 | if (error) reject(error); 266 | else resolve(JSON.parse(body.toString()).map(v => 267 | setCandle(v, new Candle(v['market'].split('-')[0], v['market'].split('-')[1]), 1))); 268 | }); 269 | }); 270 | } 271 | 272 | /** 273 | * get weeks candles 274 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 275 | * @param count count of candles 276 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 277 | */ 278 | function candlesWeek(market: string | Array, count?: number, to?: string): Promise> { 279 | return new Promise((resolve, reject) => { 280 | const options = { 281 | method: 'GET', 282 | url: `https://api.upbit.com/v1/candles/weeks`, 283 | qs: { 284 | market: market.toString(), 285 | } 286 | }; 287 | // @ts-ignore 288 | if (count) options.qs.count = count; 289 | // @ts-ignore 290 | if (to) options.qs.to = to; 291 | request(options, (error, response, body) => { 292 | if (error) reject(error); 293 | else resolve(JSON.parse(body.toString()).map(v => 294 | setCandle(v, new Candle(v['market'].split('-')[0], v['market'].split('-')[1]), 2))); 295 | }); 296 | }); 297 | } 298 | 299 | /** 300 | * get months candles 301 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 302 | * @param count count of candles 303 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 304 | */ 305 | function candlesMonth(market: string | Array, count?: number, to?: string): Promise> { 306 | return new Promise((resolve, reject) => { 307 | const options = { 308 | method: 'GET', 309 | url: `https://api.upbit.com/v1/candles/months`, 310 | qs: { 311 | market: market.toString(), 312 | } 313 | }; 314 | // @ts-ignore 315 | if (count) options.qs.count = count; 316 | // @ts-ignore 317 | if (to) options.qs.to = to; 318 | request(options, (error, response, body) => { 319 | if (error) reject(error); 320 | else resolve(JSON.parse(body.toString()).map(v => 321 | setCandle(v, new Candle(v['market'].split('-')[0], v['market'].split('-')[1]), 2))); 322 | }); 323 | }); 324 | } 325 | 326 | function allMarket() { 327 | return new Promise((resolve, reject) => { 328 | const options = { 329 | method: 'GET', 330 | url: `https://api.upbit.com/v1/market/all` 331 | }; 332 | request(options, (error, response, body) => { 333 | if (error) reject(error); 334 | else resolve(JSON.parse(body.toString())); 335 | }); 336 | }); 337 | } 338 | 339 | export default { 340 | ticker, 341 | autoMarketUpdate, 342 | orderBook, 343 | autoOrderBookUpdate, 344 | ticks, 345 | candlesMinutes, 346 | candlesDay, 347 | candlesWeek, 348 | candlesMonth, 349 | allMarket 350 | }; 351 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # upbit-api 2 | [![npm](https://img.shields.io/npm/v/upbit-api.svg?style=flat-square)](https://www.npmjs.com/package/upbit-api) 3 | [![npm](https://img.shields.io/npm/dt/upbit-api.svg?style=flat-square)](https://www.npmjs.com/package/upbit-api) 4 | [![npm](https://img.shields.io/npm/l/upbit-api.svg?registry_uri=https%3A%2F%2Fregistry.npmjs.com&style=flat-square)](https://opensource.org/licenses/MIT) 5 | [![npm](https://img.shields.io/badge/Readme-English-lightgray.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README.md) 6 | [![npm](https://img.shields.io/badge/Readme-한국어-blue.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-KR.md) 7 | [![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-JP.md) 8 | [![npm](https://img.shields.io/badge/Readme-汉语-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/upbit-api/blob/master/README-CN.md) 9 | 10 | upbit-api is an API that makes Upbit OpenAPI easy to use. 11 | 12 | This api will support the Restful API and Websocket API. 13 | 14 | It was created with Typescript and compiled into es2017. 15 | ## Coverage Table 16 | The **§** symbol includes auto-update: 17 | `autoMarketUpdate` or `autoOrderBookUpdate` 18 | 19 | WS is WebSocket. 20 | 21 | | Method | Upbit | upbit-api | version | 22 | |--------|-----------------------|-----------------|-----------------| 23 | | GET | /ticker | ticker **§** | 0.0.1+ | 24 | | GET | /orderbook | orderBook **§** | 0.2.0+ | 25 | | GET | /trades/ticks | ticks | 0.5.0+ | 26 | | GET | /candles/minutes/unit | candlesMinutes | 0.6.0+ | 27 | | GET | /market/all | allMarket | 0.7.0+ | 28 | | GET | /candles/days | candlesDay | 0.9.0+ | 29 | | GET | /candles/weeks | candlesWeek | 0.10.0+ | 30 | | GET | /candles/months | candlesMonth | 0.10.0+ | 31 | | GET | /accounts | Unsupported | At least 0.11.0 | 32 | | GET | /orders/chance | Unsupported | At least 0.11.0 | 33 | | GET | /order | Unsupported | At least 0.11.0 | 34 | | GET | /orders | Unsupported | At least 0.11.0 | 35 | | POST | /orders | Unsupported | At least 0.11.0 | 36 | | DELETE | /order | Unsupported | At least 0.11.0 | 37 | | GET | /withdraws | Unsupported | At least 0.11.0 | 38 | | GET | /withdraw | Unsupported | At least 0.11.0 | 39 | | GET | /withdraws/chance | Unsupported | At least 0.11.0 | 40 | | POST | /withdraws/coin | Unsupported | At least 0.11.0 | 41 | | POST | /withdraws/krw | Unsupported | At least 0.11.0 | 42 | | GET | /deposits | Unsupported | At least 0.11.0 | 43 | | WS | ticker | Unsupported | At least 0.11.0 | 44 | | WS | trade | Unsupported | At least 0.11.0 | 45 | | WS | orderbook | Unsupported | At least 0.11.0 | 46 | 47 | ## ticker(market) 48 | Create new `Market` object arrays. 49 | 50 | | Parameter | Type | Description | 51 | |----------------|--------------------------- |-------------------------------------| 52 | | market | string or Array\ | 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] | 53 | ### Market class 54 | | Parameter | Type | Description | 55 | |-------------------|--------|--------------------------------------------| 56 | | market | string | ex) KRW, BTC, USDT ... | 57 | | coin | string | ex) BTC, ETH, XRP ... | 58 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 59 | | tradeTime | `Date` | trade time | 60 | | price | number | price | 61 | | open | number | Market value | 62 | | high | number | Highest price | 63 | | low | number | Lowest price | 64 | | prevClose | number | the closing price of the previous day | 65 | | change | number | EVEN: Mixture RISE: Rise FALL: Fall | 66 | | changePrice | number | Absolute value of change amount | 67 | | changeRate | number | Absolute value of change rate | 68 | | signedChangePrice | number | signed change Price | 69 | | signedChangeRate | number | signed change rate | 70 | | tradeVolume | number | Latest volume | 71 | | accTradePrice | number | accTradePrice | 72 | | accTradePrice24 | number | accTradePrice24 | 73 | | accTradeVolume | number | Cumulative transaction amount(UTC 0) | 74 | | accTradeVolume24 | number | Cumulative transaction amount for 24 hours | 75 | | high52wPrice | number | 52 Weeks New Highest Price | 76 | | high52wDate | `Date` | 52 Weeks New Highest Price'Date | 77 | | low52wPrice | number | 52 Weeks New Lowest Price | 78 | | low52wDate | `Date` | 52 Weeks New Lowest Price's Date | 79 | | lastUpdate | `Date` | The time when this object updated | 80 | 81 | ## autoMarketUpdate(market, time , errorHandler, callback?) 82 | Updates object `market` every specified `time` time. 83 | 84 | | Parameter | Type | Description | 85 | |----------------|--------------------------- |---------------------------------------| 86 | | market | `Market` or Array\ | `Market` object that will be updated. | 87 | | time | number | Frequency to update (in milliseconds) | 88 | | errorHandler | function, (error) => any | error handler | 89 | | callback | function, (market) => any | optional, this function called when object updated. | 90 | 91 | 92 | ## OrderBook(market) 93 | Create new `OrderBook` object arrays. 94 | 95 | | Parameter | Type | Description | 96 | |----------------|--------------------------- |-------------------------------------| 97 | | market | string or Array\ | 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] | 98 | 99 | ### OrderBook class 100 | | Name | Type | Description | 101 | |----------------|------- |-------------| 102 | | market | string | ex) KRW, BTC, USDT ... | 103 | | coin | string | ex) BTC, ETH, XRP ... | 104 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 105 | | lastUpdate | `Date` | The time when this object updated | 106 | | askList | Array\<`Order`\> | Ask order list | 107 | | bidList | Array\<`Order`\> | Bid order list | 108 | | totalAsk |number | total ask | 109 | | totalBid |number | total bid | 110 | 111 | ### Order class 112 | 113 | | Name | Type | Description | 114 | |----------------|------- |-------------| 115 | | price | number | price of order| 116 | | size | number | size of order | 117 | 118 | ## autoOrderBookUpDate(orderBook, time , errorHandler, callback?) 119 | Updates object `OrderBook` every specified `time` time. 120 | 121 | | Parameter | Type | Description | 122 | |----------------|--------------------------- |---------------------------------------| 123 | | orderBook | `OrderBook` or Array\ | `OrderBook` object that will be updated. | 124 | | time | number | Frequency to update (in milliseconds) | 125 | | errorHandler | function, (error) => any | error handler | 126 | | callback | function, (orderBook) => any | optional, this function called when object updated. | 127 | 128 | ## ticks(market, count?, to?, cursor?) 129 | Create new `Trade` object arrays. 130 | 131 | | Parameter | Type | Description | 132 | |----------------|--------------------------- |-------------------------------------| 133 | | market | string or Array\ | 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] | 134 | | count | number | count | 135 | | to | string | HHmmss or HH:mm:ss | 136 | | cursor | number | sequential_id | 137 | 138 | ### Trade class 139 | | Name | Type | Description | 140 | |--------------------|------- |-------------| 141 | | market | string | ex) KRW, BTC, USDT ... | 142 | | coin | string | ex) BTC, ETH, XRP ... | 143 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 144 | | lastUpdate | `Date` | The time when this object updated | 145 | | tradeTime | `Date` | The time when traded | 146 | | price | number | price of this trade | 147 | | volume | number | volume of this trade | 148 | | prev_closing_price | number | prev_closing_price | 149 | | change_price | number | price - prev_closing_price | 150 | | isAsk | boolean | Trade type | 151 | | sequential_id | number | Transaction Number(Unique) | 152 | 153 | ## candlesMinutes(market, unit?, count?, to?) 154 | Create `Candle` object arrays. 155 | 156 | | Parameter | Type | Description | 157 | |----------------|--------------------------- |-------------------------------------| 158 | | market | string or Array\ | 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] | 159 | | unit | number | 1, 3, 5, 15, 10, 30, 60, 240 | 160 | | count | number | count | 161 | | to | string | yyyy-MM-dd'T'HH:mm:ssXXX | 162 | 163 | ### Candle class 164 | | Name | Type | Description | 165 | |-------------------|--------|-----------------------------------------------------------| 166 | | market | string | ex) KRW, BTC, USDT ... | 167 | | coin | string | ex) BTC, ETH, XRP ... | 168 | | marketCode | string | ex) KRW-BTC, KRW-XRP ... | 169 | | timestamp | number | The time at which the last tick was stored in the candle. | 170 | | candleDateTimeUTC | `Date` | Standard time of the candle (UTC basis) | 171 | | candleDateTimeKST | `Date` | Standard time of the candle (KST basis) | 172 | | open | number | Market value | 173 | | high | number | Highest price | 174 | | low | number | Lowest price | 175 | | accTradePrice | number | Candle's accTradePrice | 176 | | accTradeVolume | number | Candle's cumulative transaction amount | 177 | | lastUpdate | `Date` | The time when this object updated | 178 | #### MinutesCandle class 179 | `MinutesCandle` extends `Candle` 180 | 181 | | Name | Type | Description | 182 | |-------------------|--------|-----------------------------------------------------------| 183 | | unit | number | minutes. Possible values: 1, 3, 5, 15, 10, 30, 60, 240 | 184 | #### DayCandle class 185 | `DayCandle` extends `Candle` 186 | 187 | | Name | Type | Description | 188 | |---------------------|--------|---------------------------------------| 189 | | prevClosingPrice | number | the closing price of the previous day | 190 | | convertedTradePrice | number | a price converted into denominations | 191 | | changePrice | number | value of change amount | 192 | | changeRate | number | value of change rate | 193 | #### WeekMonthCandle class 194 | `WeekMonthCandle` extends `Candle` 195 | 196 | | Name | Type | Description | 197 | |---------------------|--------|---------------------------------------| 198 | | firstDayOfPeriod | number | first day of period | 199 | ## allMarket() 200 | List of markets that can be traded at Upbit. 201 | 202 | | Name | Type | Description | 203 | |--------------|--------|---------------------------------------------------| 204 | | market | string | Market information provided by Upbit, ex) BTC-XRP | 205 | | korean_name | string | Korean name ex) 비트코인 | 206 | | english_name | string | English name ex) Bitcoin | 207 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Market_1 = require("./container/Market"); 4 | var OrderBook_1 = require("./container/OrderBook"); 5 | var Order_1 = require("./container/Order"); 6 | var Trade_1 = require("./container/Trade"); 7 | var Candle_1 = require("./container/Candle"); 8 | var request = require("request"); 9 | function setMarketData(market, v) { 10 | market.tradeTime = new Date(v['trade_timestamp']); 11 | market.price = v['trade_price']; 12 | market.open = v['opening_price']; 13 | market.high = v['high_price']; 14 | market.low = v['low_price']; 15 | market.prevClose = v['prev_closing_price']; 16 | market.change = v['change']; 17 | market.changePrice = v['change_price']; 18 | market.changeRate = v['change_rate']; 19 | market.signedChangePrice = v['signed_change_price']; 20 | market.signedChangeRate = v['signed_change_rate']; 21 | market.tradeVolume = v['trade_volume']; 22 | market.accTradePrice = v['acc_trade_price']; 23 | market.accTradePrice24 = v['acc_trade_price_24h']; 24 | market.accTradeVolume = v['acc_trade_volume']; 25 | market.accTradeVolume24 = v['acc_trade_volume_24h']; 26 | market.high52wPrice = v['highest_52_week_price']; 27 | market.high52wDate = new Date(v['highest_52_week_date']); 28 | market.low52wPrice = v['lowest_52_week_price']; 29 | market.low52wDate = new Date(v['lowest_52_week_date']); 30 | market.lastUpdate = new Date(); 31 | } 32 | /** 33 | * Create new Market object arrays. 34 | * @param market example: ['KRW-BTC', 'KRW-XRP'] 35 | */ 36 | function ticker(market) { 37 | return new Promise(function (resolve, reject) { 38 | var options = { 39 | method: 'GET', 40 | url: 'https://api.upbit.com/v1/ticker', 41 | qs: { markets: market.toString() } 42 | }; 43 | request(options, function (error, response, body) { 44 | if (error) 45 | reject(error); 46 | else { 47 | var data_1 = []; 48 | body = JSON.parse(body.toString()); 49 | body.forEach(function (v) { 50 | var market = new Market_1.default(v['market'].split('-')[0], v['market'].split('-')[1]); 51 | setMarketData(market, v); 52 | data_1.push(market); 53 | }); 54 | resolve(data_1); 55 | } 56 | }); 57 | }); 58 | } 59 | /** 60 | * Updates object [market] every specified [time] time. 61 | * @param market An object or an Array to update 62 | * @param time update interval(ms) 63 | * @param {(error) => any} errorHandler 64 | * @param {(market) => any} callback called when updated, optional 65 | */ 66 | function autoMarketUpdate(market, time, errorHandler, callback) { 67 | var run = function (market) { return setInterval(function () { 68 | var options = { 69 | method: 'GET', url: 'https://api.upbit.com/v1/ticker', 70 | qs: { markets: market.market + "-" + market.coin } 71 | }; 72 | request(options, function (error, response, body) { 73 | if (error) 74 | errorHandler(error); 75 | else { 76 | body = JSON.parse(body.toString())[0]; 77 | setMarketData(market, body); 78 | if (callback) 79 | callback(market); 80 | } 81 | }); 82 | }, time); }; 83 | if (Array.isArray(market)) 84 | market.forEach(function (v) { return run(v); }); 85 | else 86 | run(market); 87 | } 88 | function setOrderBookData(v, orderBook) { 89 | var ask = []; 90 | var bid = []; 91 | v['orderbook_units'].forEach(function (v) { 92 | ask.push(new Order_1.default(v['ask_price'], v['ask_size'])); 93 | bid.push(new Order_1.default(v['bid_price'], v['bid_size'])); 94 | }); 95 | orderBook.askList = ask; 96 | orderBook.bidList = bid; 97 | return orderBook; 98 | } 99 | function autoOrderBookUpdate(orderBook, time, errorHandler, callback) { 100 | var run = function (orderBook) { return setInterval(function () { 101 | request({ 102 | method: 'GET', 103 | url: 'https://api.upbit.com/v1/orderbook', 104 | qs: { markets: orderBook.market + "-" + orderBook.coin } 105 | }, function (error, response, body) { 106 | if (error) 107 | errorHandler(error); 108 | body = JSON.parse(body); 109 | setOrderBookData(body[0], orderBook); 110 | if (callback) 111 | callback(orderBook); 112 | }); 113 | }, time); }; 114 | if (Array.isArray(orderBook)) 115 | orderBook.forEach(function (v) { return run(v); }); 116 | else 117 | run(orderBook); 118 | } 119 | /** 120 | * Load the order book. 121 | * @param market 122 | */ 123 | function orderBook(market) { 124 | return new Promise(function (resolve, reject) { 125 | request({ 126 | method: 'GET', 127 | url: 'https://api.upbit.com/v1/orderbook', 128 | qs: { markets: market.toString() } 129 | }, function (error, response, body) { 130 | if (error) 131 | reject(error); 132 | body = JSON.parse(body); 133 | resolve(body.map(function (v) { return setOrderBookData(v, new OrderBook_1.default(v['market'].split('-')[0], v['market'].split('-')[1])); })); 134 | }); 135 | }); 136 | } 137 | function setTradeData(v, trade) { 138 | trade.tradeTime = new Date(v['timestamp']); 139 | trade.price = v['trade_price']; 140 | trade.volume = v['trade_volume']; 141 | trade.prev_closing_price = v['prev_closing_price']; 142 | trade.change_price = v['change_price']; 143 | trade.sequential_id = v['sequential_id']; 144 | trade.isAsk = v['ask_bid'] === 'ASK'; 145 | trade.lastUpdate = new Date(); 146 | return trade; 147 | } 148 | /** 149 | * ticks 150 | * @param {string | Array}market ex) KRW-XRP 151 | * @param {number} count 152 | * @param {string} to HHmmss or HH:mm:ss 153 | * @param {number} cursor sequential_id 154 | */ 155 | function ticks(market, count, to, cursor) { 156 | if (count === void 0) { count = 1; } 157 | return new Promise(function (resolve, reject) { 158 | var options = { 159 | method: 'GET', 160 | url: 'https://api.upbit.com/v1/trades/ticks', 161 | qs: { 162 | market: market.toString(), 163 | count: count, 164 | } 165 | }; 166 | // @ts-ignore 167 | if (to) 168 | options.qs.to = to; 169 | // @ts-ignore 170 | if (cursor) 171 | options.qs.cursor = curosr; 172 | request(options, function (error, response, body) { 173 | if (error) 174 | reject(error); 175 | else 176 | resolve(JSON.parse(body.toString()).map(function (v) { 177 | return setTradeData(v, new Trade_1.default(v['market'].split('-')[0], v['market'].split('-')[1])); 178 | })); 179 | }); 180 | }); 181 | } 182 | function setCandle(v, candle, type) { 183 | if (type === void 0) { type = 0; } 184 | candle.accTradePrice = v.candle_acc_trade_volume; 185 | candle.accTradePrice = v.candle_acc_trade_price; 186 | candle.price = v['trade_price']; 187 | candle.high = v['high_price']; 188 | candle.low = v['low_price']; 189 | candle.open = v['opening_price']; 190 | candle.candleDateTimeUTC = new Date(v['candle_date_time_utc'] + "+0000"); 191 | candle.candleDateTimeKST = new Date(v['candle_date_time_kst'] + "+0900"); 192 | candle.timestamp = v['timestamp']; 193 | if (type === 0) 194 | setMinutesCandle(v, candle); 195 | if (type === 1) 196 | setDayCandle(v, candle); 197 | if (type === 2) 198 | setWeekMonthCandle(v, candle); 199 | return candle; 200 | } 201 | function setMinutesCandle(v, candle) { 202 | candle.unit = v.unit; 203 | return candle; 204 | } 205 | function setWeekMonthCandle(v, candle) { 206 | console.log(v); 207 | candle.firstDayOfPeriod = v.first_day_of_period; 208 | return candle; 209 | } 210 | function setDayCandle(v, candle) { 211 | candle.changePrice = v.change_price; 212 | candle.changeRate = v.change_rate; 213 | candle.convertedTradePrice = v.converted_trade_price; 214 | candle.prevClosingPrice = v.prev_closing_price; 215 | return candle; 216 | } 217 | /** 218 | * get minutes candles 219 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 220 | * @param unit 1, 3, 5, 15, 10, 30, 60, 240 221 | * @param count count of candles 222 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 223 | */ 224 | function candlesMinutes(market, unit, count, to) { 225 | return new Promise(function (resolve, reject) { 226 | var options = { 227 | method: 'GET', 228 | url: "https://api.upbit.com/v1/candles/minutes/" + unit, 229 | qs: { 230 | market: market.toString(), 231 | } 232 | }; 233 | // @ts-ignore 234 | if (count) 235 | options.qs.count = count; 236 | // @ts-ignore 237 | if (to) 238 | options.qs.to = to; 239 | request(options, function (error, response, body) { 240 | if (error) 241 | reject(error); 242 | else 243 | resolve(JSON.parse(body.toString()).map(function (v) { 244 | return setCandle(v, new Candle_1.default(v['market'].split('-')[0], v['market'].split('-')[1])); 245 | })); 246 | }); 247 | }); 248 | } 249 | /** 250 | * get days candles 251 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 252 | * @param count count of candles 253 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 254 | * @param convertingPriceUnit default : KRW 255 | */ 256 | function candlesDay(market, count, to, convertingPriceUnit) { 257 | return new Promise(function (resolve, reject) { 258 | var options = { 259 | method: 'GET', 260 | url: "https://api.upbit.com/v1/candles/days", 261 | qs: { 262 | market: market.toString(), 263 | } 264 | }; 265 | // @ts-ignore 266 | if (count) 267 | options.qs.count = count; 268 | // @ts-ignore 269 | if (to) 270 | options.qs.to = to; 271 | // @ts-ignore 272 | if (convertingPriceUnit) 273 | options.qs.convertingPriceUnit = convertingPriceUnit; 274 | request(options, function (error, response, body) { 275 | if (error) 276 | reject(error); 277 | else 278 | resolve(JSON.parse(body.toString()).map(function (v) { 279 | return setCandle(v, new Candle_1.default(v['market'].split('-')[0], v['market'].split('-')[1]), 1); 280 | })); 281 | }); 282 | }); 283 | } 284 | /** 285 | * get weeks candles 286 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 287 | * @param count count of candles 288 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 289 | */ 290 | function candlesWeek(market, count, to) { 291 | return new Promise(function (resolve, reject) { 292 | var options = { 293 | method: 'GET', 294 | url: "https://api.upbit.com/v1/candles/weeks", 295 | qs: { 296 | market: market.toString(), 297 | } 298 | }; 299 | // @ts-ignore 300 | if (count) 301 | options.qs.count = count; 302 | // @ts-ignore 303 | if (to) 304 | options.qs.to = to; 305 | request(options, function (error, response, body) { 306 | if (error) 307 | reject(error); 308 | else 309 | resolve(JSON.parse(body.toString()).map(function (v) { 310 | return setCandle(v, new Candle_1.default(v['market'].split('-')[0], v['market'].split('-')[1]), 2); 311 | })); 312 | }); 313 | }); 314 | } 315 | /** 316 | * get months candles 317 | * @param market 'KRW-BTC' or ['KRW-BTC', 'KRW-XRP'] 318 | * @param count count of candles 319 | * @param to yyyy-MM-dd'T'HH:mm:ssXXX 320 | */ 321 | function candlesMonth(market, count, to) { 322 | return new Promise(function (resolve, reject) { 323 | var options = { 324 | method: 'GET', 325 | url: "https://api.upbit.com/v1/candles/months", 326 | qs: { 327 | market: market.toString(), 328 | } 329 | }; 330 | // @ts-ignore 331 | if (count) 332 | options.qs.count = count; 333 | // @ts-ignore 334 | if (to) 335 | options.qs.to = to; 336 | request(options, function (error, response, body) { 337 | if (error) 338 | reject(error); 339 | else 340 | resolve(JSON.parse(body.toString()).map(function (v) { 341 | return setCandle(v, new Candle_1.default(v['market'].split('-')[0], v['market'].split('-')[1]), 2); 342 | })); 343 | }); 344 | }); 345 | } 346 | function allMarket() { 347 | return new Promise(function (resolve, reject) { 348 | var options = { 349 | method: 'GET', 350 | url: "https://api.upbit.com/v1/market/all" 351 | }; 352 | request(options, function (error, response, body) { 353 | if (error) 354 | reject(error); 355 | else 356 | resolve(JSON.parse(body.toString())); 357 | }); 358 | }); 359 | } 360 | exports.default = { 361 | ticker: ticker, 362 | autoMarketUpdate: autoMarketUpdate, 363 | orderBook: orderBook, 364 | autoOrderBookUpdate: autoOrderBookUpdate, 365 | ticks: ticks, 366 | candlesMinutes: candlesMinutes, 367 | candlesDay: candlesDay, 368 | candlesWeek: candlesWeek, 369 | candlesMonth: candlesMonth, 370 | allMarket: allMarket 371 | }; 372 | --------------------------------------------------------------------------------