File tree Expand file tree Collapse file tree 3 files changed +67
-67
lines changed
packages/sources/finnhub/src Expand file tree Collapse file tree 3 files changed +67
-67
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @chainlink/finnhub-adapter ' : patch
3+ ---
4+
5+ Optimize resources
Original file line number Diff line number Diff line change 11import { AdapterConfig } from '@chainlink/external-adapter-framework/config'
22
3- export const config = new AdapterConfig (
4- {
5- API_ENDPOINT : {
6- description : 'The HTTP URL to retrieve data from' ,
7- type : 'string' ,
8- default : 'https://finnhub.io/api/v1' ,
9- } ,
10- API_KEY : {
11- description : 'A Finnhub API key ' ,
12- type : 'string' ,
13- required : true ,
14- sensitive : true ,
15- } ,
16- WS_API_ENDPOINT : {
17- description : 'The WS URL to retrieve data from' ,
18- type : 'string' ,
19- default : 'wss://ws.finnhub.io' ,
20- } ,
21- WS_ENABLED : {
22- description : 'Whether data should be returned from websocket or not' ,
23- type : 'boolean' ,
24- default : false ,
25- } ,
3+ export const config = new AdapterConfig ( {
4+ API_ENDPOINT : {
5+ description : 'The HTTP URL to retrieve data from' ,
6+ type : 'string' ,
7+ default : 'https://finnhub.io/api/v1' ,
268 } ,
27- {
28- envDefaultOverrides : {
29- CACHE_MAX_ITEMS : 20000 , // stock-quotes return all data in a single call
30- } ,
9+ API_KEY : {
10+ description : 'A Finnhub API key ' ,
11+ type : 'string' ,
12+ required : true ,
13+ sensitive : true ,
3114 } ,
32- )
15+ WS_API_ENDPOINT : {
16+ description : 'The WS URL to retrieve data from' ,
17+ type : 'string' ,
18+ default : 'wss://ws.finnhub.io' ,
19+ } ,
20+ WS_ENABLED : {
21+ description : 'Whether data should be returned from websocket or not' ,
22+ type : 'boolean' ,
23+ default : false ,
24+ } ,
25+ } )
3326
3427// Details that differ depending on which exchange data is being fetched
3528// Finnhub separates the Pair symbols by a different character depending on exchange. E.g. "FHFX:EUR-USD" or "OANDA:EUR_USD"
Original file line number Diff line number Diff line change @@ -46,49 +46,51 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
4646 } )
4747 }
4848
49- return res . data . map ( ( data ) => {
50- if (
51- data . a < 0 ||
52- data . av < 0 ||
53- data . b < 0 ||
54- data . bv < 0 ||
55- data . t == 0 ||
56- ( data . av == 0 && data . bv == 0 )
57- ) {
49+ return res . data
50+ . filter ( ( d ) => params . some ( ( p ) => p . base === d . s ) )
51+ . map ( ( data ) => {
52+ if (
53+ data . a < 0 ||
54+ data . av < 0 ||
55+ data . b < 0 ||
56+ data . bv < 0 ||
57+ data . t == 0 ||
58+ ( data . av == 0 && data . bv == 0 )
59+ ) {
60+ return {
61+ params : { base : data . s } ,
62+ response : {
63+ statusCode : 502 ,
64+ errorMessage : `In-valid data ${ JSON . stringify ( data ) } received for ${ data . s } ` ,
65+ } ,
66+ }
67+ }
68+
69+ let midPrice : number
70+ if ( data . b == 0 ) {
71+ midPrice = data . a
72+ } else if ( data . a == 0 ) {
73+ midPrice = data . b
74+ } else {
75+ midPrice = ( data . b * data . bv + data . a * data . av ) / ( data . bv + data . av )
76+ }
77+
5878 return {
5979 params : { base : data . s } ,
6080 response : {
61- statusCode : 502 ,
62- errorMessage : `In-valid data ${ JSON . stringify ( data ) } received for ${ data . s } ` ,
81+ result : null ,
82+ data : {
83+ mid_price : midPrice ,
84+ bid_price : data . b ,
85+ bid_volume : data . bv ,
86+ ask_price : data . a ,
87+ ask_volume : data . av ,
88+ } ,
89+ timestamps : {
90+ providerIndicatedTimeUnixMs : data . t ,
91+ } ,
6392 } ,
6493 }
65- }
66-
67- let midPrice : number
68- if ( data . b == 0 ) {
69- midPrice = data . a
70- } else if ( data . a == 0 ) {
71- midPrice = data . b
72- } else {
73- midPrice = ( data . b * data . bv + data . a * data . av ) / ( data . bv + data . av )
74- }
75-
76- return {
77- params : { base : data . s } ,
78- response : {
79- result : null ,
80- data : {
81- mid_price : midPrice ,
82- bid_price : data . b ,
83- bid_volume : data . bv ,
84- ask_price : data . a ,
85- ask_volume : data . av ,
86- } ,
87- timestamps : {
88- providerIndicatedTimeUnixMs : data . t ,
89- } ,
90- } ,
91- }
92- } )
94+ } )
9395 } ,
9496} )
You can’t perform that action at this time.
0 commit comments