/* bot.js
C:\> cd mynode
C:\mynode> npm install --save request
C:\mynode> dir node_modules
C:\mynode> node bot.js
*/
var request = require("request");
var options = { method: 'GET',
url: 'https://apigw1.bot.or.th/bot/public/Stat-SpotRate/v2/SPOTRATE/',
qs: { start_period: '2021-06-01',end_period: '2021-06-12' },
headers: { accept: 'application/json', 'x-ibm-client-id': 'xxx ... xxx' } };
request(options, function (error, response, body) {
if (error) return console.error('Failed: %s', error.message);
console.log('Success: ', body);
});
/*
C:\mynode> node bot.js
Success: {"result":{"timestamp":"2021-08-12 17:32:39","api":"Spot Rate USD/THB"
,"data":{"data_header":{"report_name_eng":"Spot Rate and Swap Point","report_nam
e_th":"Spot Rate and Swap Point","report_uoq_name_eng":"","report_uoq_name_th":"
","report_source_of_data":[{"source_of_data_eng":"Thomson Reuters (Refinitiv)","
source_of_data_th":"Thomson Reuters (Refinitiv)"},{"source_of_data_eng":"Bank of
Thailand","source_of_data_th":"ธนาคารแห่งประเทศไทย"}],"report_remark":[{"report
_remark_eng":"Forward exchange rate can be derived from the addition of spot rat
e and swap point.","report_remark_th":"อัตราแลกเปลี่ยนล่วงหน้าคำนวณได้จากอัตราแล
กเปลี่ยนทันที และ SWAP POINT"},{"report_remark_eng":"This table has been discont
inued due to redundancy with other tables on the BOT website or original source
s.","report_remark_th":"ตารางนี้ถูกยกเลิกการเผยแพร่ เนื่องจากข้อมูลมีการเผยแพร่ใ
นตารางอื่นของ ธปท. หรือหน่วยงานอื่นที่เป็นเจ้าของข้อมูลอยู่แล้ว"},{"report_remar
k_eng":"1 Satang = 0.01 Baht.","report_remark_th":"1 สตางค์ = 0.01 บาท "}],"la
st_updated":"2021-08-03"},"data_detail":[{"period":"2021-06-11","bid_rate":"31.0
700000","offer_rate":"31.0800000"},{"period":"2021-06-10","bid_rate":"31.1700000
","offer_rate":"31.1800000"},{"period":"2021-06-09","bid_rate":"31.1600000","off
er_rate":"31.1650000"},{"period":"2021-06-08","bid_rate":"31.2000000","offer_rat
e":"31.2100000"},{"period":"2021-06-07","bid_rate":"31.1900000","offer_rate":"31
.2000000"},{"period":"2021-06-04","bid_rate":"31.2700000","offer_rate":"31.28000
00"},{"period":"2021-06-02","bid_rate":"31.1500000","offer_rate":"31.1600000"},{
"period":"2021-06-01","bid_rate":"31.1400000","offer_rate":"31.1500000"}]}}}
เปิดด้วย http://jsonviewer.stack.hu/ แสดงผ่าน Tree viewer สวย ๆ
*/