mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
add constructor to check url error
This commit is contained in:
parent
7550ea2be1
commit
dbf29f8cd2
|
@ -44,10 +44,8 @@ var rootCmd = &cobra.Command{
|
|||
return errors.New("empty key, secret or passphrase")
|
||||
}
|
||||
|
||||
client, err := okexapi.NewClient()
|
||||
if err != nil {
|
||||
return errors.New("init client error: please check url")
|
||||
}
|
||||
client := okexapi.NewClient()
|
||||
|
||||
client.Auth(key, secret, passphrase)
|
||||
|
||||
instruments, err := client.NewGetInstrumentsRequest().
|
||||
|
|
|
@ -35,10 +35,7 @@ type Exchange struct {
|
|||
}
|
||||
|
||||
func New(key, secret, passphrase string) (*Exchange, error) {
|
||||
client, err := okexapi.NewClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := okexapi.NewClient()
|
||||
|
||||
if len(key) > 0 && len(secret) > 0 {
|
||||
client.Auth(key, secret, passphrase)
|
||||
|
|
|
@ -66,21 +66,26 @@ type RestClient struct {
|
|||
Key, Secret, Passphrase string
|
||||
}
|
||||
|
||||
func NewClient() (*RestClient, error) {
|
||||
u, err := url.Parse(RestBaseURL)
|
||||
var parsedBaseURL *url.URL
|
||||
|
||||
func init() {
|
||||
url, err := url.Parse(RestBaseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
panic(err)
|
||||
}
|
||||
parsedBaseURL = url
|
||||
}
|
||||
|
||||
func NewClient() *RestClient {
|
||||
client := &RestClient{
|
||||
BaseAPIClient: requestgen.BaseAPIClient{
|
||||
BaseURL: u,
|
||||
BaseURL: parsedBaseURL,
|
||||
HttpClient: &http.Client{
|
||||
Timeout: defaultHTTPTimeout,
|
||||
},
|
||||
},
|
||||
}
|
||||
return client, nil
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *RestClient) Auth(key, secret, passphrase string) {
|
||||
|
|
|
@ -22,15 +22,13 @@ func getTestClientOrSkip(t *testing.T) *RestClient {
|
|||
return nil
|
||||
}
|
||||
|
||||
client, err := NewClient()
|
||||
assert.NoError(t, err)
|
||||
client := NewClient()
|
||||
client.Auth(key, secret, passphrase)
|
||||
return client
|
||||
}
|
||||
|
||||
func TestClient_GetInstrumentsRequest(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
assert.NoError(t, err)
|
||||
client := NewClient()
|
||||
ctx := context.Background()
|
||||
req := client.NewGetInstrumentsRequest()
|
||||
|
||||
|
@ -43,8 +41,7 @@ func TestClient_GetInstrumentsRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClient_GetFundingRateRequest(t *testing.T) {
|
||||
client, err := NewClient()
|
||||
assert.NoError(t, err)
|
||||
client := NewClient()
|
||||
ctx := context.Background()
|
||||
req := client.NewGetFundingRate()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user