From 7d216d4bfb97a3aef06d5ac44764e77a791dbfe6 Mon Sep 17 00:00:00 2001 From: Emanuele Bolognesi <35916369+adrift942@users.noreply.github.com> Date: Tue, 21 Dec 2021 16:25:29 +0100 Subject: [PATCH 1/3] fixed user agent --- client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index d3e65b0..464ffe5 100644 --- a/client.go +++ b/client.go @@ -205,9 +205,9 @@ func NewClient(apiKey, secretKey, passPhrase string) *Client { SecretKey: secretKey, PassPhrase: passPhrase, BaseURL: getAPIEndpoint(), - UserAgent: "Huobi/golang", + UserAgent: "Okex/golang", HTTPClient: http.DefaultClient, - Logger: log.New(os.Stderr, "Huobi-golang ", log.LstdFlags), + Logger: log.New(os.Stderr, "Okex-golang ", log.LstdFlags), Debug: false, Simulated: false, // True to enable simulated mode } From beb34aeb081e64271ae23bd5b04d6aedde98330c Mon Sep 17 00:00:00 2001 From: Emanuele Bolognesi <35916369+adrift942@users.noreply.github.com> Date: Sun, 2 Jan 2022 22:35:28 +0100 Subject: [PATCH 2/3] added ClosePositionService --- client.go | 5 ++++ order_service.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/client.go b/client.go index 464ffe5..12a918e 100644 --- a/client.go +++ b/client.go @@ -397,6 +397,11 @@ func (c *Client) NewAmendOrderService() *AmendOrderService { return &AmendOrderService{c: c} } +// ClosePositionService +func (c *Client) NewClosePositionService() *ClosePositionService { + return &ClosePositionService{c: c} +} + // NewPlaceAlgoOrderService func (c *Client) NewPlaceAlgoOrderService() *PlaceAlgoOrderService { return &PlaceAlgoOrderService{c: c} diff --git a/order_service.go b/order_service.go index af13926..4e9bcf2 100644 --- a/order_service.go +++ b/order_service.go @@ -473,6 +473,81 @@ type OrderDetail struct { ReqId string `json:"reqId"` } +// Close position +type ClosePositionService struct { + c *Client + instId string + posSide *string + mgnMode string + ccy *string +} + +// Set instrument id +func (s *ClosePositionService) InstrumentId(instId string) *ClosePositionService { + s.instId = instId + return s +} + +// Set position side +func (s *ClosePositionService) PositionSide(posSide string) *ClosePositionService { + s.posSide = &posSide + return s +} + +// Set margin mode +func (s *ClosePositionService) MarginMode(mgnMode string) *ClosePositionService { + s.mgnMode = mgnMode + return s +} + +// Set currency +func (s *ClosePositionService) Currency(ccy string) *ClosePositionService { + s.ccy = &ccy + return s +} + +// Do send request +func (s *ClosePositionService) Do(ctx context.Context, opts ...RequestOption) (res *ClosePositionServiceResponse, err error) { + r := &request{ + method: http.MethodPost, + endpoint: "/api/v5/trade/close-position", + secType: secTypeSigned, + } + + r.setBodyParam("instId", s.instId) + r.setBodyParam("mgnMode", s.mgnMode) + + if s.posSide != nil { + r.setBodyParam("posSide", *s.posSide) + } + if s.ccy != nil { + r.setBodyParam("ccy", *s.ccy) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + res = new(ClosePositionServiceResponse) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +} + +// Response to ClosePositionService +type ClosePositionServiceResponse struct { + Code string `json:"code"` + Msg string `json:"msg"` + Data []*ClosePositionDetail `json:"data"` +} + +type ClosePositionDetail struct { + InstId string `json:"instId"` + PosSide string `json:"posSide"` +} + // PlaceOrderService places a single order type PlaceAlgoOrderService struct { c *Client From 0e47f77a51be9b9cef1a575faada3d9148c64a7f Mon Sep 17 00:00:00 2001 From: Emanuele Bolognesi <35916369+adrift942@users.noreply.github.com> Date: Wed, 5 Jan 2022 19:35:36 +0100 Subject: [PATCH 3/3] added GetDeliveryExerciseHistoryService --- client.go | 5 +++ public_data.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/client.go b/client.go index 12a918e..7dcc24f 100644 --- a/client.go +++ b/client.go @@ -431,3 +431,8 @@ func (c *Client) NewGetInstrumentsService() *GetInstrumentsService { func (c *Client) NewGetLeverageService() *GetLeverageService { return &GetLeverageService{c: c} } + +// GetDeliveryExerciseHistoryService +func (c *Client) NewGetDeliveryExerciseHistoryService() *GetDeliveryExerciseHistoryService { + return &GetDeliveryExerciseHistoryService{c: c} +} diff --git a/public_data.go b/public_data.go index bd8ec6d..661f345 100644 --- a/public_data.go +++ b/public_data.go @@ -90,3 +90,93 @@ type InstrumentDetail struct { Alias string `json:"alias"` State string `json:"state"` } + +// GetDeliveryExerciseHistoryService +type GetDeliveryExerciseHistoryService struct { + c *Client + instType string + uly string + after *string + before *string + limit *string +} + +// Set instrument type +func (s *GetDeliveryExerciseHistoryService) InstrumentType(instType string) *GetDeliveryExerciseHistoryService { + s.instType = instType + return s +} + +// Set underlying +func (s *GetDeliveryExerciseHistoryService) Underlying(uly string) *GetDeliveryExerciseHistoryService { + s.uly = uly + return s +} + +// Set after +func (s *GetDeliveryExerciseHistoryService) After(after string) *GetDeliveryExerciseHistoryService { + s.after = &after + return s +} + +// Set before +func (s *GetDeliveryExerciseHistoryService) Before(before string) *GetDeliveryExerciseHistoryService { + s.before = &before + return s +} + +// Set limit +func (s *GetDeliveryExerciseHistoryService) Limit(limit string) *GetDeliveryExerciseHistoryService { + s.limit = &limit + return s +} + +// Do send request +func (s *GetDeliveryExerciseHistoryService) Do(ctx context.Context, opts ...RequestOption) (res *GetDeliveryExerciseHistoryServiceResponse, err error) { + r := &request{ + method: http.MethodGet, + endpoint: "/api/v5/public/delivery-exercise-history", + } + + r.setParam("instType", s.instType) + r.setParam("uly", s.uly) + + if s.after != nil { + r.setParam("after", *s.after) + } + if s.before != nil { + r.setParam("before", *s.before) + } + if s.limit != nil { + r.setParam("limit", *s.limit) + } + + data, err := s.c.callAPI(ctx, r, opts...) + if err != nil { + return nil, err + } + res = new(GetDeliveryExerciseHistoryServiceResponse) + err = json.Unmarshal(data, res) + if err != nil { + return nil, err + } + return res, nil +} + +// Response to GetInstrumentsService +type GetDeliveryExerciseHistoryServiceResponse struct { + Code string `json:"code"` + Msg string `json:"msg"` + Data []*DeliveryExcercise `json:"data"` +} + +type DeliveryExcercise struct { + Ts string `json:"timestamp"` + Details []*DeliveryExcerciseDetail `json:"details"` +} + +type DeliveryExcerciseDetail struct { + Type string `json:"type"` + InstId string `json:"instId"` + Px string `json:"px"` +}