moonmath/bitcoinity/client.go

45 lines
915 B
Go
Raw Normal View History

2024-03-17 09:10:05 +00:00
package bitcoinity
import (
"context"
"github.com/carlmjohnson/requests"
"golang.org/x/net/websocket"
)
func GetWebsocket() (Websocket, error) {
origin := baseUrl
url := "wss://bitcoinity.org/webs_bridge/websocket?vsn=1.0.0"
conn, err := websocket.Dial(url, "", origin)
if err != nil {
return nil, err
}
ws := newWebsocket(conn)
return ws, nil
}
func GetTicker(
ctx context.Context, req *GetTickerRequest,
) (*GetTickerResponse, error) {
var resp GetTickerResponse
err := requests.New(commonConfig).
Path("/markets/get_ticker").
Param("currency", string(req.Currency)).
Param("exchange", string(req.Exchange)).
Param("span", string(req.Span)).
ToJSON(&resp).
Fetch(ctx)
if err != nil {
return nil, err
}
return &resp, nil
}
const baseUrl = "https://bitcoinity.org"
func commonConfig(rb *requests.Builder) {
rb.
BaseURL(baseUrl).
Accept("application/json;charset=utf-8")
}