Skip to content

Commit

Permalink
Release: v1.0.22-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-the-h committed Oct 10, 2021
1 parent 84f69ab commit 1448a67
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Changelog
=========
All notable changes to this project will be documented in this file.

v1.0.22-alpha
------------

### Changed

- Added place algo order
- Added cancel algo order
- Added get algo order list and history

v1.0.21-alpha
------------

Expand Down
93 changes: 90 additions & 3 deletions api/rest/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (c *Trade) ClosePosition(req requests.ClosePosition) (response responses.Cl
// Retrieve order details.
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-get-order-details
func (c *Trade) GetOrderDetail(req requests.OrderList) (response responses.Order, err error) {
func (c *Trade) GetOrderDetail(req requests.OrderList) (response responses.OrderList, err error) {
p := "/api/v5/trade/order"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, true, m)
Expand All @@ -154,7 +154,7 @@ func (c *Trade) GetOrderDetail(req requests.OrderList) (response responses.Order
// Retrieve all incomplete orders under the current account.
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-get-order-list
func (c *Trade) GetOrderList(req requests.OrderList) (response responses.Order, err error) {
func (c *Trade) GetOrderList(req requests.OrderList) (response responses.OrderList, err error) {
p := "/api/v5/trade/orders-pending"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, true, m)
Expand All @@ -174,7 +174,7 @@ func (c *Trade) GetOrderList(req requests.OrderList) (response responses.Order,
//
// Retrieve the completed order data of the last 3 months, and the incomplete orders that have been canceled are only reserved for 2 hours.
// https://www.okex.com/docs-v5/en/#rest-api-trade-get-order-history-last-3-months
func (c *Trade) GetOrderHistory(req requests.OrderList, arch bool) (response responses.Order, err error) {
func (c *Trade) GetOrderHistory(req requests.OrderList, arch bool) (response responses.OrderList, err error) {
p := "/api/v5/trade/orders-history"
if arch {
p = "/api/trade/orders-history-archive"
Expand Down Expand Up @@ -213,3 +213,90 @@ func (c *Trade) GetTransactionDetails(req requests.TransactionDetails, arch bool
err = d.Decode(&response)
return
}

// PlaceAlgoOrder
// The algo order includes trigger order, oco order, conditional order,iceberg order and twap order.
//
// `iceberg` order and `twap` order just supported on demo trading
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-place-algo-order
func (c *Trade) PlaceAlgoOrder(req requests.PlaceAlgoOrder) (response responses.PlaceAlgoOrder, err error) {
p := "/api/v5/trade/order-algo"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodPost, p, true, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)

return
}

// CancelAlgoOrder
// Cancel unfilled algo orders(trigger order, oco order, conditional order). A maximum of 10 orders can be canceled at a time. Request parameters should be passed in the form of an array.
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-cancel-algo-order
func (c *Trade) CancelAlgoOrder(req requests.CancelAlgoOrder) (response responses.CancelAlgoOrder, err error) {
p := "/api/v5/trade/cancel-algos"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodPost, p, true, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)

return
}

// CancelAdvanceAlgoOrder
// Cancel unfilled algo orders(iceberg order and twap order). A maximum of 10 orders can be canceled at a time. Request parameters should be passed in the form of an array.
//
// Only released on demo trading
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-cancel-advance-algo-order
func (c *Trade) CancelAdvanceAlgoOrder(req requests.CancelAlgoOrder) (response responses.CancelAlgoOrder, err error) {
p := "/api/v5/trade/cancel-advance-algos"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodPost, p, true, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)

return
}

// GetAlgoOrderList
// Retrieve a list of untriggered Algo orders under the current account.
//
// `iceberg` order and `twap` order just supported on demo trading
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-get-algo-order-list
//
// Retrieve a list of all algo orders under the current account in the last 3 months.
//
// `iceberg` order and `twap` order just supported on demo trading
//
// https://www.okex.com/docs-v5/en/#rest-api-trade-get-algo-order-history
func (c *Trade) GetAlgoOrderList(req requests.AlgoOrderList, arch bool) (response responses.AlgoOrderList, err error) {
p := "/api/v5/trade/orders-algo-pending"
if arch {
p = "/api/trade/orders-algo-history"
}
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, true, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)

return
}
12 changes: 12 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (
ContractType string
PositionType string
PositionSide string
ActualSide string
TradeMode string
CountAction string
OrderSide string
Expand All @@ -27,6 +28,7 @@ type (
Operation string
EventType string
OrderType string
AlgoOrderType string
QuantityType string
OrderFlowType string
OrderState string
Expand Down Expand Up @@ -147,6 +149,9 @@ const (
PositionShortSide = PositionSide("short")
PositionNetSide = PositionSide("net")

TpSide = ActualSide("tp")
SlSide = ActualSide("sl")

TradeCrossMode = TradeMode("cross")
TradeIsolatedMode = TradeMode("isolated")
TradeCashMode = TradeMode("cash")
Expand Down Expand Up @@ -198,6 +203,12 @@ const (
OrderIOC = OrderType("ioc")
OrderOptimalLimitIoc = OrderType("optimal_limit_ioc")

AlgoOrderConditional = AlgoOrderType("conditional")
AlgoOrderOCO = AlgoOrderType("oco")
AlgoOrderTrigger = AlgoOrderType("trigger")
AlgoOrderIceberg = AlgoOrderType("iceberg")
AlgoOrderTwap = AlgoOrderType("twap")

QuantityBaseCcy = QuantityType("base_ccy")
QuantityQuoteCcy = QuantityType("quote_ccy")

Expand All @@ -210,6 +221,7 @@ const (
ClassD = FeeCategory(4)

OrderCancel = OrderState("canceled")
OrderPause = OrderState("pause")
OrderLive = OrderState("live")
OrderPartiallyFilled = OrderState("partially_filled")
OrderFilled = OrderState("filled")
Expand Down
61 changes: 58 additions & 3 deletions models/trade/trade_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ type (
FeeCcy string `json:"feeCcy"`
RebateCcy string `json:"rebateCcy"`
Px okex.JSONFloat64 `json:"px"`
Sz okex.JSONFloat64 `json:"sz"`
Sz okex.JSONInt64 `json:"sz"`
Pnl okex.JSONFloat64 `json:"pnl"`
AccFillSz okex.JSONFloat64 `json:"accFillSz"`
AccFillSz okex.JSONInt64 `json:"accFillSz"`
FillPx okex.JSONFloat64 `json:"fillPx"`
FillSz okex.JSONFloat64 `json:"fillSz"`
FillSz okex.JSONInt64 `json:"fillSz"`
FillTime okex.JSONFloat64 `json:"fillTime"`
AvgPx okex.JSONFloat64 `json:"avgPx"`
Lever okex.JSONFloat64 `json:"lever"`
Expand Down Expand Up @@ -81,4 +81,59 @@ type (
ExecType okex.OrderFlowType `json:"execType"`
TS okex.JSONTime `json:"ts"`
}
PlaceAlgoOrder struct {
AlgoID string `json:"algoId"`
SMsg string `json:"sMsg"`
SCode okex.JSONInt64 `json:"sCode"`
}
CancelAlgoOrder struct {
AlgoID string `json:"algoId"`
SMsg string `json:"sMsg"`
SCode okex.JSONInt64 `json:"sCode"`
}
AlgoOrder struct {
InstID string `json:"instId"`
Ccy string `json:"ccy"`
OrdID string `json:"ordId"`
AlgoID string `json:"algoId"`
ClOrdID string `json:"clOrdId"`
TradeID string `json:"tradeId"`
Tag string `json:"tag"`
Category string `json:"category"`
FeeCcy string `json:"feeCcy"`
RebateCcy string `json:"rebateCcy"`
TimeInterval string `json:"timeInterval"`
Px okex.JSONFloat64 `json:"px"`
PxVar okex.JSONFloat64 `json:"pxVar"`
PxSpread okex.JSONFloat64 `json:"pxSpread"`
PxLimit okex.JSONFloat64 `json:"pxLimit"`
Sz okex.JSONInt64 `json:"sz"`
SzLimit okex.JSONInt64 `json:"szLimit"`
ActualSz okex.JSONFloat64 `json:"actualSz"`
ActualPx okex.JSONFloat64 `json:"actualPx"`
Pnl okex.JSONFloat64 `json:"pnl"`
AccFillSz okex.JSONInt64 `json:"accFillSz"`
FillPx okex.JSONFloat64 `json:"fillPx"`
FillSz okex.JSONInt64 `json:"fillSz"`
FillTime okex.JSONFloat64 `json:"fillTime"`
AvgPx okex.JSONFloat64 `json:"avgPx"`
Lever okex.JSONFloat64 `json:"lever"`
TpTriggerPx okex.JSONFloat64 `json:"tpTriggerPx"`
TpOrdPx okex.JSONFloat64 `json:"tpOrdPx"`
SlTriggerPx okex.JSONFloat64 `json:"slTriggerPx"`
SlOrdPx okex.JSONFloat64 `json:"slOrdPx"`
OrdPx okex.JSONFloat64 `json:"ordPx"`
Fee okex.JSONFloat64 `json:"fee"`
Rebate okex.JSONFloat64 `json:"rebate"`
State okex.OrderState `json:"state"`
TdMode okex.TradeMode `json:"tdMode"`
ActualSide okex.PositionSide `json:"actualSide"`
PosSide okex.PositionSide `json:"posSide"`
Side okex.OrderSide `json:"side"`
OrdType okex.AlgoOrderType `json:"ordType"`
InstType okex.InstrumentType `json:"instType"`
TgtCcy okex.QuantityType `json:"tgtCcy"`
CTime okex.JSONTime `json:"cTime"`
TriggerTime okex.JSONTime `json:"triggerTime"`
}
)
53 changes: 51 additions & 2 deletions requests/rest/trade/trade_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type (
ClOrdID string `json:"clOrdId,omitempty"`
Tag string `json:"tag,omitempty"`
ReduceOnly bool `json:"reduceOnly,omitempty"`
Sz float64 `json:"sz,string"`
Sz int64 `json:"sz,string"`
Px float64 `json:"px,omitempty,string"`
TdMode okex.TradeMode `json:"tdMode"`
Side okex.OrderSide `json:"side"`
Expand All @@ -32,7 +32,7 @@ type (
OrdID string `json:"ordId,omitempty"`
ClOrdID string `json:"clOrdId,omitempty"`
ReqID string `json:"reqId,omitempty"`
NewSz float64 `json:"newSz,omitempty,string"`
NewSz int64 `json:"newSz,omitempty,string"`
NewPx float64 `json:"newPx,omitempty,string"`
CxlOnFail bool `json:"cxlOnFail,omitempty"`
}
Expand Down Expand Up @@ -66,4 +66,53 @@ type (
Limit float64 `json:"limit,omitempty,string"`
InstType okex.InstrumentType `json:"instType,omitempty"`
}
PlaceAlgoOrder struct {
InstID string `json:"instId"`
TdMode okex.TradeMode `json:"tdMode"`
Ccy string `json:"ccy,omitempty"`
Side okex.OrderSide `json:"side"`
PosSide okex.PositionSide `json:"posSide,omitempty"`
OrdType okex.AlgoOrderType `json:"ordType"`
Sz int64 `json:"sz,string"`
ReduceOnly bool `json:"reduceOnly,omitempty"`
TgtCcy okex.QuantityType `json:"tgtCcy,omitempty"`
StopOrder
TriggerOrder
IcebergOrder
TWAPOrder
}
StopOrder struct {
TpTriggerPx float64 `json:"tpTriggerPx,string,omitempty"`
TpOrdPx float64 `json:"tpOrdPx,string,omitempty"`
SlTriggerPx float64 `json:"slTriggerPx,string,omitempty"`
SlOrdPx float64 `json:"slOrdPx,string,omitempty"`
}
TriggerOrder struct {
TriggerPx float64 `json:"triggerPx,string,omitempty"`
OrdPx float64 `json:"ordPx,string,omitempty"`
}
IcebergOrder struct {
PxVar float64 `json:"pxVar,string,omitempty"`
PxSpread float64 `json:"pxSpread,string,omitempty"`
SzLimit int64 `json:"szLimit,string"`
PxLimit float64 `json:"pxLimit,string"`
}
TWAPOrder struct {
IcebergOrder
TimeInterval string `json:"timeInterval"`
}
CancelAlgoOrder struct {
InstID string `json:"instId"`
AlgoID string `json:"AlgoId"`
}
AlgoOrderList struct {
InstType okex.InstrumentType `json:"instType,omitempty"`
Uly string `json:"uly,omitempty"`
InstID string `json:"instId,omitempty"`
After float64 `json:"after,omitempty,string"`
Before float64 `json:"before,omitempty,string"`
Limit float64 `json:"limit,omitempty,string"`
OrdType okex.AlgoOrderType `json:"ordType,omitempty"`
State okex.OrderState `json:"state,omitempty"`
}
)
14 changes: 13 additions & 1 deletion responses/trade/trade_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@ type (
responses.Basic
ClosePositions []*trade.ClosePosition `json:"data"`
}
Order struct {
OrderList struct {
responses.Basic
Orders []*trade.Order `json:"data"`
}
TransactionDetail struct {
responses.Basic
TransactionDetails []*trade.TransactionDetail `json:"data"`
}
PlaceAlgoOrder struct {
responses.Basic
PlaceAlgoOrders []*trade.PlaceAlgoOrder `json:"data"`
}
CancelAlgoOrder struct {
responses.Basic
CancelAlgoOrders []*trade.CancelAlgoOrder `json:"data"`
}
AlgoOrderList struct {
responses.Basic
AlgoOrders []*trade.AlgoOrder `json:"data"`
}
)

0 comments on commit 1448a67

Please sign in to comment.