bank_of_thailand 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +293 -0
- data/Rakefile +12 -0
- data/docs/openapi_spec/average-exchange-rate-thb--foreign-currency-2_0_2.json +778 -0
- data/docs/openapi_spec/botlicensecheckapi-1_0_2.json +122 -0
- data/docs/openapi_spec/debt-securities-auction-result-current-2_0_0.json +201 -0
- data/docs/openapi_spec/debt-securities-auction-result-current_2.0.0.json +201 -0
- data/docs/openapi_spec/deposit-interest-rates-for-individuals-of-commercial-banks-percent-per-annum-2_0_0.json +354 -0
- data/docs/openapi_spec/financial-institutions-holidays-1_0_1.json +98 -0
- data/docs/openapi_spec/interbank-transaction-rates-percent-per-annum-2_0_0.json +224 -0
- data/docs/openapi_spec/loan-interest-rates-of-commercial-banks-percent-per-annum-2_0_0.json +335 -0
- data/docs/openapi_spec/search-series_1.0.0.json +177 -0
- data/docs/openapi_spec/swap-point-onshore-in-satangs-2_0_0.json +196 -0
- data/docs/openapi_spec/thai-baht-implied-interest-rates-percent-per-annum-2_0_0.json +182 -0
- data/docs/openapi_spec/weighted-average-interbank-exchange-rate-thb--usd-2_0_1.json +546 -0
- data/lib/bank_of_thailand/client.rb +188 -0
- data/lib/bank_of_thailand/configuration.rb +88 -0
- data/lib/bank_of_thailand/errors.rb +46 -0
- data/lib/bank_of_thailand/resource.rb +34 -0
- data/lib/bank_of_thailand/resources/average_exchange_rate.rb +81 -0
- data/lib/bank_of_thailand/resources/deposit_rate.rb +46 -0
- data/lib/bank_of_thailand/resources/exchange_rate.rb +103 -0
- data/lib/bank_of_thailand/resources/financial_holidays.rb +30 -0
- data/lib/bank_of_thailand/resources/implied_rate.rb +39 -0
- data/lib/bank_of_thailand/resources/interbank_rate.rb +39 -0
- data/lib/bank_of_thailand/resources/interest_rate.rb +49 -0
- data/lib/bank_of_thailand/resources/loan_rate.rb +45 -0
- data/lib/bank_of_thailand/resources/search_series.rb +37 -0
- data/lib/bank_of_thailand/resources/statistics.rb +80 -0
- data/lib/bank_of_thailand/resources/swap_point.rb +38 -0
- data/lib/bank_of_thailand/version.rb +5 -0
- data/lib/bank_of_thailand.rb +56 -0
- data/sig/bank_of_thailand.rbs +4 -0
- metadata +211 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0c8ed6b63a147c446647a9a14d22496586de29fcb34841bb87eb1486a7307118
|
|
4
|
+
data.tar.gz: a5929c13399366bf2715621922c73c6565c8a98b2f6d5d172ce8520e3006c0d6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2f18242c5e071d0e42f3123bf1a796427a693603bb8c6297c9ae98ef01585515ffe5cf9e6fbf332c3454e3a3ad28c678f3347ae09b58dd7d62407b137f932ac8
|
|
7
|
+
data.tar.gz: e237535be4e3f98f0953ac74b06e8bdde61f91e7ee8a70fd7665f5faeb46fa7ede942d552d3a2d4dc2e64ad85e7e99b9f4f09b99f6f9a2789ba971430caef405
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2025-11-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release with 11 API resources
|
|
7
|
+
- Exchange rate APIs (weighted-average interbank THB/USD and average exchange rates for 19 currencies)
|
|
8
|
+
- Interest rate APIs (deposit rates, loan rates, interbank rates, Thai Baht implied rates)
|
|
9
|
+
- Securities & markets APIs (debt securities auction results, swap point onshore)
|
|
10
|
+
- Regulatory APIs (BOT license check, financial institutions holidays)
|
|
11
|
+
- Search API (series search)
|
|
12
|
+
- Comprehensive test coverage (66 examples, 100% pass rate)
|
|
13
|
+
- RuboCop configuration for code quality
|
|
14
|
+
- YARD documentation support
|
|
15
|
+
- Ruby 3.0+ support with CI testing across 3.0, 3.1, 3.2, 3.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chayut Orapinpatipat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Bank of Thailand API Wrapper
|
|
2
|
+
|
|
3
|
+
A Ruby gem for accessing the Bank of Thailand's public API services. This gem provides a clean, object-oriented interface to interact with BOT's official API catalog.
|
|
4
|
+
|
|
5
|
+
[](https://www.ruby-lang.org/)
|
|
6
|
+
[](LICENSE.txt)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Token-based Authentication** - Secure API access using BOT's authorization system
|
|
11
|
+
- **11 API Resources** - Complete coverage of all documented BOT API products
|
|
12
|
+
- **Type Safety** - Comprehensive error handling with custom exception classes
|
|
13
|
+
- **Flexible Configuration** - Global or instance-level configuration options
|
|
14
|
+
- **Full Test Coverage** - 66 examples with 100% pass rate
|
|
15
|
+
- **YARD Documentation** - Complete API documentation for all endpoints
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem "bank_of_thailand"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And then execute:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
bundle install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or install it yourself as:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
gem install bank_of_thailand
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Prerequisites
|
|
38
|
+
|
|
39
|
+
Before using this gem, you need to obtain an API token from the Bank of Thailand API Portal:
|
|
40
|
+
|
|
41
|
+
1. **Create an Account** at [https://portal.api.bot.or.th](https://portal.api.bot.or.th)
|
|
42
|
+
2. **Create an Application** in your profile (Profile → My apps)
|
|
43
|
+
3. **Subscribe to API Products** from the Catalogues menu
|
|
44
|
+
4. **Select a Plan** and add to cart
|
|
45
|
+
5. **Activate Subscription** by selecting your application
|
|
46
|
+
6. **Retrieve Your Token** from Profile → My apps → Select your app → Copy token
|
|
47
|
+
|
|
48
|
+
Note: A token can only access APIs from subscribed products. Make sure to subscribe to the products you need.
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
### Global Configuration
|
|
53
|
+
|
|
54
|
+
Configure the gem globally for use throughout your application:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
require "bank_of_thailand"
|
|
58
|
+
|
|
59
|
+
BankOfThailand.configure do |config|
|
|
60
|
+
config.api_token = ENV["BOT_API_TOKEN"] # Required
|
|
61
|
+
config.timeout = 30 # Optional, default: 30 seconds
|
|
62
|
+
config.max_retries = 3 # Optional, default: 3
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Create a client using global configuration
|
|
66
|
+
client = BankOfThailand::Client.new
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Instance Configuration
|
|
70
|
+
|
|
71
|
+
Configure individual client instances:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
client = BankOfThailand::Client.new do |config|
|
|
75
|
+
config.api_token = "your_token_here"
|
|
76
|
+
config.timeout = 60
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Configuration Options
|
|
81
|
+
|
|
82
|
+
| Option | Type | Default | Description |
|
|
83
|
+
|--------|------|---------|-------------|
|
|
84
|
+
| `api_token` | String | `nil` | **Required.** Your BOT API token from the portal |
|
|
85
|
+
| `base_url` | String | `https://gateway.api.bot.or.th` | Base gateway URL (rarely needs changing) |
|
|
86
|
+
| `timeout` | Integer | `30` | Request timeout in seconds |
|
|
87
|
+
| `max_retries` | Integer | `3` | Number of retry attempts for failed requests |
|
|
88
|
+
| `logger` | Logger | `nil` | Optional logger for debugging |
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
|
|
92
|
+
### Available API Resources
|
|
93
|
+
|
|
94
|
+
The gem provides access to 11 BOT API resources:
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
client = BankOfThailand::Client.new
|
|
98
|
+
|
|
99
|
+
# Exchange Rates
|
|
100
|
+
client.exchange_rate # Weighted-average Interbank Exchange Rate (THB/USD)
|
|
101
|
+
client.average_exchange_rate # Average Exchange Rate (THB/Foreign Currencies)
|
|
102
|
+
|
|
103
|
+
# Interest Rates
|
|
104
|
+
client.deposit_rate # Deposit Interest Rates
|
|
105
|
+
client.loan_rate # Loan Interest Rates
|
|
106
|
+
client.interbank_rate # Interbank Transaction Rates
|
|
107
|
+
client.implied_rate # Thai Baht Implied Interest Rates
|
|
108
|
+
|
|
109
|
+
# Securities & Markets
|
|
110
|
+
client.debt_securities # Debt Securities Auction Results
|
|
111
|
+
client.swap_point # Swap Point Onshore
|
|
112
|
+
|
|
113
|
+
# Regulatory & Reference
|
|
114
|
+
client.license_check # BOT License Check
|
|
115
|
+
client.financial_holidays # Financial Institutions' Holidays
|
|
116
|
+
client.search_series # Search Stat APIs
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Exchange Rates
|
|
120
|
+
|
|
121
|
+
#### Weighted-average Interbank Exchange Rate (THB/USD)
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
# Daily rates
|
|
125
|
+
daily_rates = client.exchange_rate.daily(
|
|
126
|
+
start_period: "2025-01-01",
|
|
127
|
+
end_period: "2025-01-31"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# Monthly, quarterly, and annual rates also available
|
|
131
|
+
monthly = client.exchange_rate.monthly(start_period: "2025-01", end_period: "2025-03")
|
|
132
|
+
quarterly = client.exchange_rate.quarterly(start_period: "2025-Q1", end_period: "2025-Q2")
|
|
133
|
+
annual = client.exchange_rate.annual(start_period: "2020", end_period: "2024")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Average Exchange Rate (Multiple Currencies)
|
|
137
|
+
|
|
138
|
+
```ruby
|
|
139
|
+
# Daily average rates with optional currency filter
|
|
140
|
+
rates = client.average_exchange_rate.daily(
|
|
141
|
+
start_period: "2025-01-01",
|
|
142
|
+
end_period: "2025-01-31",
|
|
143
|
+
currency: "USD" # Optional: filter by currency
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# Also supports monthly, quarterly, and annual
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Interest Rates
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
# Deposit rates
|
|
153
|
+
deposit = client.deposit_rate.rates(
|
|
154
|
+
start_period: "2025-01-01",
|
|
155
|
+
end_period: "2025-01-31"
|
|
156
|
+
)
|
|
157
|
+
deposit_avg = client.deposit_rate.average_rates(start_period: "2025-01-01", end_period: "2025-01-31")
|
|
158
|
+
|
|
159
|
+
# Loan rates
|
|
160
|
+
loan = client.loan_rate.rates(start_period: "2025-01-01", end_period: "2025-01-31")
|
|
161
|
+
loan_avg = client.loan_rate.average_rates(start_period: "2025-01-01", end_period: "2025-01-31")
|
|
162
|
+
|
|
163
|
+
# Interbank rates (with optional term_type filter)
|
|
164
|
+
interbank = client.interbank_rate.rates(
|
|
165
|
+
start_period: "2025-01-01",
|
|
166
|
+
end_period: "2025-01-31",
|
|
167
|
+
term_type: "O/N" # Optional
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Implied rates (with optional rate_type filter)
|
|
171
|
+
implied = client.implied_rate.rates(
|
|
172
|
+
start_period: "2025-01-01",
|
|
173
|
+
end_period: "2025-01-31",
|
|
174
|
+
rate_type: "ONSHORE : T/N" # Optional
|
|
175
|
+
)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Securities & Markets
|
|
179
|
+
|
|
180
|
+
```ruby
|
|
181
|
+
# Debt securities auction results
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Securities & Markets
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
# Debt securities auction results
|
|
188
|
+
results = client.debt_securities.auction_results(
|
|
189
|
+
start_period: "2025-01-01",
|
|
190
|
+
end_period: "2025-01-31"
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
# Swap point onshore (with optional term_type filter)
|
|
194
|
+
swap = client.swap_point.rates(
|
|
195
|
+
start_period: "2025-01-01",
|
|
196
|
+
end_period: "2025-01-31",
|
|
197
|
+
term_type: "1 Month" # Optional
|
|
198
|
+
)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Regulatory & Reference Data
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
# Search for authorized entities
|
|
205
|
+
results = client.license_check.search_authorized(
|
|
206
|
+
keyword: "finance",
|
|
207
|
+
page: 1, # Optional
|
|
208
|
+
limit: 10 # Optional
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
# Get license details
|
|
212
|
+
license = client.license_check.license(auth_id: "12345", doc_id: "DOC-001")
|
|
213
|
+
|
|
214
|
+
# Get entity details
|
|
215
|
+
entity = client.license_check.authorized_detail(id: 12345)
|
|
216
|
+
|
|
217
|
+
# Financial holidays
|
|
218
|
+
holidays = client.financial_holidays.list(year: "2025")
|
|
219
|
+
|
|
220
|
+
# Search series
|
|
221
|
+
series = client.search_series.search(keyword: "government debt")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Error Handling
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
begin
|
|
228
|
+
client.exchange_rate.daily
|
|
229
|
+
rescue BankOfThailand::RateLimitError => e
|
|
230
|
+
retry_after = e.retry_after
|
|
231
|
+
rescue BankOfThailand::APIError => e
|
|
232
|
+
puts "API error: #{e.message}"
|
|
233
|
+
end
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Exception Hierarchy
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
BankOfThailand::Error (StandardError)
|
|
240
|
+
├── ConfigurationError
|
|
241
|
+
└── RequestError
|
|
242
|
+
├── AuthenticationError
|
|
243
|
+
│ └── InvalidTokenError
|
|
244
|
+
├── NotFoundError
|
|
245
|
+
├── RateLimitError
|
|
246
|
+
└── ServerError
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Rate Limits
|
|
250
|
+
|
|
251
|
+
Rate limits vary by API product. The gem automatically handles rate limiting errors and provides retry information via `RateLimitError#retry_after`.
|
|
252
|
+
|
|
253
|
+
## Development
|
|
254
|
+
|
|
255
|
+
After checking out the repo, run `bin/setup` to install dependencies. Run `rake spec` to execute tests. Use `bin/console` for an interactive prompt.
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# Run tests
|
|
259
|
+
bundle exec rspec
|
|
260
|
+
|
|
261
|
+
# Run linter
|
|
262
|
+
bundle exec rubocop
|
|
263
|
+
|
|
264
|
+
# Generate documentation
|
|
265
|
+
bundle exec yard doc
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## API Documentation
|
|
269
|
+
|
|
270
|
+
For detailed information about the Bank of Thailand APIs:
|
|
271
|
+
|
|
272
|
+
- **API Portal**: [https://portal.api.bot.or.th](https://portal.api.bot.or.th)
|
|
273
|
+
- **Production Gateway**: [https://gateway.api.bot.or.th](https://gateway.api.bot.or.th)
|
|
274
|
+
- **Official BOT Website**: [https://www.bot.or.th](https://www.bot.or.th)
|
|
275
|
+
|
|
276
|
+
## Contributing
|
|
277
|
+
|
|
278
|
+
Bug reports and pull requests are welcome at [github.com/chayuto/bank_of_thailand](https://github.com/chayuto/bank_of_thailand).
|
|
279
|
+
|
|
280
|
+
1. Fork the repository
|
|
281
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
|
282
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
283
|
+
4. Push to the branch (`git push origin feature/my-new-feature`)
|
|
284
|
+
5. Create a Pull Request
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
|
289
|
+
|
|
290
|
+
## Changelog
|
|
291
|
+
|
|
292
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history and release notes.
|
|
293
|
+
|