mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-11 18:44:26 +00:00
150 lines
2.7 KiB
Markdown
Executable File
150 lines
2.7 KiB
Markdown
Executable File
# Currency
|
|
|
|
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/currency/api](https://m3o.com/currency/api).
|
|
|
|
Endpoints:
|
|
|
|
## Codes
|
|
|
|
Codes returns the supported currency codes for the API
|
|
|
|
|
|
[https://m3o.com/currency/api#Codes](https://m3o.com/currency/api#Codes)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/currency"
|
|
)
|
|
|
|
// Codes returns the supported currency codes for the API
|
|
func GetSupportedCodes() {
|
|
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := currencyService.Codes(¤cy.CodesRequest{
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Rates
|
|
|
|
Rates returns the currency rates for a given code e.g USD
|
|
|
|
|
|
[https://m3o.com/currency/api#Rates](https://m3o.com/currency/api#Rates)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/currency"
|
|
)
|
|
|
|
// Rates returns the currency rates for a given code e.g USD
|
|
func GetRatesForUsd() {
|
|
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := currencyService.Rates(¤cy.RatesRequest{
|
|
Code: "USD",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Convert
|
|
|
|
Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
|
|
|
|
[https://m3o.com/currency/api#Convert](https://m3o.com/currency/api#Convert)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/currency"
|
|
)
|
|
|
|
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
func ConvertUsdToGbp() {
|
|
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
From: "USD",
|
|
To: "GBP",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## Convert
|
|
|
|
Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
|
|
|
|
[https://m3o.com/currency/api#Convert](https://m3o.com/currency/api#Convert)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/currency"
|
|
)
|
|
|
|
// Convert returns the currency conversion rate between two pairs e.g USD/GBP
|
|
func Convert10usdToGbp() {
|
|
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := currencyService.Convert(¤cy.ConvertRequest{
|
|
Amount: 10,
|
|
From: "USD",
|
|
To: "GBP",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|
|
## History
|
|
|
|
Returns the historic rates for a currency on a given date
|
|
|
|
|
|
[https://m3o.com/currency/api#History](https://m3o.com/currency/api#History)
|
|
|
|
```go
|
|
package example
|
|
|
|
import(
|
|
"fmt"
|
|
"os"
|
|
|
|
"go.m3o.com/currency"
|
|
)
|
|
|
|
// Returns the historic rates for a currency on a given date
|
|
func HistoricRatesForAcurrency() {
|
|
currencyService := currency.NewCurrencyService(os.Getenv("M3O_API_TOKEN"))
|
|
rsp, err := currencyService.History(¤cy.HistoryRequest{
|
|
Code: "USD",
|
|
Date: "2021-05-30",
|
|
|
|
})
|
|
fmt.Println(rsp, err)
|
|
|
|
}
|
|
```
|