@@ -15,7 +15,28 @@ gem 'metalpriceapi'
1515
1616api_key = ' SET_YOUR_API_KEY_HERE'
1717client = MetalpriceAPI ::Client .new (api_key: api_key)
18+
19+ # Or use EU server:
20+ # client = MetalpriceAPI::Client.new(api_key: api_key, server: 'eu')
1821```
22+ ---
23+ ## Server Regions
24+
25+ MetalpriceAPI provides two regional endpoints. Choose the one closest to your servers for optimal performance.
26+
27+ | Region | Base URL |
28+ | --------| ----------|
29+ | United States (default) | ` https://api.metalpriceapi.com/v1 ` |
30+ | Europe | ` https://api-eu.metalpriceapi.com/v1 ` |
31+
32+ ``` ruby
33+ # Default (US)
34+ client = MetalpriceAPI ::Client .new (api_key: ' SET_YOUR_API_KEY_HERE' )
35+
36+ # Europe
37+ client = MetalpriceAPI ::Client .new (api_key: ' SET_YOUR_API_KEY_HERE' , server: ' eu' )
38+ ```
39+
1940---
2041## Documentation
2142
@@ -27,32 +48,62 @@ client.fetchSymbols()
2748[ Link] ( https://metalpriceapi.com/documentation#api_symbol )
2849
2950---
30- #### fetchLive(base, currencies)
51+ #### setServer(server)
52+
53+ - ` server ` <[ string] > Pass ` 'eu' ` to use the EU server (` api-eu.metalpriceapi.com ` ), or ` 'us' ` for the US server. Defaults to US if not specified.
54+
55+ ``` ruby
56+ client.setServer(' eu' )
57+ ```
58+
59+ ---
60+ #### fetchLive(base, currencies, unit, purity, math)
3161
3262- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
3363- ` currencies ` <[ Array] <[ string] >> Optional. Pass in an array of currencies to return values for.
64+ - ` unit ` <[ string] > Optional. Pass in a unit for metal prices (e.g. ` troy_oz ` , ` gram ` , ` kilogram ` ).
65+ - ` purity ` <[ string] > Optional. Pass in a purity level for metal prices.
66+ - ` math ` <[ string] > Optional. Pass in a math expression to apply to the rates.
3467
3568``` ruby
36- client.fetchLive(base = ' USD' , currencies = [' XAU' , ' XAG' , ' XPD' , ' XPT' ])
69+ client.fetchLive(' USD' , [' XAU' , ' XAG' , ' XPD' , ' XPT' ], ' troy_oz ' )
3770```
3871
3972[ Link] ( https://metalpriceapi.com/documentation#api_realtime )
4073
4174---
42- #### fetchHistorical(date, base, currencies)
75+ #### fetchHistorical(date, base, currencies, unit )
4376
4477- ` date ` <[ string] > Required. Pass in a string with format ` YYYY-MM-DD `
4578- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
4679- ` currencies ` <[ Array] <[ string] >> Optional. Pass in an array of currencies to return values for.
80+ - ` unit ` <[ string] > Optional. Pass in a unit for metal prices (e.g. ` troy_oz ` , ` gram ` , ` kilogram ` ).
4781
4882``` ruby
49- client.fetchHistorical(date = ' 2021-04 -05' , base = ' USD' , currencies = [' XAU' , ' XAG' , ' XPD' , ' XPT' ])
83+ client.fetchHistorical(' 2024-02 -05' , ' USD' , [' XAU' , ' XAG' , ' XPD' , ' XPT' ], ' troy_oz ' )
5084```
5185
5286[ Link] ( https://metalpriceapi.com/documentation#api_historical )
5387
5488---
55- #### fetchOHLC(base, currency, date, unit, dateType)
89+ #### hourly(base, currency, unit, start_date, end_date, math, date_type)
90+
91+ - ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
92+ - ` currency ` <[ string] > Required. Specify currency you would like to get hourly rates for.
93+ - ` unit ` <[ string] > Optional. Pass in a unit for metal prices (e.g. ` troy_oz ` , ` gram ` , ` kilogram ` ).
94+ - ` start_date ` <[ string] > Required. Specify the start date using the format ` YYYY-MM-DD ` .
95+ - ` end_date ` <[ string] > Required. Specify the end date using the format ` YYYY-MM-DD ` .
96+ - ` math ` <[ string] > Optional. Pass in a math expression to apply to the rates.
97+ - ` date_type ` <[ string] > Optional. Pass in a date type, overrides date parameters if passed in.
98+
99+ ``` ruby
100+ client.hourly(' USD' , ' XAU' , ' troy_oz' , ' 2025-11-03' , ' 2025-11-03' )
101+ ```
102+
103+ [ Link] ( https://metalpriceapi.com/documentation#api_hourly )
104+
105+ ---
106+ #### fetchOHLC(base, currency, date, unit, date_type)
56107
57108- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
58109- ` currency ` <[ string] > Required. Specify currency you would like to get OHLC for.
@@ -61,60 +112,65 @@ client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG',
61112- ` date_type ` <[ string] > Optional. Pass in a date type, overrides date parameter if passed in.
62113
63114``` ruby
64- client.fetchOHLC(base = ' USD' , currency = ' XAU' , date = ' 2024-02-05 ' , unit = ' troy_oz' , date_type = nil )
115+ client.fetchOHLC(' USD' , ' XAU' , ' 2024-02-06 ' , ' troy_oz' )
65116```
66117
67118[ Link] ( https://metalpriceapi.com/documentation#api_ohlc )
68119
69120---
70- #### convert(from_currency, to_currency, amount, date)
121+ #### convert(from_currency, to_currency, amount, date, unit )
71122
72123- ` from_currency ` <[ string] > Optional. Pass in a base currency, defaults to USD.
73124- ` to_currency ` <[ string] > Required. Specify currency you would like to convert to.
74125- ` amount ` <[ number] > Required. The amount to convert.
75126- ` date ` <[ string] > Optional. Specify date to use historical midpoint value for conversion with format ` YYYY-MM-DD ` . Otherwise, it will use live exchange rate date if value not passed in.
127+ - ` unit ` <[ string] > Optional. Pass in a unit for metal prices (e.g. ` troy_oz ` , ` gram ` , ` kilogram ` ).
76128
77129``` ruby
78- client.convert(from_currency = ' USD' , to_currency = ' EUR' , amount = 100 , date = ' 2021-04 -05' )
130+ client.convert(' USD' , ' EUR' , 100 , ' 2024-02 -05' )
79131```
80132
81133[ Link] ( https://metalpriceapi.com/documentation#api_convert )
82134
83135---
84- #### timeframe(start_date, end_date, base, currencies)
136+ #### timeframe(start_date, end_date, base, currencies, unit )
85137
86138- ` start_date ` <[ string] > Required. Specify the start date of your timeframe using the format ` YYYY-MM-DD ` .
87139- ` end_date ` <[ string] > Required. Specify the end date of your timeframe using the format ` YYYY-MM-DD ` .
88140- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
89141- ` currencies ` <[ Array] <[ string] >> Optional. Pass in an array of currencies to return values for.
142+ - ` unit ` <[ string] > Optional. Pass in a unit for metal prices (e.g. ` troy_oz ` , ` gram ` , ` kilogram ` ).
90143
91144``` ruby
92- client.timeframe(start_date = ' 2021-04 -05' , end_date = ' 2021-04 -06' , base = ' USD' , currencies = [' XAU' , ' XAG' , ' XPD' , ' XPT' ])
145+ client.timeframe(' 2024-02 -05' , ' 2024-02 -06' , ' USD' , [' XAU' , ' XAG' , ' XPD' , ' XPT' ], ' troy_oz ' )
93146```
94147
95148[ Link] ( https://metalpriceapi.com/documentation#api_timeframe )
96149
97150---
98- #### change(start_date, end_date, base, currencies)
151+ #### change(start_date, end_date, base, currencies, date_type )
99152
100153- ` start_date ` <[ string] > Required. Specify the start date of your timeframe using the format ` YYYY-MM-DD ` .
101154- ` end_date ` <[ string] > Required. Specify the end date of your timeframe using the format ` YYYY-MM-DD ` .
102155- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
103156- ` currencies ` <[ Array] <[ string] >> Optional. Pass in an array of currencies to return values for.
157+ - ` date_type ` <[ string] > Optional. Pass in a date type, overrides date parameters if passed in.
104158
105159``` ruby
106- client.change(start_date = ' 2021-04 -05' , end_date = ' 2021-04 -06' , base = ' USD' , currencies = [' XAU' , ' XAG' , ' XPD' , ' XPT' ])
160+ client.change(' 2024-02 -05' , ' 2024-02 -06' , ' USD' , [' XAU' , ' XAG' , ' XPD' , ' XPT' ])
107161```
108162
109163[ Link] ( https://metalpriceapi.com/documentation#api_change )
164+
110165---
111- #### carat(start_date, end_date, base, currencies )
166+ #### carat(base, currency, date )
112167
113168- ` base ` <[ string] > Optional. Pass in a base currency, defaults to USD.
169+ - ` currency ` <[ string] > Optional. Pass in a metal code to get carat prices for (defaults to XAU).
114170- ` date ` <[ string] > Optional. Specify date to get Carat for specific date using format ` YYYY-MM-DD ` . If not specified, uses live rates.
115171
116172``` ruby
117- client.carat(base = ' USD' , date = ' 2021-04 -06' )
173+ client.carat(' USD' , ' XAU ' , ' 2024-02 -06' )
118174```
119175
120176[ Link] ( https://metalpriceapi.com/documentation#api_carat )
@@ -128,6 +184,9 @@ client.usage()
128184
129185[ Link] ( https://metalpriceapi.com/documentation#api_usage )
130186
187+ ---
188+ ** [ Official documentation] ( https://metalpriceapi.com/documentation ) **
189+
131190---
132191## FAQ
133192
0 commit comments