mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -180,8 +181,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -197,8 +198,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := a.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -225,14 +226,14 @@ func TestSubmitOrder(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderSubmission = &exchange.OrderSubmission{
|
||||
var orderSubmission = &order.Submit{
|
||||
Pair: currency.Pair{
|
||||
Delimiter: "_",
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.MarketOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Market,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -254,7 +255,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -280,7 +281,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -297,8 +298,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("QA pass needs to be completed and mock needs to be updated error cannot be nil")
|
||||
}
|
||||
|
||||
if len(resp.OrderStatus) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
|
||||
if len(resp.Status) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.Status))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +318,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := a.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := a.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
@@ -319,33 +320,29 @@ func (a *ANX) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]excha
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (a *ANX) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
if order == nil {
|
||||
return submitOrderResponse, exchange.ErrOrderSubmissionIsNil
|
||||
}
|
||||
|
||||
if err := order.Validate(); err != nil {
|
||||
func (a *ANX) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var isBuying bool
|
||||
var limitPriceInSettlementCurrency float64
|
||||
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
isBuying = true
|
||||
}
|
||||
|
||||
if order.OrderType == exchange.LimitOrderType {
|
||||
limitPriceInSettlementCurrency = order.Price
|
||||
if s.OrderType == order.Limit {
|
||||
limitPriceInSettlementCurrency = s.Price
|
||||
}
|
||||
|
||||
response, err := a.NewOrder(order.OrderType.ToString(),
|
||||
response, err := a.NewOrder(s.OrderType.String(),
|
||||
isBuying,
|
||||
order.Pair.Base.String(),
|
||||
order.Amount,
|
||||
order.Pair.Quote.String(),
|
||||
order.Amount,
|
||||
s.Pair.Base.String(),
|
||||
s.Amount,
|
||||
s.Pair.Quote.String(),
|
||||
s.Amount,
|
||||
limitPriceInSettlementCurrency,
|
||||
false,
|
||||
"",
|
||||
@@ -364,21 +361,21 @@ func (a *ANX) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOrder
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (a *ANX) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (a *ANX) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (a *ANX) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (a *ANX) CancelOrder(order *order.Cancel) error {
|
||||
orderIDs := []string{order.OrderID}
|
||||
_, err := a.CancelOrderByIDs(orderIDs)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (a *ANX) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
placedOrders, err := a.GetOrderList(true)
|
||||
if err != nil {
|
||||
@@ -397,7 +394,7 @@ func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAll
|
||||
|
||||
for _, order := range resp.OrderCancellationResponses {
|
||||
if order.Error != CancelRequestSubmitted {
|
||||
cancelAllOrdersResponse.OrderStatus[order.UUID] = order.Error
|
||||
cancelAllOrdersResponse.Status[order.UUID] = order.Error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,8 +402,8 @@ func (a *ANX) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAll
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (a *ANX) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (a *ANX) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -450,18 +447,18 @@ func (a *ANX) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *ANX) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrderList(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
orderDate := time.Unix(resp[i].Timestamp, 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].OrderType))
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].TradedCurrencyAmount,
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
|
||||
resp[i].SettlementCurrency,
|
||||
@@ -471,40 +468,40 @@ func (a *ANX) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
|
||||
ID: resp[i].OrderID,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].SettlementCurrencyAmount,
|
||||
Status: resp[i].OrderStatus,
|
||||
Status: order.Status(resp[i].OrderStatus),
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
order.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (a *ANX) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := a.GetOrderList(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp {
|
||||
orderDate := time.Unix(resp[i].Timestamp, 0)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp[i].OrderType))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].OrderType))
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].TradedCurrencyAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: a.Name,
|
||||
ID: resp[i].OrderID,
|
||||
OrderType: orderType,
|
||||
Price: resp[i].SettlementCurrencyAmount,
|
||||
Status: resp[i].OrderStatus,
|
||||
Status: order.Status(resp[i].OrderStatus),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(resp[i].TradedCurrency,
|
||||
resp[i].SettlementCurrency,
|
||||
a.GetPairFormat(asset.Spot, false).Delimiter),
|
||||
@@ -513,10 +510,9 @@ func (a *ANX) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]ex
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user