-
Notifications
You must be signed in to change notification settings - Fork 9
/
bitfinex-api.ts
101 lines (81 loc) · 3.28 KB
/
bitfinex-api.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
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
import { Observable } from 'rxjs';
import { ExchangeApi } from '../exchange-api.abstract';
import { ExchangeInfo, SupportFeatures, Ticker, Orderbook, Trade, CandleStick, ExchangeOptions } from '../exchange-types';
import { BitfinexWebsocket } from './websocket';
import { BitfinexTicker } from './ticker';
import { BitfinexOrderbook } from './orderbook';
import { BitfinexCandleStick } from './candlestick';
import { BitfinexTrade } from './trade';
export class BitfinexApi extends ExchangeApi {
private readonly bitfinexWebsocket: BitfinexWebsocket;
private readonly bitfinexTicker: BitfinexTicker;
private readonly bitfinexOrderbook: BitfinexOrderbook;
private readonly bitfinexCandleStick: BitfinexCandleStick;
private readonly bitfinexTrade: BitfinexTrade;
get exchangeInfo(): ExchangeInfo {
return {
name: 'bitfinex',
logoUrl: 'https://files.readme.io/65ad6c8-small-logo.png',
homepage: 'https://www.bitfinex.com/',
country: 'British Virgin Islands',
};
}
get markets(): string[] {
return ['btc_usd', 'eos_btc', 'eth_btc', 'ltc_btc', 'bcc_btc'];
}
get representativeMarkets(): string[] {
return ['btc_usd', 'eos_btc', 'eth_btc'];
}
get supportFeatures(): SupportFeatures {
return {
ticker: true,
orderbook: true,
chart: true,
};
}
constructor(options?: ExchangeOptions) {
super(options);
const corsProxy = this.options.corsProxy;
this.bitfinexWebsocket = new BitfinexWebsocket();
this.bitfinexTicker = new BitfinexTicker(corsProxy, this.bitfinexWebsocket);
this.bitfinexOrderbook = new BitfinexOrderbook(corsProxy, this.bitfinexWebsocket);
this.bitfinexCandleStick = new BitfinexCandleStick(corsProxy, this.bitfinexWebsocket);
this.bitfinexTrade = new BitfinexTrade(corsProxy, this.bitfinexWebsocket);
}
async fetchTicker(pair: string): Promise<Ticker> {
return this.bitfinexTicker.fetchTicker(pair);
}
ticker$(pair: string): Observable<Ticker> {
return this.bitfinexTicker.ticker$(pair);
}
async stopTicker(pair: string): Promise<void> {
await this.bitfinexTicker.stopTicker(pair);
}
async fetchOrderbook(pair: string): Promise<Orderbook> {
return this.bitfinexOrderbook.fetchOrderbook(pair);
}
orderbook$(pair: string): Observable<Orderbook> {
return this.bitfinexOrderbook.orderbook$(pair);
}
async stopOrderbook(pair: string): Promise<void> {
await this.bitfinexOrderbook.stopOrderbook(pair);
}
async fetchTrades(pair: string): Promise<Trade[]> {
return this.bitfinexTrade.fetchTrades(pair);
}
trade$(pair: string): Observable<Trade> {
return this.bitfinexTrade.trade$(pair);
}
async stopTrade(pair: string): Promise<void> {
await this.bitfinexTrade.stopTrade(pair);
}
async fetchCandleStickRange(pair: string, minutesFoot: number, start: number, end: number): Promise<CandleStick[]> {
return this.bitfinexCandleStick.fetchCandleStickRange(pair, minutesFoot, start, end);
}
candlestick$(pair: string, minutesFoot: number): Observable<CandleStick> {
return this.bitfinexCandleStick.candlestick$(pair, minutesFoot);
}
candlestickWithInitialHistory$(pair: string, minutesFoot: number): Observable<CandleStick[] | CandleStick> {
return this.bitfinexCandleStick.candlestickWithInitialHistory$(pair, minutesFoot);
}
}