@@ -6,34 +6,34 @@ import {environment} from '../environments/environment';
6
6
import { HttpClient , HttpHeaders } from '@angular/common/http' ;
7
7
import { TradeInfo } from './tradeInfo' ;
8
8
9
-
10
- // const binHttpOptions = {
11
- // headers: new HttpHeaders({
12
- // 'Content-Type': 'application/json',
13
- // 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token',
14
- // 'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
15
- // 'Access-Control-Allow-Origin': '*'
16
- // })
17
- // };
18
-
9
+ export class BinancePriceResult {
10
+ symbol : string ;
11
+ bestAsk : string ;
12
+ bestBid : string ;
13
+ }
19
14
20
15
@Injectable ( {
21
16
providedIn : 'root'
22
17
} )
23
18
export class BinanceService {
24
19
25
20
symbols : Subject < string > ;
26
- /*constructor(private wss: WebsocketService, private http: HttpClient) {
27
- }*/
28
21
29
- // getOrderBookTickers(): Observable<any> {
30
- // return this.http.get<any>(`${environment.BINANCE_API_URL}/api/v3/ticker/bookTicker`, binHttpOptions).pipe(
31
- // retry(3),
32
- // tap(orderbook => console.log(`fetched Binance getOrderBookTickers`)),
33
- // catchError(this.handleError('getOrderBookTickers', [])),
34
- // map(orderbook => JSON.parse(orderbook))
35
- // );
36
- // }
22
+ getPrice ( symbol : string ) : Subject < BinancePriceResult > {
23
+ const listener = this . listenSymbols ( [ symbol ] ) ;
24
+
25
+ return < Subject < BinancePriceResult > > listener . pipe (
26
+ map ( data => JSON . parse ( data ) . data ) ,
27
+ map ( function ( data ) {
28
+ setTimeout ( ( ) => this . complete ( ) ) ;
29
+ return Object . assign ( new BinancePriceResult ( ) , {
30
+ symbol : data . s ,
31
+ bestAsk : data . a ,
32
+ bestBid : data . b ,
33
+ } ) ;
34
+ } )
35
+ ) ;
36
+ }
37
37
38
38
listenSymbols ( symbols : string [ ] ) : Subject < string > {
39
39
if ( this . symbols != null && this . symbols !== undefined ) {
0 commit comments