Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/tbtc-bot/go-okex
Browse files Browse the repository at this point in the history
  • Loading branch information
amaioli committed Jan 9, 2022
2 parents c3a5282 + 0e47f77 commit 92eece1
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -426,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}
}
75 changes: 75 additions & 0 deletions order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions public_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 92eece1

Please sign in to comment.