-
Notifications
You must be signed in to change notification settings - Fork 64
/
market.js
200 lines (183 loc) · 4.76 KB
/
market.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const axios = require('axios')
const Market = {}
/*
Get Symbols List
GET /api/v1/symbols
market = string [optional]
*/
Market.getSymbols = async function(market = "") {
let endpoint = ""
if (market != "") {
endpoint = `/api/v1/symbols?market=${market}`
} else {
endpoint = "/api/v1/symbols"
}
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Ticker
GET /api/v1/market/orderbook/level1?symbol=<symbol>
symbol = string
*/
Market.getTicker = async function(symbol) {
let endpoint = `/api/v1/market/orderbook/level1?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get All Tickers
GET /api/v1/market/allTickers
*/
Market.getAllTickers = async function() {
let endpoint = '/api/v1/market/allTickers'
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get 24hr Stats
GET /api/v1/market/stats?symbol=<symbol>
symbol = string
*/
Market.get24hrStats = async function(symbol) {
let endpoint = `/api/v1/market/stats?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Market List
GET /api/v1/markets
*/
Market.getMarketList = async function() {
let endpoint = '/api/v1/markets'
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Part Order Book (aggregated)
GET /api/v1/market/orderbook/level2_20?symbol=<symbol>
GET /api/v1/market/orderbook/level2_100?symbol=<symbol>
params = {
amount: integer (20 || 100)
symbol: string
}
*/
Market.getPartOrderBook = async function(params) {
let endpoint = `/api/v1/market/orderbook/level2_${params.amount}?symbol=${params.symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Full Order Book (aggregated)
GET /api/v1/market/orderbook/level2?symbol=<symbol>
symbol = string
*/
Market.getOrderBook = async function(symbol) {
let endpoint = `/api/v1/market/orderbook/level2?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Full Order Book (aggregated)
GET /api/v2/market/orderbook/level2?symbol=<symbol>
symbol = string
*/
Market.getFullOrderBook = async function(symbol) {
let endpoint = `/api/v3/market/orderbook/level2?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Full Order Book (atomic)
GET /api/v1/market/orderbook/level3?symbol=<symbol>
symbol = string
*/
Market.getFullOrderBookAtomic = async function(symbol) {
let endpoint = `/api/v3/market/orderbook/level3?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Trade Histories
GET /api/v1/market/histories?symbol=<symbol>
symbol = string
*/
Market.getTradeHistories = async function(symbol) {
let endpoint = `/api/v1/market/histories?symbol=${symbol}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Klines
GET /api/v1/market/candles?symbol=<symbol>
params = {
symbol: string
startAt: long (unix time)
endAt: long (unix time)
type: enum [1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 8hour, 12hour 1day, 1week]
}
*/
Market.getKlines = async function(params) {
let endpoint = '/api/v1/market/candles'
params.startAt = params.startAt.toString().slice(0, 10)
params.endAt = params.endAt.toString().slice(0, 10)
let url = this.baseURL + endpoint + this.formatQuery(params)
let result = await axios.get(url)
return result.data
}
/*
Get currencies
GET /api/v1/currencies
*/
Market.getCurrencies = async function() {
let endpoint = '/api/v1/currencies'
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get currency detail
GET /api/v1/currencies/{currency}
currency = string
*/
Market.getCurrency = async function(currency) {
let endpoint = `/api/v1/currencies/${currency}`
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
/*
Get Fiat Price
GET /api/v1/prices
params = {
base: string (e.g. 'USD') [optional]
currencies: array
}
*/
Market.getFiatPrice = async function(params) {
let endpoint = '/api/v1/prices'
let url = this.baseURL + endpoint + this.formatQuery(params)
let result = await axios.get(url)
return result.data
}
/*
Server Time
GET /api/v1/timestamp
*/
Market.getServerTime = async function() {
let endpoint = '/api/v1/timestamp'
let url = this.baseURL + endpoint
let result = await axios.get(url)
return result.data
}
module.exports = Market