@@ -2,6 +2,21 @@ import { XMLParser } from 'fast-xml-parser';
22import { FXRate , currency } from 'src/types' ;
33import axios from 'axios' ;
44
5+ import crypto from 'crypto' ;
6+ import https from 'https' ;
7+
8+ /**
9+ * Handle this problem with Node 18
10+ * write EPROTO B8150000:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled
11+ * **/
12+ const allowLegacyRenegotiationforNodeJsOptions = {
13+ httpsAgent : new https . Agent ( {
14+ // allow sb CCB to use legacy renegotiation
15+ // 💩 CCB
16+ secureOptions : crypto . constants . SSL_OP_LEGACY_SERVER_CONNECT ,
17+ } ) ,
18+ } ;
19+
520const parser = new XMLParser ( ) ;
621
722const currencyMap = {
@@ -25,12 +40,22 @@ const currencyMap = {
2540 '458' : { name : 'MYR' as currency . MYR } ,
2641 '643' : { name : 'RUB' as currency . RUB } ,
2742 '398' : { name : 'KZT' as currency . KZT } ,
43+ '784' : { name : 'AED' as currency . AED } ,
44+ '682' : { name : 'SAR' as currency . SAR } ,
45+ '348' : { name : 'HUF' as currency . HUF } ,
46+ '484' : { name : 'MXN' as currency . MXN } ,
47+ '985' : { name : 'PLN' as currency . PLN } ,
48+ '949' : { name : 'TRY' as currency . TRY } ,
49+ '203' : { name : 'CZK' as currency . CZK } ,
50+ '376' : { name : 'ILS' as currency . ILS } ,
51+ '496' : { name : 'MNT' as currency . MNT } ,
2852} ;
2953
3054const getCCBFXRates = async ( ) : Promise < FXRate [ ] > => {
3155 const req = await axios . get (
32- 'http ://www.ccb.com/cn/home/news/jshckpj_new.xml' ,
56+ 'https ://www.ccb.com/cn/home/news/jshckpj_new.xml' ,
3357 {
58+ ...allowLegacyRenegotiationforNodeJsOptions ,
3459 headers : {
3560 'User-Agent' :
3661 process . env [ 'HEADER_USER_AGENT' ] ?? 'fxrate axios/latest' ,
@@ -40,7 +65,15 @@ const getCCBFXRates = async (): Promise<FXRate[]> => {
4065 const settlements = parser . parse ( req . data ) [ 'ReferencePriceSettlements' ] [
4166 'ReferencePriceSettlement'
4267 ] ;
68+
4369 const result = settlements . map ( ( data : any ) => {
70+ if ( ! ( data [ 'Ofrd_Ccy_CcyCd' ] in currencyMap ) ) {
71+ console . log (
72+ `[${ new Date ( ) . toUTCString ( ) } ] [CCB] Unsupported currency code ${ data [ 'Ofrd_Ccy_CcyCd' ] } , skipped.` ,
73+ ) ;
74+ return null ;
75+ }
76+
4477 return {
4578 currency : {
4679 from : currencyMap [ data [ 'Ofrd_Ccy_CcyCd' ] ] . name ,
0 commit comments