-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbinance-api.ts
More file actions
113 lines (90 loc) · 3.26 KB
/
Copy pathbinance-api.ts
File metadata and controls
113 lines (90 loc) · 3.26 KB
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
import { Observable } from 'rxjs';
import { ExchangeApi } from '../exchange-api.abstract';
import { ExchangeInfo, SupportFeatures, Ticker, Orderbook, Trade, CandleStick, ExchangeOptions } from '../exchange-types';
import { BinanceTicker } from './ticker';
import { BinanceOrderbook } from './orderbook';
import { BinanceTrade } from './trade';
import { BinanceCandleStick } from './candlestick';
import { BinanceWebsocket } from './websocket';
export class BinanceApi extends ExchangeApi {
private readonly binanceWebsocket: BinanceWebsocket;
private readonly binanceTicker: BinanceTicker;
private readonly binanceOrderbook: BinanceOrderbook;
private readonly binanceTrade: BinanceTrade;
private readonly binanceCandleStick: BinanceCandleStick;
get exchangeInfo(): ExchangeInfo {
return {
name: 'binance',
logoUrl: 'https://www.binance.com/resources/img/logo-en.svg',
homepage: 'https://www.binance.com/?ref=16635017',
country: 'cn',
};
}
get markets(): string[] {
return ['btc_usdt', 'eos_btc', 'eth_btc', 'ltc_btc', 'bcc_btc'];
}
get representativeMarkets(): string[] {
return ['btc_usdt', '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.binanceWebsocket = new BinanceWebsocket();
this.binanceTicker = new BinanceTicker(this.binanceWebsocket, corsProxy);
this.binanceOrderbook = new BinanceOrderbook(this.binanceWebsocket, corsProxy);
this.binanceTrade = new BinanceTrade(this.binanceWebsocket, corsProxy);
this.binanceCandleStick = new BinanceCandleStick(this.binanceWebsocket, corsProxy);
}
/**
* Implement common interface
*/
async fetchTicker(pair: string): Promise<Ticker> {
return this.binanceTicker.fetch(pair);
}
ticker$(pair: string): Observable<Ticker> {
return this.binanceTicker.stream$(pair);
}
stopTicker(pair: string): void {
this.binanceTicker.stop(pair);
}
async fetchOrderbook(pair: string): Promise<Orderbook> {
return this.binanceOrderbook.fetch(pair);
}
orderbook$(pair: string): Observable<Orderbook> {
return this.binanceOrderbook.stream$(pair);
}
stopOrderbook(pair: string): void {
this.binanceOrderbook.stop(pair);
}
async fetchTrades(pair: string): Promise<Trade[]> {
return this.binanceTrade.fetch(pair);
}
trade$(pair: string): Observable<Trade> {
return this.binanceTrade.stream$(pair);
}
stopTrade(pair: string): void {
this.binanceTrade.stop(pair);
}
async fetchCandleStickRange(pair: string, minutesFoot: number, start: number, end: number): Promise<CandleStick[]> {
return this.binanceCandleStick.fetchRange(pair, minutesFoot, start, end);
}
/**
* Specific exchange functions
*/
async fetchOrderbookLimit(pair: string, limit: number): Promise<Orderbook> {
return this.binanceOrderbook.fetch(pair, limit);
}
candlestick$(pair: string, minutesFoot: number): Observable<CandleStick> {
return this.binanceCandleStick.stream$(pair, minutesFoot);
}
stopCandleStick(pair: string, minutesFoot: number): void {
this.binanceCandleStick.stop(pair, minutesFoot);
}
}