mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-21 07:26:48 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
)
|
||||
|
||||
// Please supply you own test keys here to run better tests.
|
||||
@@ -333,8 +334,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
Currencies: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
}
|
||||
@@ -353,8 +354,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -379,14 +380,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.LTC,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -409,7 +410,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -435,7 +436,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -451,13 +452,13 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := b.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package bittrex
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -12,6 +11,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"
|
||||
@@ -139,7 +139,10 @@ func (b *Bittrex) Run() {
|
||||
|
||||
err := b.UpdatePairs(currency.NewPairsFromStrings(enabledPairs), asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +152,10 @@ func (b *Bittrex) Run() {
|
||||
|
||||
err := b.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
b.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,30 +319,29 @@ func (b *Bittrex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]e
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bittrex) 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 (b *Bittrex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
buy := order.OrderSide == exchange.BuyOrderSide
|
||||
var response UUID
|
||||
var err error
|
||||
buy := s.OrderSide == order.Buy
|
||||
|
||||
if order.OrderType != exchange.LimitOrderType {
|
||||
return submitOrderResponse, errors.New("limit order not supported on exchange")
|
||||
if s.OrderType != order.Limit {
|
||||
return submitOrderResponse,
|
||||
errors.New("limit order not supported on exchange")
|
||||
}
|
||||
|
||||
var response UUID
|
||||
var err error
|
||||
if buy {
|
||||
response, err = b.PlaceBuyLimit(order.Pair.String(), order.Amount,
|
||||
order.Price)
|
||||
response, err = b.PlaceBuyLimit(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
} else {
|
||||
response, err = b.PlaceSellLimit(order.Pair.String(), order.Amount,
|
||||
order.Price)
|
||||
response, err = b.PlaceSellLimit(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price)
|
||||
}
|
||||
|
||||
if response.Result.ID != "" {
|
||||
@@ -352,21 +357,21 @@ func (b *Bittrex) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitO
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bittrex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bittrex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bittrex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bittrex) CancelOrder(order *order.Cancel) error {
|
||||
_, err := b.CancelExistingOrder(order.OrderID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (b *Bittrex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := b.GetOpenOrders("")
|
||||
if err != nil {
|
||||
@@ -376,7 +381,7 @@ func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
for i := range openOrders.Result {
|
||||
_, err := b.CancelExistingOrder(openOrders.Result[i].OrderUUID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[openOrders.Result[i].OrderUUID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[openOrders.Result[i].OrderUUID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,8 +389,8 @@ func (b *Bittrex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cance
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bittrex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bittrex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -403,7 +408,7 @@ func (b *Bittrex) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
// submitted
|
||||
func (b *Bittrex) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
|
||||
uuid, err := b.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.AddressTag, withdrawRequest.Address, withdrawRequest.Amount)
|
||||
return fmt.Sprintf("%v", uuid), err
|
||||
return uuid.Result.ID, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
@@ -434,10 +439,10 @@ func (b *Bittrex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bittrex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOpenOrders(currPair)
|
||||
@@ -445,19 +450,23 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].Opened)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Result[i].OrderUUID,
|
||||
resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Result[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp.Result[i].Quantity,
|
||||
RemainingAmount: resp.Result[i].QuantityRemaining,
|
||||
Price: resp.Result[i].Price,
|
||||
@@ -469,19 +478,18 @@ func (b *Bittrex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (b *Bittrex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var currPair string
|
||||
if len(getOrdersRequest.Currencies) == 1 {
|
||||
currPair = getOrdersRequest.Currencies[0].String()
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
|
||||
resp, err := b.GetOrderHistoryForCurrency(currPair)
|
||||
@@ -489,19 +497,23 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Result {
|
||||
orderDate, err := time.Parse(time.RFC3339, resp.Result[i].TimeStamp)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name, "GetActiveOrders", resp.Result[i].OrderUUID, resp.Result[i].Opened)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
b.Name,
|
||||
"GetActiveOrders",
|
||||
resp.Result[i].OrderUUID,
|
||||
resp.Result[i].Opened)
|
||||
}
|
||||
|
||||
pair := currency.NewPairDelimiter(resp.Result[i].Exchange,
|
||||
b.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Result[i].Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Result[i].Type))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp.Result[i].Quantity,
|
||||
RemainingAmount: resp.Result[i].QuantityRemaining,
|
||||
Price: resp.Result[i].Price,
|
||||
@@ -514,10 +526,9 @@ func (b *Bittrex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) (
|
||||
})
|
||||
}
|
||||
|
||||
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