package bybit_connector import ( "context" "github.com/wuhewuhe/bybit.go.api/handlers" "github.com/wuhewuhe/bybit.go.api/models" "net/http" ) type TradeClient struct { c *Client params map[string]interface{} } func (s *TradeClient) PlaceOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/create", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) AmendOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/amend", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) CancelOrder(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/cancel", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) GetOpenOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodGet, endpoint: "/v5/order/realtime", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) GetOrderHistory(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodGet, endpoint: "/v5/order/history", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) GetSpotBorrowQuota(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodGet, endpoint: "/v5/order/spot-borrow-check", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) CancelAllOrders(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/cancel-all", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) SetDisconnectCancelAll(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/disconnected-cancel-all", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(ServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) PlaceBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/create-batch", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(models.BatchOrderServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) AmendBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/amend-batch", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(models.BatchOrderServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil } func (s *TradeClient) CancelBatchOrder(ctx context.Context, opts ...RequestOption) (res *models.BatchOrderServerResponse, err error) { if err = handlers.ValidateParams(s.params); err != nil { return nil, err } r := &request{ method: http.MethodPost, endpoint: "/v5/order/cancel-batch", secType: secTypeSigned, } r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err } res = new(models.BatchOrderServerResponse) err = json.Unmarshal(data, res) if err != nil { return nil, err } return res, nil }