-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathokcoin.ts
75 lines (68 loc) · 2.46 KB
/
okcoin.ts
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
import { BaseExchangeAdapter, ExchangeDataType, Ticker } from './base'
import { Exchange } from '../utils'
export class OKCoinAdapter extends BaseExchangeAdapter {
baseApiUrl = 'https://www.okcoin.com/api'
readonly _exchangeName = Exchange.OKCOIN
// There are no known deviations from the standard mapping
private static readonly tokenSymbolMap = OKCoinAdapter.standardTokenSymbolMap
async fetchTicker(): Promise<Ticker> {
const json = await this.fetchFromApi(
ExchangeDataType.TICKER,
`spot/v3/instruments/${this.pairSymbol}/ticker`
)
return this.parseTicker(json)
}
/**
* Parses the json response from the ticker endpoint and returns a Ticker object
*
* @param json response from /spot/v3/instruments/${this.pairSymbol}/ticker
*
* Example response from OKCoin docs: https://www.okcoin.com/docs/en/#spot-some
* {
* "best_ask": "7222.2",
* "best_bid": "7222.1",
* "instrument_id": "BTC-USDT",
* "product_id": "BTC-USDT",
* "last": "7222.2",
* "last_qty": "0.00136237",
* "ask": "7222.2",
* "best_ask_size": "0.09207739",
* "bid": "7222.1",
* "best_bid_size": "3.61314948",
* "open_24h": "7356.8",
* "high_24h": "7367.7",
* "low_24h": "7160",
* "base_volume_24h": "18577.2",
* "timestamp": "2019-12-11T07:48:04.014Z",
* "quote_volume_24h": "134899542.8"
* }
*/
parseTicker(json: any): Ticker {
const ticker = {
...this.priceObjectMetadata,
ask: this.safeBigNumberParse(json.ask)!,
baseVolume: this.safeBigNumberParse(json.base_volume_24h)!,
bid: this.safeBigNumberParse(json.bid)!,
high: this.safeBigNumberParse(json.high_24h),
lastPrice: this.safeBigNumberParse(json.last)!,
low: this.safeBigNumberParse(json.low_24h),
open: this.safeBigNumberParse(json.open_24h),
quoteVolume: this.safeBigNumberParse(json.quote_volume_24h)!,
timestamp: this.safeDateParse(json.timestamp)!,
}
this.verifyTicker(ticker)
return ticker
}
protected generatePairSymbol(): string {
return `${OKCoinAdapter.tokenSymbolMap.get(
this.config.baseCurrency
)}-${OKCoinAdapter.tokenSymbolMap.get(this.config.quoteCurrency)}`
}
/**
* OKCoin doesn't have an endpoint to check this. So, return true, and assume
* that if the API can be reached, the orderbook is live.
*/
async isOrderbookLive(): Promise<boolean> {
return true
}
}