You may use various methods to test getting market prices by using WebSocket.
The most well-known methods are telsocket
or wscat
.
When you use
wscat
$ npm install -g wscat
$ wscat -c wss://sg-api.upbit.com/websocket/v1
connected (press CTRL+C to quit)
$ npm install -g wscat
$ wscat -c wss://id-api.upbit.com/websocket/v1
connected (press CTRL+C to quit)
$ npm install -g wscat
$ wscat -c wss://th-api.upbit.com/websocket/v1
connected (press CTRL+C to quit)
When you use
telsocket
$ telsocket -url wss://sg-api.upbit.com/websocket/v1
Connected!
$ telsocket -url wss://id-api.upbit.com/websocket/v1
Connected!
$ telsocket -url wss://th-api.upbit.com/websocket/v1
Connected!
If you want real-time information on the SGD-Bitcoin (SGD-BTC) market, you can make the request as follows.
$ telsocket -url wss://sg-api.upbit.com/websocket/v1
Connected!
> [{"ticket":"test"},{"type":"ticker","codes":["SGD-BTC"]}]
{"market":"SGD-BTC","opening_price":8450000.00000000,"high_price":8679000.00000000,"low_price":8445000.00000000,"trade_price":8629000.0,"prev_closing_price":8450000.00000000,"acc_trade_price":105514711074.18726000,"change":"RISE","change_price":179000.00000000,"signed_change_price":179000.00000000,"change_rate":0.0211834320,"signed_change_rate":0.0211834320,"ask_bid":"ASK","trade_volume":0.0105675,"acc_trade_volume":12312.36058857,"trade_date":"20180418","trade_time":"100729","trade_timestamp":1524046049000,"acc_ask_volume":5703.42273172,"acc_bid_volume":6608.93785685,"highest_52_week_price":28885000.00000000,"highest_52_week_date":"2018-01-06","lowest_52_week_price":3286000.00000000,"lowest_52_week_date":"2017-09-15","trade_status":"ACTIVE","market_state":"ACTIVE","market_state_for_ios":"ACTIVE","is_trading_suspended":false,"delisting_date":null,"market_warning":"NONE","timestamp":1524046049766,"acc_trade_price_24h":55330325803.78210000,"acc_trade_volume_24h":6448.96200341}
{"market":"SGD-BTC","opening_price":8450000.00000000,"high_price":8679000.00000000,"low_price":8445000.00000000,"trade_price":8629000.0,"prev_closing_price":8450000.00000000,"acc_trade_price":105515441503.850220000,"change":"RISE","change_price":179000.00000000,"signed_change_price":179000.00000000,"change_rate":0.0211834320,"signed_change_rate":0.0211834320,"ask_bid":"ASK","trade_volume":0.08464824,"acc_trade_volume":12312.44523681,"trade_date":"20180418","trade_time":"100730","trade_timestamp":1524046050000,"acc_ask_volume":5703.50737996,"acc_bid_volume":6608.93785685,"highest_52_week_price":28885000.00000000,"highest_52_week_date":"2018-01-06","lowest_52_week_price":3286000.00000000,"lowest_52_week_date":"2017-09-15","trade_status":"ACTIVE","market_state":"ACTIVE","market_state_for_ios":"ACTIVE","is_trading_suspended":false,"delisting_date":null,"market_warning":"NONE","timestamp":1524046050758,"acc_trade_price_24h":55330325803.78210000,"acc_trade_volume_24h":6448.96200341}
...
$ telsocket -url wss://id-api.upbit.com/websocket/v1
Connected!
> [{"ticket":"test"},{"type":"ticker","codes":["BTC-ETH"]}]
{"type":"ticker","code":"BTC-ETH","opening_price":0.02040727,"high_price":0.02080000,"low_price":0.02005003,"trade_price":0.02033990,"prev_closing_price":0.02040727,"acc_trade_price":28.94601828,"change":"FALL","change_price":0.00006737,"signed_change_price":-0.00006737,"change_rate":0.0033012745,"signed_change_rate":-0.0033012745,"ask_bid":"BID","trade_volume":0.14347633,"acc_trade_volume":1424.31382618,"trade_date":"20191125","trade_time":"092304","trade_timestamp":1574673784000,"acc_ask_volume":1092.53436480,"acc_bid_volume":331.77946138,"highest_52_week_price":0.04167024,"highest_52_week_date":"2019-01-05","lowest_52_week_price":0.01614901,"lowest_52_week_date":"2019-09-06","trade_status":null,"market_state":"ACTIVE","market_state_for_ios":null,"is_trading_suspended":false,"delisting_date":null,"market_warning":"NONE","timestamp":1574673784242,"acc_trade_price_24h":86.0899596010439837,"acc_trade_volume_24h":4209.39183766,"stream_type":"SNAPSHOT"}
{"type":"ticker","code":"BTC-ETH","opening_price":0.02040727,"high_price":0.02080000,"low_price":0.02005003,"trade_price":0.02033990,"prev_closing_price":0.02040727,"acc_trade_price":28.94601828,"change":"FALL","change_price":0.00006737,"signed_change_price":-0.00006737,"change_rate":0.0033012745,"signed_change_rate":-0.0033012745,"ask_bid":"BID","trade_volume":0.14347633,"acc_trade_volume":1424.31382618,"trade_date":"20191125","trade_time":"092304","trade_timestamp":1574673784000,"acc_ask_volume":1092.53436480,"acc_bid_volume":331.77946138,"highest_52_week_price":0.04167024,"highest_52_week_date":"2019-01-05","lowest_52_week_price":0.01614901,"lowest_52_week_date":"2019-09-06","trade_status":null,"market_state":"ACTIVE","market_state_for_ios":null,"is_trading_suspended":false,"delisting_date":null,"market_warning":"NONE","timestamp":1574673784242,"acc_trade_price_24h":86.0899596010439837,"acc_trade_volume_24h":4209.39183766,"stream_type":"REALTIME"}
If you do not specify whether you want to receive only snapshot information or real-time information, you will receive "Snapshot Information" first and then "Real-time Information" continuously.
If you want to receive information on multiple markets simultaneously, you can indicate multiple markets in the codes
field by separating them with commas (,).
For example, if you want to receive only "real-time trade information" in a "simplified format" from the SGD-Bitcoin (SGD-BTC) market and Bitcoin-Ravencoin (BTC-RVN) market, you can make the following request.
$ telsocket -url wss://sg-api.upbit.com/websocket/v1
Connected!
[{"ticket":"test"},{"format":"SIMPLE"},{"type":"trade","codes":["SGD-BTC","BTC-RVN"]}]
{"mk":"SGD-BTC","tms":1523531768829,"td":"2018-04-12","ttm":"11:16:03","ttms":1523531763000,"tp":7691000.0,"tv":0.00996719,"ab":"BID","pcp":7429000.00000000,"c":"RISE","cp":262000.00000000,"sid":1523531768829000,"st":"SNAPSHOT"}
{"mk":"BTC-RVN","tms":1523531745481,"td":"2018-04-12","ttm":"11:15:48","ttms":1523531748370,"tp":0.09601999,"tv":0.18711789,"ab":"BID","pcp":0.09618000,"c":"FALL","cp":0.00016001,"sid":15235317454810000,"st":"SNAPSHOT"}
{"mk":"SGD-BTC","tms":1523531769250,"td":"2018-04-12","ttm":"11:16:04","ttms":1523531764000,"tp":7691000.0,"tv":0.07580113,"ab":"BID","pcp":7429000.00000000,"c":"RISE","cp":262000.00000000,"sid":1523531769250000,"st":"REALTIME"}
...
$ telsocket -url wss://id-api.upbit.com/websocket/v1
Connected!
> [{"ticket":"test"},{"format":"SIMPLE"},{"type":"trade","codes":["IDR-BTC"]},{"format":"SIMPLE"}]
{"ty":"trade","cd":"IDR-BTC","tms":1574675162100,"td":"2019-11-25","ttm":"09:46:01","ttms":1574675161000,"tp":96670000.0,"tv":0.02958988,"ab":"ASK","pcp":99850000.00000000,"c":"FALL","cp":3180000.00000000,"sid":1574675161000001,"st":"SNAPSHOT"}
{"ty":"trade","cd":"IDR-BTC","tms":1574675342766,"td":"2019-11-25","ttm":"09:49:02","ttms":1574675342000,"tp":97080000.0,"tv":0.01029073,"ab":"BID","pcp":99850000.00000000,"c":"FALL","cp":2770000.00000000,"sid":1574675342000000,"st":"REALTIME"}
In the same way, you will receive a snapshot first, followed by the real-time transaction status.
All of the above requests are based on the assumption that the WebSocket connection is successful.
Some additional request examples are as follows.
trade
data of the SGD-BTC and BTC-XRP markets.
[{"ticket":"UNIQUE_TICKET"},{"type":"trade","codes":["SGD-BTC","BTC-XRP"]}]orderbook
data of the SGD-BTC and BTC-XRP markets
[{"ticket":"UNIQUE_TICKET"},{"type":"orderbook","codes":["SGD-BTC","BTC-XRP"]}]trade
data from the SGD-BTC market andorderbook
data from the BTC-ETH market
[{"ticket":"UNIQUE_TICKET"},{"type":"trade","codes":["SGD-BTC"]},{"type":"orderbook","codes":["BTC-ETH"]}]trade
data from the SGD-BTC market,orderbook
data from the BTC-ETH market,ticker
data from the BTC-EOS market
[{"ticket":"UNIQUE_TICKET"},{"type":"trade","codes":["SGD-BTC"]},{"type":"orderbook","codes":["BTC-ETH"]},{"type":"ticker", "codes":["BTC-EOS"]}]
If you are requesting multiple types of information simultaneously, you can categorize the information types through the "type
" field in DEFAULT format and "ty
" field in SIMPLE format.