Files
m3o-go/examples/forex/README.md
2022-02-24 18:24:35 +00:00

91 lines
1.4 KiB
Markdown
Executable File

# Forex
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/forex/api](https://m3o.com/forex/api).
Endpoints:
## Quote
Get the latest quote for the forex
[https://m3o.com/forex/api#Quote](https://m3o.com/forex/api#Quote)
```go
package example
import(
"fmt"
"os"
"go.m3o.com/forex"
)
// Get the latest quote for the forex
func GetAfxQuote() {
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
rsp, err := forexService.Quote(&forex.QuoteRequest{
Symbol: "GBPUSD",
})
fmt.Println(rsp, err)
}
```
## History
Returns the data for the previous close
[https://m3o.com/forex/api#History](https://m3o.com/forex/api#History)
```go
package example
import(
"fmt"
"os"
"go.m3o.com/forex"
)
// Returns the data for the previous close
func GetPreviousClose() {
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
rsp, err := forexService.History(&forex.HistoryRequest{
Symbol: "GBPUSD",
})
fmt.Println(rsp, err)
}
```
## Price
Get the latest price for a given forex ticker
[https://m3o.com/forex/api#Price](https://m3o.com/forex/api#Price)
```go
package example
import(
"fmt"
"os"
"go.m3o.com/forex"
)
// Get the latest price for a given forex ticker
func GetAnFxPrice() {
forexService := forex.NewForexService(os.Getenv("M3O_API_TOKEN"))
rsp, err := forexService.Price(&forex.PriceRequest{
Symbol: "GBPUSD",
})
fmt.Println(rsp, err)
}
```