Skip to content

Commit 412937d

Browse files
Initial release v1.3.0 - Official .NET SDK for MetalpriceAPI
0 parents  commit 412937d

File tree

8 files changed

+507
-0
lines changed

8 files changed

+507
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bin/
2+
obj/
3+
.vs/
4+
*.user
5+
*.suo
6+
*.DotSettings

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2026 MetalpriceAPI
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MetalpriceAPI.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetalpriceAPI", "src\MetalpriceAPI\MetalpriceAPI.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
EndGlobal

README.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
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'

example/Example.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using MetalpriceAPI;
2+
3+
string apiKey = "REPLACE_ME";
4+
using var client = new MetalpriceApiClient(apiKey);
5+
6+
// Or use EU server:
7+
// using var client = new MetalpriceApiClient(apiKey, "eu");
8+
9+
var result = await client.FetchSymbolsAsync();
10+
Console.WriteLine(result);
11+
12+
result = await client.FetchLiveAsync("USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz");
13+
Console.WriteLine(result);
14+
15+
result = await client.FetchHistoricalAsync("2024-02-05", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz");
16+
Console.WriteLine(result);
17+
18+
result = await client.HourlyAsync("USD", "XAU", "troy_oz", "2025-11-03", "2025-11-03");
19+
Console.WriteLine(result);
20+
21+
result = await client.FetchOHLCAsync("USD", "XAU", "2024-02-06", "troy_oz");
22+
Console.WriteLine(result);
23+
24+
result = await client.ConvertAsync("USD", "EUR", 100, "2024-02-05");
25+
Console.WriteLine(result);
26+
27+
result = await client.TimeframeAsync("2024-02-05", "2024-02-06", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" }, "troy_oz");
28+
Console.WriteLine(result);
29+
30+
result = await client.ChangeAsync("2024-02-05", "2024-02-06", "USD", new List<string> { "XAU", "XAG", "XPD", "XPT" });
31+
Console.WriteLine(result);
32+
33+
result = await client.CaratAsync("USD", "XAU", "2024-02-06");
34+
Console.WriteLine(result);
35+
36+
result = await client.UsageAsync();
37+
Console.WriteLine(result);

example/Example.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\src\MetalpriceAPI\MetalpriceAPI.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<PackageId>MetalpriceAPI</PackageId>
8+
<Version>1.3.0</Version>
9+
<Authors>MetalpriceAPI</Authors>
10+
<Description>Official .NET wrapper for MetalpriceAPI.com - Metal price API and foreign exchange rate API</Description>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<PackageProjectUrl>https://metalpriceapi.com</PackageProjectUrl>
13+
<RepositoryUrl>https://github.com/metalpriceapi/metalpriceapi-csharp</RepositoryUrl>
14+
</PropertyGroup>
15+
16+
</Project>

0 commit comments

Comments
 (0)