mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pkg/exchange: add QueryOrder api
This commit is contained in:
parent
bc9f7b7a1e
commit
3207a8227c
|
@ -28,6 +28,11 @@ func (g *GetOrderHistoriesRequest) OrderId(orderId string) *GetOrderHistoriesReq
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GetOrderHistoriesRequest) OrderLinkId(orderLinkId string) *GetOrderHistoriesRequest {
|
||||||
|
g.orderLinkId = &orderLinkId
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GetOrderHistoriesRequest) OrderFilter(orderFilter string) *GetOrderHistoriesRequest {
|
func (g *GetOrderHistoriesRequest) OrderFilter(orderFilter string) *GetOrderHistoriesRequest {
|
||||||
g.orderFilter = &orderFilter
|
g.orderFilter = &orderFilter
|
||||||
return g
|
return g
|
||||||
|
@ -93,6 +98,14 @@ func (g *GetOrderHistoriesRequest) GetQueryParameters() (url.Values, error) {
|
||||||
params["orderId"] = orderId
|
params["orderId"] = orderId
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
// check orderLinkId field -> json key orderLinkId
|
||||||
|
if g.orderLinkId != nil {
|
||||||
|
orderLinkId := *g.orderLinkId
|
||||||
|
|
||||||
|
// assign parameter of orderLinkId
|
||||||
|
params["orderLinkId"] = orderLinkId
|
||||||
|
} else {
|
||||||
|
}
|
||||||
// check orderFilter field -> json key orderFilter
|
// check orderFilter field -> json key orderFilter
|
||||||
if g.orderFilter != nil {
|
if g.orderFilter != nil {
|
||||||
orderFilter := *g.orderFilter
|
orderFilter := *g.orderFilter
|
||||||
|
|
|
@ -9,14 +9,15 @@ import (
|
||||||
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result
|
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Result
|
||||||
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result
|
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Result
|
||||||
|
|
||||||
//go:generate GetRequest -url "/v5/order/history" -type GetOrderHistoriesRequest -responseDataType .OpenOrdersResponse
|
//go:generate GetRequest -url "/v5/order/history" -type GetOrderHistoriesRequest -responseDataType .OrdersResponse
|
||||||
type GetOrderHistoriesRequest struct {
|
type GetOrderHistoriesRequest struct {
|
||||||
client requestgen.AuthenticatedAPIClient
|
client requestgen.AuthenticatedAPIClient
|
||||||
|
|
||||||
category Category `param:"category,query" validValues:"spot"`
|
category Category `param:"category,query" validValues:"spot"`
|
||||||
|
|
||||||
symbol *string `param:"symbol,query"`
|
symbol *string `param:"symbol,query"`
|
||||||
orderId *string `param:"orderId,query"`
|
orderId *string `param:"orderId,query"`
|
||||||
|
orderLinkId *string `param:"orderLinkId,query"`
|
||||||
// orderFilter supports 3 types of Order:
|
// orderFilter supports 3 types of Order:
|
||||||
// 1. active order, 2. StopOrder: conditional order, 3. tpslOrder: spot TP/SL order
|
// 1. active order, 2. StopOrder: conditional order, 3. tpslOrder: spot TP/SL order
|
||||||
// Normal spot: return Order active order by default
|
// Normal spot: return Order active order by default
|
||||||
|
|
|
@ -2,6 +2,7 @@ package bybit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -183,6 +184,39 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
|
||||||
return orders, nil
|
return orders, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) {
|
||||||
|
if len(q.OrderID) == 0 && len(q.ClientOrderID) == 0 {
|
||||||
|
return nil, errors.New("one of OrderID/ClientOrderID is required parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(q.OrderID) != 0 && len(q.ClientOrderID) != 0 {
|
||||||
|
return nil, errors.New("only accept one parameter of OrderID/ClientOrderID")
|
||||||
|
}
|
||||||
|
|
||||||
|
req := e.client.NewGetOrderHistoriesRequest()
|
||||||
|
if len(q.Symbol) != 0 {
|
||||||
|
req.Symbol(q.Symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(q.OrderID) != 0 {
|
||||||
|
req.OrderId(q.OrderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(q.ClientOrderID) != 0 {
|
||||||
|
req.OrderLinkId(q.ClientOrderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := req.Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to query order, queryConfig: %+v, err: %w", q, err)
|
||||||
|
}
|
||||||
|
if len(res.List) != 1 {
|
||||||
|
return nil, fmt.Errorf("unexpected order length, queryConfig: %+v", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
return toGlobalOrder(res.List[0])
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
|
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error) {
|
||||||
if len(order.Market.Symbol) == 0 {
|
if len(order.Market.Symbol) == 0 {
|
||||||
return nil, fmt.Errorf("order.Market.Symbol is required: %+v", order)
|
return nil, fmt.Errorf("order.Market.Symbol is required: %+v", order)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user