45 lines
915 B
Go
45 lines
915 B
Go
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")
|
|
}
|