Skip to content

Commit

Permalink
feat: add some htx apis
Browse files Browse the repository at this point in the history
  • Loading branch information
linstohu committed Dec 27, 2023
1 parent 26fb1c6 commit 524f084
Show file tree
Hide file tree
Showing 15 changed files with 2,144 additions and 0 deletions.
113 changes: 113 additions & 0 deletions htx/spot/rest/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,116 @@ func (scli *SpotClient) GetSymbols(ctx context.Context, param types.GetSymbolsPa

return &ret, nil
}

func (scli *SpotClient) GetSymbolInfo(ctx context.Context) (*types.GetSymbolInfoResp, error) {
req := utils.HTTPRequest{
BaseURL: scli.cli.GetBaseURL(),
Path: "/v1/settings/common/market-symbols",
Method: http.MethodGet,
}

{
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.GetSymbolInfoResp
if err := resp.ReadJsonBody(&ret); err != nil {
return nil, errors.New(resp.Error())
}

return &ret, nil
}

func (scli *SpotClient) GetMarketDepth(ctx context.Context, param types.GetMarketDepthParam) (*types.GetMarketDepthResp, error) {
req := utils.HTTPRequest{
BaseURL: scli.cli.GetBaseURL(),
Path: "/market/depth",
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.GetMarketDepthResp
if err := resp.ReadJsonBody(&ret); err != nil {
return nil, errors.New(err.Error())
}

return &ret, nil
}

func (scli *SpotClient) GetKline(ctx context.Context, param types.GetKlineParam) (*types.GetKlineResp, error) {
req := utils.HTTPRequest{
BaseURL: scli.cli.GetBaseURL(),
Path: "/market/history/kline",
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.GetKlineResp
if err := resp.ReadJsonBody(&ret); err != nil {
return nil, errors.New(resp.Error())
}

return &ret, nil
}

func (scli *SpotClient) GetAllMarketTickers(ctx context.Context) (*types.GetMarketTickersResp, error) {
req := utils.HTTPRequest{
BaseURL: scli.cli.GetBaseURL(),
Path: "/market/tickers",
Method: http.MethodGet,
}

{
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.GetMarketTickersResp
if err := resp.ReadJsonBody(&ret); err != nil {
return nil, errors.New(resp.Error())
}

return &ret, nil
}
40 changes: 40 additions & 0 deletions htx/spot/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ func TestNewOrder(t *testing.T) {

assert.Nil(t, err)
}

func TestCancelOrder(t *testing.T) {
cli := testNewSpotClient(t)

_, err := cli.CancelOrder(context.TODO(), types.CancelOrderParams{
OrderID: "",
})

assert.Nil(t, err)
}

func TestGetOpenOrders(t *testing.T) {
cli := testNewSpotClient(t)

_, err := cli.GetOpenOrders(context.TODO(), types.GetOpenOrdersParam{
AccountID: "",
})

assert.Nil(t, err)
}

func TestCancelOrders(t *testing.T) {
cli := testNewSpotClient(t)

_, err := cli.CancelOrders(context.TODO(), types.CancelOrdersParam{
AccountID: "",
})

assert.Nil(t, err)
}

func TestSearchMatchResults(t *testing.T) {
cli := testNewSpotClient(t)

_, err := cli.SearchMatchResults(context.TODO(), types.SearchMatchResultsParam{
Symbol: "usdcusdt",
})

assert.Nil(t, err)
}
Loading

0 comments on commit 524f084

Please sign in to comment.