|
| 1 | +# MetalpriceAPI |
| 2 | + |
| 3 | +MetalpriceAPI is the official .NET wrapper for MetalpriceAPI.com. This allows you to quickly integrate our metal price API and foreign exchange rate API into your application. Check https://metalpriceapi.com documentation for more information. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### NuGet |
| 8 | + |
| 9 | +``` |
| 10 | +dotnet add package MetalpriceAPI |
| 11 | +``` |
| 12 | + |
| 13 | +Or add to your `.csproj`: |
| 14 | + |
| 15 | +```xml |
| 16 | +<PackageReference Include="MetalpriceAPI" Version="1.3.0" /> |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +```csharp |
| 22 | +using MetalpriceAPI; |
| 23 | + |
| 24 | +string apiKey = "SET_YOUR_API_KEY_HERE"; |
| 25 | +using var client = new MetalpriceApiClient(apiKey); |
| 26 | + |
| 27 | +// Or use EU server: |
| 28 | +// using var client = new MetalpriceApiClient(apiKey, "eu"); |
| 29 | +``` |
| 30 | +--- |
| 31 | +## Server Regions |
| 32 | + |
| 33 | +MetalpriceAPI provides two regional endpoints. Choose the one closest to your servers for optimal performance. |
| 34 | + |
| 35 | +| Region | Base URL | |
| 36 | +|--------|----------| |
| 37 | +| United States (default) | `https://api.metalpriceapi.com/v1` | |
| 38 | +| Europe | `https://api-eu.metalpriceapi.com/v1` | |
| 39 | + |
| 40 | +```csharp |
| 41 | +using MetalpriceAPI; |
| 42 | + |
| 43 | +// Default (US) |
| 44 | +using var client = new MetalpriceApiClient("SET_YOUR_API_KEY_HERE"); |
| 45 | + |
| 46 | +// Europe |
| 47 | +using var client = new MetalpriceApiClient("SET_YOUR_API_KEY_HERE", "eu"); |
| 48 | +``` |
| 49 | + |
| 50 | +--- |
| 51 | +## Documentation |
| 52 | + |
| 53 | +#### FetchSymbolsAsync() |
| 54 | +```csharp |
| 55 | +await client.FetchSymbolsAsync(); |
| 56 | +``` |
| 57 | + |
| 58 | +[Link](https://metalpriceapi.com/documentation#api_symbol) |
| 59 | + |
| 60 | +--- |
| 61 | +#### SetServer(server) |
| 62 | + |
| 63 | +- `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. |
| 64 | + |
| 65 | +```csharp |
| 66 | +client.SetServer("eu"); |
| 67 | +``` |
| 68 | + |
| 69 | +--- |
| 70 | +#### FetchLiveAsync(baseVal, currencies, unit, purity, math) |
| 71 | + |
| 72 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 73 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 74 | +- `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`). |
| 75 | +- `purity` <[string]> Optional. Pass in a purity level for metal prices. |
| 76 | +- `math` <[string]> Optional. Pass in a math expression to apply to the rates. |
| 77 | + |
| 78 | +```csharp |
| 79 | +await client.FetchLiveAsync("USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz"); |
| 80 | +``` |
| 81 | + |
| 82 | +[Link](https://metalpriceapi.com/documentation#api_realtime) |
| 83 | + |
| 84 | +--- |
| 85 | +#### FetchHistoricalAsync(date, baseVal, currencies, unit) |
| 86 | + |
| 87 | +- `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD` |
| 88 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 89 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 90 | +- `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`). |
| 91 | + |
| 92 | +```csharp |
| 93 | +await client.FetchHistoricalAsync("2024-02-05", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz"); |
| 94 | +``` |
| 95 | + |
| 96 | +[Link](https://metalpriceapi.com/documentation#api_historical) |
| 97 | + |
| 98 | +--- |
| 99 | +#### HourlyAsync(baseVal, currency, unit, startDate, endDate, math, dateType) |
| 100 | + |
| 101 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 102 | +- `currency` <[string]> Required. Specify currency you would like to get hourly rates for. |
| 103 | +- `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`). |
| 104 | +- `startDate` <[string]> Required. Specify the start date using the format `YYYY-MM-DD`. |
| 105 | +- `endDate` <[string]> Required. Specify the end date using the format `YYYY-MM-DD`. |
| 106 | +- `math` <[string]> Optional. Pass in a math expression to apply to the rates. |
| 107 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameters if passed in. |
| 108 | + |
| 109 | +```csharp |
| 110 | +await client.HourlyAsync("USD", "XAU", "troy_oz", "2025-11-03", "2025-11-03"); |
| 111 | +``` |
| 112 | + |
| 113 | +[Link](https://metalpriceapi.com/documentation#api_hourly) |
| 114 | + |
| 115 | +--- |
| 116 | +#### FetchOHLCAsync(baseVal, currency, date, unit, dateType) |
| 117 | + |
| 118 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 119 | +- `currency` <[string]> Required. Specify currency you would like to get OHLC for. |
| 120 | +- `date` <[string]> Required. Specify date to get OHLC for specific date using format `YYYY-MM-DD`. |
| 121 | +- `unit` <[string]> Optional. Pass in a unit, defaults to troy_oz. |
| 122 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameter if passed in. |
| 123 | + |
| 124 | +```csharp |
| 125 | +await client.FetchOHLCAsync("USD", "XAU", "2024-02-05", "troy_oz"); |
| 126 | +``` |
| 127 | + |
| 128 | +[Link](https://metalpriceapi.com/documentation#api_ohlc) |
| 129 | + |
| 130 | +--- |
| 131 | +#### ConvertAsync(fromCurrency, toCurrency, amount, date, unit) |
| 132 | + |
| 133 | +- `fromCurrency` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 134 | +- `toCurrency` <[string]> Required. Specify currency you would like to convert to. |
| 135 | +- `amount` <[number]> Required. The amount to convert. |
| 136 | +- `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. |
| 137 | +- `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`). |
| 138 | + |
| 139 | +```csharp |
| 140 | +await client.ConvertAsync("USD", "EUR", 100, "2024-02-05"); |
| 141 | +``` |
| 142 | + |
| 143 | +[Link](https://metalpriceapi.com/documentation#api_convert) |
| 144 | + |
| 145 | +--- |
| 146 | +#### TimeframeAsync(startDate, endDate, baseVal, currencies, unit) |
| 147 | + |
| 148 | +- `startDate` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. |
| 149 | +- `endDate` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. |
| 150 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 151 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 152 | +- `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`). |
| 153 | + |
| 154 | +```csharp |
| 155 | +await client.TimeframeAsync("2024-02-05", "2024-02-06", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz"); |
| 156 | +``` |
| 157 | + |
| 158 | +[Link](https://metalpriceapi.com/documentation#api_timeframe) |
| 159 | + |
| 160 | +--- |
| 161 | +#### ChangeAsync(startDate, endDate, baseVal, currencies, dateType) |
| 162 | + |
| 163 | +- `startDate` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. |
| 164 | +- `endDate` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. |
| 165 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 166 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 167 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameters if passed in. |
| 168 | + |
| 169 | +```csharp |
| 170 | +await client.ChangeAsync("2024-02-05", "2024-02-06", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }); |
| 171 | +``` |
| 172 | + |
| 173 | +[Link](https://metalpriceapi.com/documentation#api_change) |
| 174 | + |
| 175 | +--- |
| 176 | +#### CaratAsync(baseVal, currency, date) |
| 177 | + |
| 178 | +- `baseVal` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 179 | +- `currency` <[string]> Optional. Pass in a metal code to get carat prices for (defaults to XAU). |
| 180 | +- `date` <[string]> Optional. Specify date to get Carat for specific date using format `YYYY-MM-DD`. If not specified, uses live rates. |
| 181 | + |
| 182 | +```csharp |
| 183 | +await client.CaratAsync("USD", "XAU", "2024-02-05"); |
| 184 | +``` |
| 185 | + |
| 186 | +[Link](https://metalpriceapi.com/documentation#api_carat) |
| 187 | + |
| 188 | +--- |
| 189 | +#### UsageAsync() |
| 190 | +```csharp |
| 191 | +await client.UsageAsync(); |
| 192 | +``` |
| 193 | + |
| 194 | +[Link](https://metalpriceapi.com/documentation#api_usage) |
| 195 | + |
| 196 | +--- |
| 197 | +**[Official documentation](https://metalpriceapi.com/documentation)** |
| 198 | + |
| 199 | +--- |
| 200 | +## FAQ |
| 201 | + |
| 202 | +- How do I get an API Key? |
| 203 | + |
| 204 | + Free API Keys are available [here](https://metalpriceapi.com). |
| 205 | + |
| 206 | +- I want more information |
| 207 | + |
| 208 | + Checkout our FAQs [here](https://metalpriceapi.com/faq). |
| 209 | + |
| 210 | + |
| 211 | +## Support |
| 212 | + |
| 213 | +For support, get in touch using [this form](https://metalpriceapi.com/contact). |
| 214 | + |
| 215 | + |
| 216 | +[List]: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1 'List' |
| 217 | +[number]: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/numeric-types 'Number' |
| 218 | +[string]: https://learn.microsoft.com/en-us/dotnet/api/system.string 'String' |
0 commit comments