mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-18 23:16:49 +00:00
Getting closed orders implementation, fixed Binance MARKET order creation, expanded SubmitOrder response (#572)
* GetClosedOrder implemented for Kraken and Binance, fixed Binance MARKET order creaton, added rate, fee and cost fileds on SubmitOrder responce * return Trades on Binance SubmitOrder, new validation methods on Binance and kraken GetClosedOrderInfo * removed the Binance extra method GetClosedOrder * func description corrected * removed price, fee and cost from SimulateOrder response, as we get all necessary info in response to calculate them on client side * GetClosedOrder implementation moved to GetOrderInfo * changed GetOrderInfo params * removed Canceled order.Type used for Kraken * update QueryOrder in gctscript * add missed params to QueryOrder validator (gctscript) * fixed testing issues * GetClosedOrder implemented for Kraken and Binance, fixed Binance MARKET order creaton, added rate, fee and cost fileds on SubmitOrder responce * return Trades on Binance SubmitOrder, new validation methods on Binance and kraken GetClosedOrderInfo * removed the Binance extra method GetClosedOrder * func description corrected * removed price, fee and cost from SimulateOrder response, as we get all necessary info in response to calculate them on client side * GetClosedOrder implementation moved to GetOrderInfo * changed GetOrderInfo params * removed Canceled order.Type used for Kraken * update QueryOrder in gctscript * add missed params to QueryOrder validator (gctscript) * fixed testing issues * pull previous changes * linter issues fix * updated query_order exmple in gctscript, fixed params check * removed orderPair unnecessary conversion Co-authored-by: Vazha Bezhanishvili <vazha.bezhanishvili@elegro.eu>
This commit is contained in:
@@ -269,8 +269,8 @@ func (a *Alphapoint) CancelAllOrders(orderCancellation *order.Cancel) (order.Can
|
||||
a.CancelAllExistingOrders(orderCancellation.AccountID)
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (a *Alphapoint) GetOrderInfo(orderID string) (float64, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (a *Alphapoint) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (float64, error) {
|
||||
orders, err := a.GetOrders()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -45,6 +45,7 @@ const (
|
||||
queryOrder = "/api/v3/order"
|
||||
openOrders = "/api/v3/openOrders"
|
||||
allOrders = "/api/v3/allOrders"
|
||||
myTrades = "/api/v3/myTrades"
|
||||
|
||||
// Withdraw API endpoints
|
||||
withdrawEndpoint = "/wapi/v3/withdraw.html"
|
||||
|
||||
@@ -328,22 +328,26 @@ type CancelOrderResponse struct {
|
||||
|
||||
// QueryOrderData holds query order data
|
||||
type QueryOrderData struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Symbol string `json:"symbol"`
|
||||
OrderID int64 `json:"orderId"`
|
||||
ClientOrderID string `json:"clientOrderId"`
|
||||
Price float64 `json:"price,string"`
|
||||
OrigQty float64 `json:"origQty,string"`
|
||||
ExecutedQty float64 `json:"executedQty,string"`
|
||||
Status string `json:"status"`
|
||||
TimeInForce string `json:"timeInForce"`
|
||||
Type string `json:"type"`
|
||||
Side string `json:"side"`
|
||||
StopPrice float64 `json:"stopPrice,string"`
|
||||
IcebergQty float64 `json:"icebergQty,string"`
|
||||
Time float64 `json:"time"`
|
||||
IsWorking bool `json:"isWorking"`
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Symbol string `json:"symbol"`
|
||||
OrderID int64 `json:"orderId"`
|
||||
ClientOrderID string `json:"clientOrderId"`
|
||||
Price float64 `json:"price,string"`
|
||||
OrigQty float64 `json:"origQty,string"`
|
||||
ExecutedQty float64 `json:"executedQty,string"`
|
||||
Status string `json:"status"`
|
||||
TimeInForce string `json:"timeInForce"`
|
||||
Type string `json:"type"`
|
||||
Side string `json:"side"`
|
||||
StopPrice float64 `json:"stopPrice,string"`
|
||||
IcebergQty float64 `json:"icebergQty,string"`
|
||||
Time float64 `json:"time"`
|
||||
IsWorking bool `json:"isWorking"`
|
||||
CummulativeQuoteQty float64 `json:"cummulativeQuoteQty,string"`
|
||||
OrderListID int64 `json:"orderListId"`
|
||||
OrigQuoteOrderQty float64 `json:"origQuoteOrderQty,string"`
|
||||
UpdateTime int64 `json:"updateTime"`
|
||||
}
|
||||
|
||||
// Balance holds query order data
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -513,9 +514,11 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
sideType = order.Sell.String()
|
||||
}
|
||||
|
||||
timeInForce := BinanceRequestParamsTimeGTC
|
||||
var requestParamsOrderType RequestParamsOrderType
|
||||
switch s.Type {
|
||||
case order.Market:
|
||||
timeInForce = ""
|
||||
requestParamsOrderType = BinanceRequestParamsOrderMarket
|
||||
case order.Limit:
|
||||
requestParamsOrderType = BinanceRequestParamsOrderLimit
|
||||
@@ -530,13 +533,14 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
Price: s.Price,
|
||||
Quantity: s.Amount,
|
||||
TradeType: requestParamsOrderType,
|
||||
TimeInForce: BinanceRequestParamsTimeGTC,
|
||||
TimeInForce: timeInForce,
|
||||
}
|
||||
|
||||
response, err := b.NewOrder(&orderRequest)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
if response.OrderID > 0 {
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderID, 10)
|
||||
}
|
||||
@@ -545,6 +549,15 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
}
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
|
||||
for i := range response.Fills {
|
||||
submitOrderResponse.Trades = append(submitOrderResponse.Trades, order.TradeHistory{
|
||||
Price: response.Fills[i].Price,
|
||||
Amount: response.Fills[i].Qty,
|
||||
Fee: response.Fills[i].Commission,
|
||||
FeeAsset: response.Fills[i].CommissionAsset,
|
||||
})
|
||||
}
|
||||
|
||||
return submitOrderResponse, nil
|
||||
}
|
||||
|
||||
@@ -598,10 +611,63 @@ func (b *Binance) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, err
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Binance) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (o order.Detail, err error) {
|
||||
if assetType == "" {
|
||||
assetType = asset.Spot
|
||||
}
|
||||
|
||||
formattedPair, err := b.FormatExchangeCurrency(pair, assetType)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
orderIDInt64, err := convert.Int64FromString(orderID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := b.QueryOrder(formattedPair.String(), "", orderIDInt64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
orderSide := order.Side(resp.Side)
|
||||
orderDate, err := convert.TimeFromUnixTimestampFloat(resp.Time)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
orderCloseDate, err := convert.TimeFromUnixTimestampFloat(float64(resp.UpdateTime))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
status, err := order.StringToOrderStatus(resp.Status)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
orderType := order.Limit
|
||||
if resp.Type == "MARKET" {
|
||||
orderType = order.Market
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
Amount: resp.OrigQty,
|
||||
Date: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp.OrderID, 10),
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Pair: formattedPair,
|
||||
Cost: resp.CummulativeQuoteQty,
|
||||
AssetType: assetType,
|
||||
CloseTime: orderCloseDate,
|
||||
Status: status,
|
||||
Price: resp.Price,
|
||||
ExecutedAmount: resp.ExecutedQty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
@@ -676,7 +742,10 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
for i := range resp {
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].Type))
|
||||
orderDate := time.Unix(0, int64(resp[i].Time)*int64(time.Millisecond))
|
||||
orderDate, err := convert.TimeFromUnixTimestampFloat(resp[i].Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pair, err := currency.NewPairFromString(resp[i].Symbol)
|
||||
if err != nil {
|
||||
@@ -730,7 +799,10 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
for i := range resp {
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].Type))
|
||||
orderDate := time.Unix(0, int64(resp[i].Time)*int64(time.Millisecond))
|
||||
orderDate, err := convert.TimeFromUnixTimestampFloat(resp[i].Time)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// New orders are covered in GetOpenOrders
|
||||
if resp[i].Status == "NEW" {
|
||||
continue
|
||||
|
||||
@@ -583,8 +583,8 @@ func (b *Bitfinex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, er
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -309,8 +309,8 @@ func (b *Bitflyer) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, er
|
||||
return order.CancelAllResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitflyer) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bitflyer) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -444,8 +444,8 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.Cancel
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bithumb) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bithumb) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -505,8 +505,8 @@ func (b *Bitmex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitmex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bitmex) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -442,8 +442,8 @@ func (b *Bitstamp) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, er
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitstamp) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bitstamp) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -448,8 +448,8 @@ func (b *Bittrex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, err
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bittrex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bittrex) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -502,8 +502,8 @@ func (b *BTCMarkets) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse,
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *BTCMarkets) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *BTCMarkets) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
o, err := b.FetchOrder(orderID)
|
||||
if err != nil {
|
||||
|
||||
@@ -541,8 +541,8 @@ func orderIntToType(i int) order.Type {
|
||||
return order.UnknownType
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *BTSE) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *BTSE) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
o, err := b.GetOrders("", orderID, "")
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
@@ -594,8 +594,7 @@ func (b *BTSE) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
"", orderID)
|
||||
if err != nil {
|
||||
return od,
|
||||
fmt.Errorf("unable to get order fills for orderID %s",
|
||||
orderID)
|
||||
fmt.Errorf("unable to get order fills for orderID %s", orderID)
|
||||
}
|
||||
|
||||
for i := range th {
|
||||
|
||||
@@ -515,8 +515,8 @@ func (c *CoinbasePro) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse,
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (c *CoinbasePro) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (c *CoinbasePro) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
genOrderDetail, errGo := c.GetOrder(orderID)
|
||||
if errGo != nil {
|
||||
return order.Detail{}, fmt.Errorf("error retrieving order %s : %s", orderID, errGo)
|
||||
|
||||
@@ -589,8 +589,8 @@ func (c *Coinbene) CancelAllOrders(orderCancellation *order.Cancel) (order.Cance
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (c *Coinbene) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (c *Coinbene) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
tempResp, err := c.FetchSpotOrderInfo(orderID)
|
||||
if err != nil {
|
||||
|
||||
@@ -718,8 +718,8 @@ func (c *COINUT) CancelAllOrders(details *order.Cancel) (order.CancelAllResponse
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (c *COINUT) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (c *COINUT) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
return order.Detail{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -444,8 +444,8 @@ func (e *EXMO) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error)
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (e *EXMO) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (e *EXMO) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -644,8 +644,8 @@ func (s *OrderData) GetCompatible(f *FTX) (OrderVars, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (f *FTX) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (f *FTX) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
orderData, err := f.GetOrderStatus(orderID)
|
||||
if err != nil {
|
||||
@@ -655,7 +655,7 @@ func (f *FTX) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
assetType, err := f.GetPairAssetType(p)
|
||||
orderAssetType, err := f.GetPairAssetType(p)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -666,7 +666,7 @@ func (f *FTX) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
resp.Exchange = f.Name
|
||||
resp.ExecutedAmount = orderData.Size - orderData.RemainingSize
|
||||
resp.Pair = p
|
||||
resp.AssetType = assetType
|
||||
resp.AssetType = orderAssetType
|
||||
resp.Price = orderData.Price
|
||||
resp.RemainingAmount = orderData.RemainingSize
|
||||
orderVars, err := orderData.GetCompatible(f)
|
||||
|
||||
@@ -477,7 +477,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
t.Skip("no API keys set skipping test")
|
||||
}
|
||||
|
||||
_, err := g.GetOrderInfo("917591554")
|
||||
_, err := g.GetOrderInfo("917591554", currency.Pair{}, asset.Spot)
|
||||
if err != nil {
|
||||
if err.Error() != "no order found with id 917591554" && err.Error() != "failed to get open orders" {
|
||||
t.Fatalf("GetOrderInfo() returned an error skipping test: %v", err)
|
||||
|
||||
@@ -508,15 +508,19 @@ func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (g *Gateio) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (g *Gateio) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
orders, err := g.GetOpenOrders("")
|
||||
if err != nil {
|
||||
return orderDetail, errors.New("failed to get open orders")
|
||||
}
|
||||
|
||||
format, err := g.GetPairFormat(asset.Spot, false)
|
||||
if assetType == "" {
|
||||
assetType = asset.Spot
|
||||
}
|
||||
|
||||
format, err := g.GetPairFormat(assetType, false)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
|
||||
@@ -385,8 +385,8 @@ func (g *Gemini) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (g *Gemini) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (g *Gemini) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -536,8 +536,8 @@ func (h *HitBTC) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (h *HitBTC) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (h *HitBTC) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -659,8 +659,8 @@ func (h *HUOBI) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAl
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (h *HUOBI) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (h *HUOBI) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
var respData *OrderInfo
|
||||
if h.Websocket.CanUseAuthenticatedWebsocketForWrapper() {
|
||||
@@ -685,7 +685,8 @@ func (h *HUOBI) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
}
|
||||
var responseID = strconv.FormatInt(respData.ID, 10)
|
||||
if responseID != orderID {
|
||||
return orderDetail, errors.New(h.Name + " - GetOrderInfo orderID mismatch. Expected: " + orderID + " Received: " + responseID)
|
||||
return orderDetail, errors.New(h.Name + " - GetOrderInfo orderID mismatch. Expected: " +
|
||||
orderID + " Received: " + responseID)
|
||||
}
|
||||
typeDetails := strings.Split(respData.Type, "-")
|
||||
orderSide, err := order.StringToOrderSide(typeDetails[0])
|
||||
|
||||
@@ -52,7 +52,7 @@ type IBotExchange interface {
|
||||
ModifyOrder(action *order.Modify) (string, error)
|
||||
CancelOrder(o *order.Cancel) error
|
||||
CancelAllOrders(orders *order.Cancel) (order.CancelAllResponse, error)
|
||||
GetOrderInfo(orderID string) (order.Detail, error)
|
||||
GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error)
|
||||
GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)
|
||||
GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
|
||||
@@ -400,8 +400,8 @@ func (i *ItBit) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAl
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (i *ItBit) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (i *ItBit) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
_, err := k.GetOrderInfo("OZPTPJ-HVYHF-EDIGXS")
|
||||
_, err := k.GetOrderInfo("OZPTPJ-HVYHF-EDIGXS", currency.Pair{}, asset.Spot)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting error")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package kraken
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -608,67 +609,75 @@ func (k *Kraken) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (k *Kraken) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (k *Kraken) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
var emptyOrderOptions OrderInfoOptions
|
||||
openOrders, err := k.GetOpenOrders(emptyOrderOptions)
|
||||
resp, err := k.QueryOrdersInfo(OrderInfoOptions{
|
||||
Trades: true,
|
||||
}, orderID)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
if orderInfo, ok := openOrders.Open[orderID]; ok {
|
||||
avail, err := k.GetAvailablePairs(asset.Spot)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
|
||||
fmt, err := k.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
orderInfo, ok := resp[orderID]
|
||||
if !ok {
|
||||
return orderDetail, fmt.Errorf("order %s not found in response", orderID)
|
||||
}
|
||||
|
||||
var trades []order.TradeHistory
|
||||
for i := range orderInfo.Trades {
|
||||
trades = append(trades, order.TradeHistory{
|
||||
TID: orderInfo.Trades[i],
|
||||
})
|
||||
}
|
||||
side, err := order.StringToOrderSide(orderInfo.Description.Type)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
status, err := order.StringToOrderStatus(orderInfo.Status)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
oType, err := order.StringToOrderType(orderInfo.Description.OrderType)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
if assetType == "" {
|
||||
assetType = asset.Spot
|
||||
}
|
||||
|
||||
p, err := currency.NewPairFromFormattedPairs(orderInfo.Description.Pair,
|
||||
avail,
|
||||
fmt)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
orderDetail = order.Detail{
|
||||
Exchange: k.Name,
|
||||
ID: orderID,
|
||||
Pair: p,
|
||||
Side: side,
|
||||
Type: oType,
|
||||
Date: convert.TimeFromUnixTimestampDecimal(orderInfo.OpenTime),
|
||||
Status: status,
|
||||
Price: orderInfo.Price,
|
||||
Amount: orderInfo.Volume,
|
||||
ExecutedAmount: orderInfo.VolumeExecuted,
|
||||
RemainingAmount: orderInfo.Volume - orderInfo.VolumeExecuted,
|
||||
Fee: orderInfo.Fee,
|
||||
Trades: trades,
|
||||
}
|
||||
} else {
|
||||
return orderDetail, errors.New(k.Name + " - Order ID not found: " + orderID)
|
||||
avail, err := k.GetAvailablePairs(assetType)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
|
||||
format, err := k.GetPairFormat(assetType, true)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
|
||||
var trades []order.TradeHistory
|
||||
for i := range orderInfo.Trades {
|
||||
trades = append(trades, order.TradeHistory{
|
||||
TID: orderInfo.Trades[i],
|
||||
})
|
||||
}
|
||||
side, err := order.StringToOrderSide(orderInfo.Description.Type)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
status, err := order.StringToOrderStatus(orderInfo.Status)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
oType, err := order.StringToOrderType(orderInfo.Description.OrderType)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
|
||||
p, err := currency.NewPairFromFormattedPairs(orderInfo.Description.Pair,
|
||||
avail,
|
||||
format)
|
||||
if err != nil {
|
||||
return orderDetail, err
|
||||
}
|
||||
orderDetail = order.Detail{
|
||||
Exchange: k.Name,
|
||||
ID: orderID,
|
||||
Pair: p,
|
||||
Side: side,
|
||||
Type: oType,
|
||||
Date: convert.TimeFromUnixTimestampDecimal(orderInfo.OpenTime),
|
||||
CloseTime: convert.TimeFromUnixTimestampDecimal(orderInfo.CloseTime),
|
||||
Status: status,
|
||||
Price: orderInfo.Price,
|
||||
Amount: orderInfo.Volume,
|
||||
ExecutedAmount: orderInfo.VolumeExecuted,
|
||||
RemainingAmount: orderInfo.Volume - orderInfo.VolumeExecuted,
|
||||
Fee: orderInfo.Fee,
|
||||
Trades: trades,
|
||||
}
|
||||
|
||||
return orderDetail, nil
|
||||
|
||||
@@ -399,8 +399,8 @@ func (l *LakeBTC) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, err
|
||||
return cancelAllOrdersResponse, l.CancelExistingOrders(ordersToCancel)
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *LakeBTC) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (l *LakeBTC) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := l.GetOrderInfo("9ead39f5-701a-400b-b635-d7349eb0f6b")
|
||||
_, err := l.GetOrderInfo("9ead39f5-701a-400b-b635-d7349eb0f6b", currency.Pair{}, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -445,8 +445,8 @@ func (l *Lbank) CancelAllOrders(o *order.Cancel) (order.CancelAllResponse, error
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *Lbank) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (l *Lbank) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
orderIDs, err := l.getAllOpenOrderID()
|
||||
if err != nil {
|
||||
|
||||
@@ -394,8 +394,8 @@ func (l *LocalBitcoins) CancelAllOrders(_ *order.Cancel) (order.CancelAllRespons
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (l *LocalBitcoins) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (l *LocalBitcoins) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -378,14 +378,18 @@ func (o *OKGroup) CancelAllOrders(orderCancellation *order.Cancel) (order.Cancel
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (o *OKGroup) GetOrderInfo(orderID string) (resp order.Detail, err error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (o *OKGroup) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (resp order.Detail, err error) {
|
||||
mOrder, err := o.GetSpotOrder(GetSpotOrderRequest{OrderID: orderID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
format, err := o.GetPairFormat(asset.Spot, false)
|
||||
if assetType == "" {
|
||||
assetType = asset.Spot
|
||||
}
|
||||
|
||||
format, err := o.GetPairFormat(assetType, false)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ type SubmitResponse struct {
|
||||
IsOrderPlaced bool
|
||||
FullyMatched bool
|
||||
OrderID string
|
||||
Rate float64
|
||||
Fee float64
|
||||
Cost float64
|
||||
Trades []TradeHistory
|
||||
}
|
||||
|
||||
// Modify contains all properties of an order
|
||||
@@ -124,6 +128,7 @@ type Detail struct {
|
||||
TargetAmount float64
|
||||
ExecutedAmount float64
|
||||
RemainingAmount float64
|
||||
Cost float64
|
||||
Fee float64
|
||||
Exchange string
|
||||
InternalOrderID string
|
||||
@@ -183,6 +188,7 @@ type TradeHistory struct {
|
||||
Side Side
|
||||
Timestamp time.Time
|
||||
IsMaker bool
|
||||
FeeAsset string
|
||||
}
|
||||
|
||||
// GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions
|
||||
@@ -191,9 +197,11 @@ type GetOrdersRequest struct {
|
||||
Side Side
|
||||
StartTicks time.Time
|
||||
EndTicks time.Time
|
||||
OrderID string
|
||||
// Currencies Empty array = all currencies. Some endpoints only support
|
||||
// singular currency enquiries
|
||||
Pairs []currency.Pair
|
||||
Pairs []currency.Pair
|
||||
AssetType asset.Item
|
||||
}
|
||||
|
||||
// Status defines order status types
|
||||
@@ -216,6 +224,7 @@ const (
|
||||
Hidden Status = "HIDDEN"
|
||||
UnknownStatus Status = "UNKNOWN"
|
||||
Open Status = "OPEN"
|
||||
Closed Status = "CLOSED"
|
||||
)
|
||||
|
||||
// Type enforces a standard for order types across the code base
|
||||
|
||||
@@ -662,8 +662,12 @@ func StringToOrderStatus(status string) (Status, error) {
|
||||
return PartiallyCancelled, nil
|
||||
case strings.EqualFold(status, Open.String()):
|
||||
return Open, nil
|
||||
case strings.EqualFold(status, Closed.String()):
|
||||
return Closed, nil
|
||||
case strings.EqualFold(status, Cancelled.String()):
|
||||
return Cancelled, nil
|
||||
case strings.EqualFold(status, "CANCELED"): // Kraken case
|
||||
return Cancelled, nil
|
||||
case strings.EqualFold(status, PendingCancel.String()),
|
||||
strings.EqualFold(status, "pending cancel"),
|
||||
strings.EqualFold(status, "pending cancellation"):
|
||||
|
||||
@@ -503,8 +503,8 @@ func (p *Poloniex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, er
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (p *Poloniex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (p *Poloniex) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestGetOpenOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.GetOrderInfo("6196974")
|
||||
_, err := y.GetOrderInfo("6196974", currency.Pair{}, asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetOrderInfo() Expected error")
|
||||
}
|
||||
|
||||
@@ -419,8 +419,8 @@ func (y *Yobit) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (y *Yobit) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (y *Yobit) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -540,8 +540,8 @@ func (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (z *ZB) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (z *ZB) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user