Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions v2/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ type GetAccountService struct {
omitZeroBalances *bool
}

// OmitZeroBalances sets the omitZeroBalances parameter on the request.
// When set to true, the API will return the non-zero balances of an account.
func (s *GetAccountService) OmitZeroBalances(v bool) *GetAccountService {
s.omitZeroBalances = &v
return s
}

// Do send request
func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
// buildRequest creates the API request for GetAccount
func (s *GetAccountService) buildRequest() *request {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/account",
Expand All @@ -29,7 +22,19 @@ func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res
if s.omitZeroBalances != nil {
r.setParam("omitZeroBalances", *s.omitZeroBalances)
}
return r
}

// OmitZeroBalances sets the omitZeroBalances parameter on the request.
// When set to true, the API will return the non-zero balances of an account.
func (s *GetAccountService) OmitZeroBalances(v bool) *GetAccountService {
s.omitZeroBalances = &v
return s
}

// Do send request
func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -42,6 +47,27 @@ func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res
return res, nil
}

// DoSBE sends the request with SBE encoding and returns the decoded response
// Template 400 - AccountResponse
func (s *GetAccountService) DoSBE(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
// Add SBE headers
opts = append(opts, WithSBE(3, 1))

r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}

// Decode SBE response using centralized decoder
res = &Account{}
if err := sbeDecoder.DecodeResponse(data, res); err != nil {
return nil, err
}

return res, nil
}

// Account define account info
type Account struct {
MakerCommission int64 `json:"makerCommission"`
Expand Down
43 changes: 35 additions & 8 deletions v2/depth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ type DepthService struct {
limit *int
}

// buildRequest creates the API request for Depth
func (s *DepthService) buildRequest() *request {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/depth",
}
r.setParam("symbol", s.symbol)
if s.limit != nil {
r.setParam("limit", *s.limit)
}
return r
}

// Symbol set symbol
func (s *DepthService) Symbol(symbol string) *DepthService {
s.symbol = symbol
Expand All @@ -28,14 +41,7 @@ func (s *DepthService) Limit(limit int) *DepthService {

// Do send request
func (s *DepthService) Do(ctx context.Context, opts ...RequestOption) (res *DepthResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/depth",
}
r.setParam("symbol", s.symbol)
if s.limit != nil {
r.setParam("limit", *s.limit)
}
r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -67,6 +73,27 @@ func (s *DepthService) Do(ctx context.Context, opts ...RequestOption) (res *Dept
return res, nil
}

// DoSBE sends the request with SBE encoding and returns the decoded response
// Template 200 - DepthResponse
func (s *DepthService) DoSBE(ctx context.Context, opts ...RequestOption) (res *DepthResponse, err error) {
// Add SBE headers
opts = append(opts, WithSBE(3, 1))

r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}

// Decode SBE response using centralized decoder
res = &DepthResponse{}
if err := sbeDecoder.DecodeResponse(data, res); err != nil {
return nil, err
}

return res, nil
}

// DepthResponse define depth info with bids and asks
type DepthResponse struct {
LastUpdateID int64 `json:"lastUpdateId"`
Expand Down
63 changes: 45 additions & 18 deletions v2/kline_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ type KlinesService struct {
timeZone *string // Default: 0 (UTC)
}

// buildRequest creates the API request for Klines
func (s *KlinesService) buildRequest() *request {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/klines",
}
r.setParam("symbol", s.symbol)
r.setParam("interval", s.interval)
if s.limit != nil {
r.setParam("limit", *s.limit)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.timeZone != nil {
r.setParam("timeZone", *s.timeZone)
}
return r
}

// Symbol set symbol
func (s *KlinesService) Symbol(symbol string) *KlinesService {
s.symbol = symbol
Expand Down Expand Up @@ -55,24 +78,7 @@ func (s *KlinesService) TimeZone(timeZone string) *KlinesService {

// Do send request
func (s *KlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*Kline, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/klines",
}
r.setParam("symbol", s.symbol)
r.setParam("interval", s.interval)
if s.limit != nil {
r.setParam("limit", *s.limit)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.timeZone != nil {
r.setParam("timeZone", *s.timeZone)
}
r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*Kline{}, err
Expand Down Expand Up @@ -106,6 +112,27 @@ func (s *KlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*K
return res, nil
}

// DoSBE sends the request with SBE encoding and returns the decoded response
// Template 203 - KlinesResponse
func (s *KlinesService) DoSBE(ctx context.Context, opts ...RequestOption) (res []*Kline, err error) {
// Add SBE headers
opts = append(opts, WithSBE(3, 1))

r := s.buildRequest()
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}

// Decode SBE response using centralized decoder
res = make([]*Kline, 0)
if err := sbeDecoder.DecodeResponse(data, &res); err != nil {
return nil, err
}

return res, nil
}

// Kline define kline info
type Kline struct {
OpenTime int64 `json:"openTime"`
Expand Down
Loading