Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion ts/src/pro/upbit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import upbitRest from '../upbit.js';
import { ArrayCache, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
import type { Int, Str, Order, OrderBook, Trade, Ticker, Dict, Balances, Tickers, Strings } from '../base/types.js';
import type { Int, Str, Order, OrderBook, Trade, Ticker, Dict, Balances, Tickers, Strings, OHLCV } from '../base/types.js';
import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
import { jwt } from '../base/functions/rsa.js';
import Client from '../base/ws/Client.js';
import { InvalidOrder } from '../base/errors.js';

// ---------------------------------------------------------------------------

Expand All @@ -20,6 +21,7 @@ export default class upbit extends upbitRest {
'watchTickers': true,
'watchTrades': true,
'watchTradesForSymbols': true,
'watchOHLCV': true,
'watchOrders': true,
'watchMyTrades': true,
'watchBalance': true,
Expand Down Expand Up @@ -203,6 +205,27 @@ export default class upbit extends upbitRest {
return orderbook.limit ();
}

/**
* @method
* @name upbit#watchOHLCV
* @description watches information an OHLCV with timestamp, openingPrice, highPrice, lowPrice, tradePrice, baseVolume in 1s.
* @see https://docs.upbit.com/kr/reference/websocket-candle for Upbit KR
* @see https://global-docs.upbit.com/reference/websocket-candle for Upbit Global
* @param {string} symbol unified market symbol of the market orders were made in
* @param {string} timeframe specifies the OHLCV candle interval to watch. As of now, Upbit only supports 1s candles.
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {OHLCV[]} a list of [OHLCV structures]{@link https://docs.ccxt.com/#/?id=ohlcv-structure}
*/
async watchOHLCV (symbol: string, timeframe = '1s', since: Int = undefined, limit: Int = undefined, params = {}): Promise<OHLCV[]> {
if (timeframe !== '1s') {
throw new InvalidOrder (this.id + ' watchOHLCV does not support' + timeframe + ' candle.');
}
Comment thread
baileySoobinPark marked this conversation as resolved.
const timeFrameOHLCV = 'candle.' + timeframe;
return await this.watchPublic (symbol, timeFrameOHLCV);
}

handleTicker (client: Client, message) {
// 2020-03-17T23:07:36.511Z "onMessage" <Buffer 7b 22 74 79 70 65 22 3a 22 74 69 63 6b 65 72 22 2c 22 63 6f 64 65 22 3a 22 42 54 43 2d 45 54 48 22 2c 22 6f 70 65 6e 69 6e 67 5f 70 72 69 63 65 22 3a ... >
// { type: "ticker",
Expand Down Expand Up @@ -332,6 +355,27 @@ export default class upbit extends upbitRest {
client.resolve (stored, messageHash);
}

handleOHLCV (client: Client, message) {
// {
// type: 'candle.1s',
// code: 'KRW-USDT',
// candle_date_time_utc: '2025-04-22T09:50:34',
// candle_date_time_kst: '2025-04-22T18:50:34',
// opening_price: 1438,
// high_price: 1438,
// low_price: 1438,
// trade_price: 1438,
// candle_acc_trade_volume: 1145.8935,
// candle_acc_trade_price: 1647794.853,
// timestamp: 1745315434125,
// stream_type: 'REALTIME'
// }
const marketId = this.safeString (message, 'code');
const messageHash = 'candle.1s:' + marketId;
const ohlcv = this.parseOHLCV (message);
client.resolve (ohlcv, messageHash);
}

async authenticate (params = {}) {
this.checkRequiredCredentials ();
const wsOptions: Dict = this.safeDict (this.options, 'ws', {});
Expand Down Expand Up @@ -657,6 +701,7 @@ export default class upbit extends upbitRest {
'trade': this.handleTrades,
'myOrder': this.handleMyOrder,
'myAsset': this.handleBalance,
'candle.1s': this.handleOHLCV,
};
const methodName = this.safeString (message, 'type');
const method = this.safeValue (methods, methodName);
Expand Down