2021-12-22 15:35:39 +00:00
|
|
|
package kucoinapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
2021-12-22 17:54:53 +00:00
|
|
|
"time"
|
2021-12-22 15:35:39 +00:00
|
|
|
|
2021-12-29 14:06:21 +00:00
|
|
|
"github.com/c9s/requestgen"
|
2021-12-22 16:41:10 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-12-22 15:35:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type BulletService struct {
|
|
|
|
client *RestClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BulletService) NewGetPublicBulletRequest() *GetPublicBulletRequest {
|
|
|
|
return &GetPublicBulletRequest{client: s.client}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BulletService) NewGetPrivateBulletRequest() *GetPrivateBulletRequest {
|
|
|
|
return &GetPrivateBulletRequest{client: s.client}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Bullet struct {
|
|
|
|
InstanceServers []struct {
|
|
|
|
Endpoint string `json:"endpoint"`
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
Encrypt bool `json:"encrypt"`
|
|
|
|
PingInterval int `json:"pingInterval"`
|
|
|
|
PingTimeout int `json:"pingTimeout"`
|
|
|
|
} `json:"instanceServers"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
}
|
|
|
|
|
2021-12-22 17:54:53 +00:00
|
|
|
func (b *Bullet) PingInterval() time.Duration {
|
|
|
|
return time.Duration(b.InstanceServers[0].PingInterval) * time.Millisecond
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Bullet) PingTimeout() time.Duration {
|
|
|
|
return time.Duration(b.InstanceServers[0].PingTimeout) * time.Millisecond
|
|
|
|
}
|
|
|
|
|
2021-12-22 16:41:10 +00:00
|
|
|
func (b *Bullet) URL() (*url.URL, error) {
|
|
|
|
if len(b.InstanceServers) == 0 {
|
|
|
|
return nil, errors.New("InstanceServers is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
u, err := url.Parse(b.InstanceServers[0].Endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params := url.Values{}
|
|
|
|
params.Add("token", b.Token)
|
|
|
|
|
|
|
|
u.RawQuery = params.Encode()
|
|
|
|
return u, nil
|
|
|
|
}
|
|
|
|
|
2021-12-29 14:06:21 +00:00
|
|
|
//go:generate requestgen -type GetPublicBulletRequest -method "POST" -url "/api/v1/bullet-public" -responseType .APIResponse -responseDataField Data -responseDataType .Bullet
|
|
|
|
type GetPublicBulletRequest struct {
|
|
|
|
client requestgen.APIClient
|
2021-12-22 15:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-29 14:06:21 +00:00
|
|
|
//go:generate requestgen -type GetPrivateBulletRequest -method "POST" -url "/api/v1/bullet-private" -responseType .APIResponse -responseDataField Data -responseDataType .Bullet
|
|
|
|
type GetPrivateBulletRequest struct {
|
|
|
|
client requestgen.AuthenticatedAPIClient
|
2021-12-22 15:35:39 +00:00
|
|
|
}
|