-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release(v0.0.2-1): now NCB HK supported now
- Loading branch information
Showing
7 changed files
with
149 additions
and
63 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "fxrate", | ||
"version": "0.0.2", | ||
"version": "0.0.2-1", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"author": "Bo Xu <[email protected]> (https://186526.xyz/)", | ||
"dependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import axios from 'axios'; | ||
|
||
import { FXRate, currency } from 'src/types'; | ||
|
||
const currencyMapping = { | ||
'156': 'CNY' as currency.CNY, | ||
A04: 'CNH' as currency.CNH, | ||
'840': 'USD' as currency.USD, | ||
'826': 'GBP' as currency.GBP, | ||
'392': 'JPY' as currency.JPY, | ||
'036': 'AUD' as currency.AUD, | ||
'554': 'NZD' as currency.NZD, | ||
'124': 'CAD' as currency.CAD, | ||
'978': 'EUR' as currency.EUR, | ||
'756': 'CHF' as currency.CHF, | ||
'208': 'DKK' as currency.DKK, | ||
'578': 'NOK' as currency.NOK, | ||
'752': 'SEK' as currency.SEK, | ||
'702': 'SGD' as currency.SGD, | ||
'764': 'THB' as currency.THB, | ||
}; | ||
|
||
const getNCBHKFXRates = async (): Promise<FXRate[]> => { | ||
const res = await axios.post( | ||
'https://www.ncb.com.hk/api/precious/findConversionRateAll', | ||
{ | ||
headers: { | ||
language: 'en', | ||
'User-Agent': | ||
process.env['HEADER_USER_AGENT'] ?? 'fxrate axios/latest', | ||
}, | ||
body: { | ||
language: 3, | ||
custType: 1, | ||
}, | ||
}, | ||
); | ||
|
||
return res.data.data.resultList | ||
.map((fx) => { | ||
const currencyName = currencyMapping[fx.currency]; | ||
|
||
const buy = fx.outNum < fx.inNum ? fx.outNum : fx.inNum; | ||
const sell = fx.outNum < fx.inNum ? fx.inNum : fx.outNum; | ||
|
||
return { | ||
currency: { | ||
to: currencyName as unknown as currency.unknown, | ||
from: 'HKD' as currency.HKD, | ||
}, | ||
rate: { | ||
buy: { | ||
remit: buy, | ||
cash: buy, | ||
}, | ||
sell: { | ||
remit: sell, | ||
cash: sell, | ||
}, | ||
}, | ||
unit: 100, | ||
updated: new Date(fx.createTime + ' UTC+8'), | ||
}; | ||
}) | ||
.sort(); | ||
}; | ||
|
||
export default getNCBHKFXRates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters