Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NewListOpenOcoService #348

Merged
merged 1 commit into from
Feb 16, 2022
Merged
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"ocos"
]
}
5 changes: 5 additions & 0 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ func (c *Client) NewListOpenOrdersService() *ListOpenOrdersService {
return &ListOpenOrdersService{c: c}
}

// NewListOpenOcoService init list open oco service
func (c *Client) NewListOpenOcoService() *ListOpenOcoService {
return &ListOpenOcoService{c: c}
}

// NewListOrdersService init listing orders service
func (c *Client) NewListOrdersService() *ListOrdersService {
return &ListOrdersService{c: c}
Expand Down
2 changes: 1 addition & 1 deletion v2/margin_order_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s *marginOrderServiceTestSuite) TestCreateOrderFull() {
Type: OrderTypeLimit,
Side: SideTypeBuy,
Fills: []*Fill{
&Fill{
{
Price: "0.00002991",
Quantity: "344.00000000",
Commission: "0.00332384",
Expand Down
36 changes: 36 additions & 0 deletions v2/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,42 @@ type OCOOrderReport struct {
IcebergQuantity string `json:"icebergQty"`
}

// ListOpenOcoService list opened oco
type ListOpenOcoService struct {
c *Client
}

// oco define oco info
type Oco struct {
Symbol string `json:"symbol"`
OrderListId int64 `json:"orderListId"`
ContingencyType string `json:"contingencyType"`
ListStatusType string `json:"listStatusType"`
ListOrderStatus string `json:"listOrderStatus"`
ListClientOrderID string `json:"listClientOrderId"`
TransactionTime int64 `json:"transactionTime"`
Orders []*Order `json:"orders"`
}

// Do send request
func (s *ListOpenOcoService) Do(ctx context.Context, opts ...RequestOption) (res []*Oco, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/openOrderList ",
secType: secTypeSigned,
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*Oco{}, err
}
res = make([]*Oco, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*Oco{}, err
}
return res, nil
}

// ListOpenOrdersService list opened orders
type ListOpenOrdersService struct {
c *Client
Expand Down
80 changes: 78 additions & 2 deletions v2/order_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *orderServiceTestSuite) TestCreateOrderFull() {
Type: OrderTypeLimit,
Side: SideTypeBuy,
Fills: []*Fill{
&Fill{
{
Price: "0.00002991",
Quantity: "344.00000000",
Commission: "0.00332384",
Expand Down Expand Up @@ -387,7 +387,83 @@ func (s *baseOrderTestSuite) assertOCOOrderEqual(e, a *OCOOrder) {
r.Equal(e.OrderID, a.OrderID, "OrderID")
r.Equal(e.Symbol, a.Symbol, "Symbol")
}

func (s *orderServiceTestSuite) TestListOpenOco() {
data := []byte(`[
{
"orderListId": 31,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "wuB13fmulKj3YjdqWEcsnp",
"transactionTime": 1565246080644,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "r3EH2N76dHfLoSZWIUw1bT"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Cv1SnyPD3qhqpbjpYEHbd2"
}
]
}
]`)
s.mockDo(data, nil)
defer s.assertDo()
recvWindow := int64(1000)
s.assertReq(func(r *request) {
e := newSignedRequest().setParams(params{
"recvWindow": recvWindow,
})
s.assertRequestEqual(e, r)
})
ocos, err := s.client.NewListOpenOcoService().
Do(newContext(), WithRecvWindow(recvWindow))
r := s.r()
r.NoError(err)
r.Len(ocos, 1)
e := &Oco{
Symbol: "LTCBTC",
OrderListId: 31,
ContingencyType: "OCO",
ListStatusType: "EXEC_STARTED",
ListOrderStatus: "EXECUTING",
ListClientOrderID: "wuB13fmulKj3YjdqWEcsnp",
TransactionTime: 1565246080644,
Orders: []*Order{
{
Symbol: "LTCBTC",
OrderID: 4,
ClientOrderID: "r3EH2N76dHfLoSZWIUw1bT",
},
{
Symbol: "LTCBTC",
OrderID: 5,
ClientOrderID: "Cv1SnyPD3qhqpbjpYEHbd2",
},
},
}
s.assertOcoEqual(e, ocos[0])
}
func (s *baseOrderTestSuite) assertOcoEqual(e, a *Oco) {
r := s.r()
r.Equal(e.Symbol, a.Symbol, "Symbol")
r.Equal(e.ContingencyType, a.ContingencyType, "ContingencyType")
r.Equal(e.ListClientOrderID, a.ListClientOrderID, "ListClientOrderID")
r.Equal(e.ListOrderStatus, a.ListOrderStatus, "ListOrderStatus")
r.Equal(e.ListStatusType, a.ListStatusType, "ListStatusType")
r.Equal(e.OrderListId, a.OrderListId, "OrderListId")
r.Equal(e.Orders[0].Symbol, a.Orders[0].Symbol, "Orders[0].Symbol")
r.Equal(e.Orders[0].OrderID, a.Orders[0].OrderID, "Orders[0].OrderID")
r.Equal(e.Orders[0].ClientOrderID, a.Orders[0].ClientOrderID, "Orders[0].ClientOrderID")
r.Equal(e.Orders[1].Symbol, a.Orders[1].Symbol, "Orders[1].Symbol")
r.Equal(e.Orders[1].OrderID, a.Orders[1].OrderID, "Orders[1].OrderID")
r.Equal(e.Orders[1].ClientOrderID, a.Orders[1].ClientOrderID, "Orders[1].ClientOrderID")
r.Equal(e.TransactionTime, a.TransactionTime, "TransactionTime")
}
func (s *orderServiceTestSuite) TestListOpenOrders() {
data := []byte(`[
{
Expand Down