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:
Vazha
2020-10-22 03:54:24 +03:00
committed by GitHub
parent 4ccb495baf
commit fab9d934fe
54 changed files with 2365 additions and 2151 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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