Skip to content

Commit 1ccd44f

Browse files
authored
Merge pull request #8 from magicaleks/SigV2-impl
fix: recvWindow + sig review
2 parents 447c814 + 6fdcaea commit 1ccd44f

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

client.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,17 @@ func (c *Client) parseRequest(r *request, opts ...RequestOption) (err error) {
140140
return err
141141
}
142142

143-
r.setParam(recvWindowKey, r.recvWindow)
143+
recvWindow := r.recvWindow
144+
if recvWindow == 0 {
145+
recvWindow = 10000
146+
}
147+
148+
r.setParam(recvWindowKey, recvWindow)
144149

145150
timestamp := time.Now().UnixNano() / 1e6
146151
if r.query != nil {
147152
r.setParam(timestampKey, timestamp)
153+
c.debug(r.query.Encode())
148154
sign := computeHmac256(r.query.Encode(), c.SecretKey)
149155
r.setParam(signatureKey, sign)
150156
} else {
@@ -197,7 +203,8 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
197203
}
198204
req = req.WithContext(ctx)
199205
req.Header = r.header
200-
c.debug("request: %#v", req)
206+
// c.debug("request: %#v", req)
207+
c.debug("request url: %#v", req.URL.String())
201208
f := c.do
202209
if f == nil {
203210
f = c.HTTPClient.Do
@@ -216,7 +223,7 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
216223
err = cerr
217224
}
218225
}()
219-
c.debug("response: %#v", res)
226+
// c.debug("response: %#v", res)
220227
c.debug("response body: %s", string(data))
221228
c.debug("response status code: %d", res.StatusCode)
222229

order_service.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -288,37 +288,35 @@ func (s *GetOrderService) Do(ctx context.Context, opts ...RequestOption) (res *G
288288
}
289289

290290
type GetOpenOrdersService struct {
291-
c *Client
292-
symbol string
293-
orderId int
294-
clientOrderID string
291+
c *Client
292+
symbol string
295293
}
296294

297295
// Define response of get order request
298296
type GetOpenOrdersResponse struct {
299-
Orders []*OpenOrderResponse `json:"orders"`
297+
Orders []*GetOrderResponse `json:"orders"`
300298
}
301299

302-
type OpenOrderResponse struct {
303-
Symbol string `json:"symbol"`
304-
OrderId int `json:"orderId"`
305-
Side SideType `json:"side"`
306-
PositionSide PositionSideType `json:"positionSide"`
307-
OrderType OrderType `json:"type"`
308-
OrigQuantity string `json:"origQty"`
309-
Price string `json:"price"`
310-
Quantity string `json:"executedQty"`
311-
AveragePrice string `json:"avgPrice"`
312-
CumQuote string `json:"cumQuote"`
313-
StopPrice string `json:"stopPrice"`
314-
Profit string `json:"profit"`
315-
Fee string `json:"commission"`
316-
Status OrderStatus `json:"status"`
317-
Time int64 `json:"time"`
318-
UpdateTime int64 `json:"ppdateTime"`
319-
WorkingType OrderWorkingType `json:"workingType"`
320-
ClientOrderID string `json:"clientOrderID"`
321-
}
300+
// type OpenOrderResponse struct {
301+
// Symbol string `json:"symbol"`
302+
// OrderId int `json:"orderId"`
303+
// Side SideType `json:"side"`
304+
// PositionSide PositionSideType `json:"positionSide"`
305+
// OrderType OrderType `json:"type"`
306+
// OrigQuantity string `json:"origQty"`
307+
// Price string `json:"price"`
308+
// Quantity string `json:"executedQty"`
309+
// AveragePrice string `json:"avgPrice"`
310+
// CumQuote string `json:"cumQuote"`
311+
// StopPrice string `json:"stopPrice"`
312+
// Profit string `json:"profit"`
313+
// Fee string `json:"commission"`
314+
// Status OrderStatus `json:"status"`
315+
// Time int64 `json:"time"`
316+
// UpdateTime int64 `json:"ppdateTime"`
317+
// WorkingType OrderWorkingType `json:"workingType"`
318+
// ClientOrderID string `json:"clientOrderID"`
319+
// }
322320

323321
func (s *GetOpenOrdersService) Symbol(symbol string) *GetOpenOrdersService {
324322
s.symbol = symbol

0 commit comments

Comments
 (0)