Skip to content

Commit e7441e8

Browse files
authored
Merge pull request #2 from icemilo/feature/add-markets-api
Add market list api
2 parents 8511fb1 + e57fe24 commit e7441e8

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

demo/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import upbit from '../src';
22

3-
const { getTicker, getMinCandles, getCandles, getTick, getOrderbook, subscribe } = upbit;
3+
const { getTicker, getMinCandles, getCandles, getTick, getOrderbook, getMarketList, subscribe } = upbit;
44

55
(async () => {
66
console.log('---------- getTicker() ----------')
@@ -18,6 +18,9 @@ const { getTicker, getMinCandles, getCandles, getTick, getOrderbook, subscribe }
1818
console.log('---------- getOrderbook() ----------')
1919
console.log(await getOrderbook());
2020

21+
console.log('---------- getMarketList() ----------')
22+
console.log(await getMarketList());
23+
2124
console.log('---------- subscribe() ----------')
2225
subscribe({
2326
reconnect: () => {

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getCandles,
77
getTick,
88
getOrderbook,
9+
getMarketList,
910
} from './quotation';
1011
import Exchange from './exchange';
1112

@@ -16,6 +17,7 @@ const upbit = {
1617
getCandles,
1718
getTick,
1819
getOrderbook,
20+
getMarketList,
1921
Exchange,
2022
};
2123

@@ -27,5 +29,6 @@ export {
2729
getCandles,
2830
getTick,
2931
getOrderbook,
32+
getMarketList,
3033
Exchange,
3134
};

src/quotation/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fetch from 'node-fetch';
33
import WebSocket from 'ws';
44
import { HOST, WSS_HOST, DEFAULT_MARKET, subscription } from '../constants';
5-
import type { SubscriptionOption, TimeUnit, Minute, Market, Candle, Tick, Orderbook } from '../type';
5+
import type { SubscriptionOption, TimeUnit, Minute, Market, Candle, Tick, Orderbook, MarketInfo } from '../type';
66
import { handleWsOpen, handleWsError, handleWsClose, getEndpoint, serializeArray } from '../utils';
77

88
/**
@@ -143,3 +143,19 @@ export const getOrderbook: Function = async (markets: Array<string> = [DEFAULT_M
143143

144144
return data;
145145
};
146+
147+
/**
148+
* Get list of markets available
149+
* https://api.upbit.com/v1/market/all
150+
*
151+
* @async
152+
* @return {Promise<Object>}
153+
*/
154+
export const getMarketList: Function = async (): Promise<Array<MarketInfo>> => {
155+
const pathname: string = 'market/all';
156+
const endpoint: string = getEndpoint(HOST, pathname, '');
157+
const result: Response = await fetch(endpoint);
158+
const data: Array<MarketInfo> = await result.json();
159+
160+
return data;
161+
};

src/type/MarketInfo.js.flow

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @flow
2+
export type MarketInfo = {
3+
market: string,
4+
korean_name: string,
5+
english_name: string,
6+
};

src/type/index.js.flow

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type { SubscriptionList } from './SubscriptionList';
44
export type { SubscriptionOption } from './SubscriptionOption';
55
export type { TimeUnit } from './TimeUnit';
66
export type { Minute } from './Minute';
7+
export type { MarketInfo } from './MarketInfo';
78
export type { Market } from './Market';
89
export type { Candle } from './Candle';
910
export type { Tick } from './Tick';

0 commit comments

Comments
 (0)