-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
570 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023, LinstoHu | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/linstohu/nexapi/htx/spot/rest/types" | ||
"github.com/linstohu/nexapi/htx/utils" | ||
) | ||
|
||
func (scli *SpotClient) GetSymbols(ctx context.Context, param types.GetSymbolsParam) (*types.GetSymbolsResp, error) { | ||
req := utils.HTTPRequest{ | ||
BaseURL: scli.cli.GetBaseURL(), | ||
Path: "/v2/settings/common/symbols", | ||
Method: http.MethodGet, | ||
Query: param, | ||
} | ||
|
||
{ | ||
headers, err := scli.cli.GetHeaders() | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Headers = headers | ||
} | ||
|
||
resp, err := scli.cli.SendHTTPRequest(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret types.GetSymbolsResp | ||
if err := resp.ReadJsonBody(&ret); err != nil { | ||
return nil, errors.New(resp.Error()) | ||
} | ||
|
||
return &ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2023, LinstoHu | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/linstohu/nexapi/htx/spot/rest/types" | ||
"github.com/linstohu/nexapi/htx/utils" | ||
) | ||
|
||
func (scli *SpotClient) GetMergedMarketTicker(ctx context.Context, param types.GetMergedMarketTickerParam) (*types.GetMergedMarketTickerResp, error) { | ||
err := scli.validate.Struct(param) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req := utils.HTTPRequest{ | ||
BaseURL: scli.cli.GetBaseURL(), | ||
Path: "/market/detail/merged", | ||
Method: http.MethodGet, | ||
Query: param, | ||
} | ||
|
||
{ | ||
headers, err := scli.cli.GetHeaders() | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Headers = headers | ||
} | ||
|
||
resp, err := scli.cli.SendHTTPRequest(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret types.GetMergedMarketTickerResp | ||
if err := resp.ReadJsonBody(&ret); err != nil { | ||
return nil, errors.New(resp.Error()) | ||
} | ||
|
||
return &ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2023, LinstoHu | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/linstohu/nexapi/htx/spot/rest/types" | ||
"github.com/linstohu/nexapi/htx/utils" | ||
) | ||
|
||
func (scli *SpotClient) NewOrder(ctx context.Context, param types.NewOrderParam) (*types.NewOrderResp, error) { | ||
if err := scli.cli.CheckAuth(); err != nil { | ||
return nil, err | ||
} | ||
|
||
err := scli.validate.Struct(param) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req := utils.HTTPRequest{ | ||
BaseURL: scli.cli.GetBaseURL(), | ||
Path: "/v1/order/orders/place", | ||
Method: http.MethodPost, | ||
Body: param, | ||
} | ||
|
||
{ | ||
headers, err := scli.cli.GetHeaders() | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Headers = headers | ||
} | ||
|
||
{ | ||
query := scli.cli.GenAuthParams() | ||
|
||
signStr, err := scli.cli.NormalizeRequestContent(req, query) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
h := scli.cli.Sign([]byte(signStr)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query.Signature = h | ||
|
||
req.Query = query | ||
} | ||
|
||
resp, err := scli.cli.SendHTTPRequest(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ret types.NewOrderResp | ||
if err := resp.ReadJsonBody(&ret); err != nil { | ||
return nil, errors.New(resp.Error()) | ||
} | ||
|
||
return &ret, nil | ||
} |
Oops, something went wrong.