Files
m3o-go/examples/stock/README.md
2022-03-01 15:48:51 +00:00

2.0 KiB
Executable File

Stock

An m3o.com API. For example usage see m3o.com/stock/api.

Endpoints:

Price

Get the last price for a given stock ticker

https://m3o.com/stock/api#Price

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stock"
)

// Get the last price for a given stock ticker
func GetAstockPrice() {
	stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := stockService.Price(&stock.PriceRequest{
		Symbol: "AAPL",

	})
	fmt.Println(rsp, err)
	
}

Quote

Get the last quote for the stock

https://m3o.com/stock/api#Quote

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stock"
)

// Get the last quote for the stock
func GetAstockQuote() {
	stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := stockService.Quote(&stock.QuoteRequest{
		Symbol: "AAPL",

	})
	fmt.Println(rsp, err)
	
}

History

Get the historic open-close for a given day

https://m3o.com/stock/api#History

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stock"
)

// Get the historic open-close for a given day
func GetHistoricData() {
	stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := stockService.History(&stock.HistoryRequest{
		Date: "2020-10-01",
Stock: "AAPL",

	})
	fmt.Println(rsp, err)
	
}

OrderBook

Get the historic order book and each trade by timestamp

https://m3o.com/stock/api#OrderBook

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stock"
)

// Get the historic order book and each trade by timestamp
func OrderBookHistory() {
	stockService := stock.NewStockService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := stockService.OrderBook(&stock.OrderBookRequest{
		Date: "2020-10-01",
End: "2020-10-01T11:00:00Z",
Limit: 3,
Start: "2020-10-01T10:00:00Z",
Stock: "AAPL",

	})
	fmt.Println(rsp, err)
	
}