mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-28 15:10:32 +00:00
committed by
Adrian Gallagher
parent
242b02c382
commit
63a9e9fcb1
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
)
|
||||
@@ -362,10 +363,10 @@ func (b *Bitfinex) GetTradesV2(currencyPair string, timestampStart, timestampEnd
|
||||
tempHistory.Amount = data[2].(float64)
|
||||
tempHistory.Price = data[3].(float64)
|
||||
tempHistory.Exchange = b.Name
|
||||
tempHistory.Type = exchange.BuyOrderSide.ToString()
|
||||
tempHistory.Type = order.Buy.String()
|
||||
|
||||
if tempHistory.Amount < 0 {
|
||||
tempHistory.Type = exchange.SellOrderSide.ToString()
|
||||
tempHistory.Type = order.Sell.String()
|
||||
tempHistory.Amount *= -1
|
||||
}
|
||||
|
||||
@@ -582,9 +583,9 @@ func (b *Bitfinex) NewOrder(currencyPair string, amount, price float64, buy bool
|
||||
req["is_hidden"] = hidden
|
||||
|
||||
if buy {
|
||||
req["side"] = exchange.BuyOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Buy.Lower()
|
||||
} else {
|
||||
req["side"] = exchange.SellOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Sell.Lower()
|
||||
}
|
||||
|
||||
return response,
|
||||
@@ -657,9 +658,9 @@ func (b *Bitfinex) ReplaceOrder(orderID int64, symbol string, amount, price floa
|
||||
req["is_hidden"] = hidden
|
||||
|
||||
if buy {
|
||||
req["side"] = exchange.BuyOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Buy.Lower()
|
||||
} else {
|
||||
req["side"] = exchange.SellOrderSide.ToLower().ToString()
|
||||
req["side"] = order.Sell.Lower()
|
||||
}
|
||||
|
||||
return response,
|
||||
|
||||
@@ -12,6 +12,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"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
)
|
||||
@@ -365,8 +366,12 @@ func TestNewOrder(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.NewOrder("BTCUSD", 1, 2, true,
|
||||
exchange.LimitOrderType.ToLower().ToString(), false)
|
||||
_, err := b.NewOrder("BTCUSD",
|
||||
1,
|
||||
2,
|
||||
true,
|
||||
order.Limit.Lower(),
|
||||
false)
|
||||
if err == nil {
|
||||
t.Error("NewOrder() Expected error")
|
||||
}
|
||||
@@ -384,8 +389,8 @@ func TestNewOrderMulti(t *testing.T) {
|
||||
Amount: 1,
|
||||
Price: 1,
|
||||
Exchange: "bitfinex",
|
||||
Side: exchange.BuyOrderSide.ToLower().ToString(),
|
||||
Type: exchange.LimitOrderType.ToLower().ToString(),
|
||||
Side: order.Buy.Lower(),
|
||||
Type: order.Limit.Lower(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -438,7 +443,7 @@ func TestReplaceOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.ReplaceOrder(1337, "BTCUSD",
|
||||
1, 1, true, exchange.LimitOrderType.ToLower().ToString(), false)
|
||||
1, 1, true, order.Limit.Lower(), false)
|
||||
if err == nil {
|
||||
t.Error("ReplaceOrder() Expected error")
|
||||
}
|
||||
@@ -748,8 +753,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -764,8 +769,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)
|
||||
@@ -789,14 +794,14 @@ func TestSubmitOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
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.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -819,7 +824,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",
|
||||
@@ -845,7 +850,7 @@ func TestCancelAllExchangeOrdera(t *testing.T) {
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
@@ -861,13 +866,13 @@ func TestCancelAllExchangeOrdera(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")
|
||||
}
|
||||
|
||||
@@ -14,6 +14,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"
|
||||
@@ -189,7 +190,9 @@ func (b *Bitfinex) Start(wg *sync.WaitGroup) {
|
||||
func (b *Bitfinex) Run() {
|
||||
if b.Verbose {
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
"%s Websocket: %s.",
|
||||
b.GetName(),
|
||||
common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -326,14 +329,14 @@ func (b *Bitfinex) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
{ID: "trading"},
|
||||
}
|
||||
|
||||
for _, bal := range accountBalance {
|
||||
for x := range accountBalance {
|
||||
for i := range Accounts {
|
||||
if Accounts[i].ID == bal.Type {
|
||||
if Accounts[i].ID == accountBalance[x].Type {
|
||||
Accounts[i].Currencies = append(Accounts[i].Currencies,
|
||||
exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(bal.Currency),
|
||||
TotalValue: bal.Amount,
|
||||
Hold: bal.Amount - bal.Available,
|
||||
CurrencyName: currency.NewCode(accountBalance[x].Currency),
|
||||
TotalValue: accountBalance[x].Amount,
|
||||
Hold: accountBalance[x].Amount - accountBalance[x].Available,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -356,30 +359,26 @@ func (b *Bitfinex) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitfinex) 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 *Bitfinex) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var isBuying bool
|
||||
if order.OrderSide == exchange.BuyOrderSide {
|
||||
if s.OrderSide == order.Buy {
|
||||
isBuying = true
|
||||
}
|
||||
b.appendOptionalDelimiter(&order.Pair)
|
||||
response, err := b.NewOrder(order.Pair.String(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
b.appendOptionalDelimiter(&s.Pair)
|
||||
response, err := b.NewOrder(s.Pair.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
isBuying,
|
||||
order.OrderType.ToString(),
|
||||
s.OrderType.String(),
|
||||
false)
|
||||
|
||||
if response.OrderID > 0 {
|
||||
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderID)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderID, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -391,31 +390,29 @@ func (b *Bitfinex) SubmitOrder(order *exchange.OrderSubmission) (exchange.Submit
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitfinex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (b *Bitfinex) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitfinex) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (b *Bitfinex) CancelOrder(order *order.Cancel) error {
|
||||
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = b.CancelExistingOrder(orderIDInt)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitfinex) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
func (b *Bitfinex) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
_, err := b.CancelAllExistingOrders()
|
||||
return exchange.CancelAllOrdersResponse{}, err
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (b *Bitfinex) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -454,7 +451,7 @@ func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoW
|
||||
return "", errors.New("no withdrawID returned. Check order status")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v", resp[0].WithdrawalID), err
|
||||
return strconv.FormatInt(resp[0].WithdrawalID, 10), err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
@@ -511,26 +508,28 @@ func (b *Bitfinex) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bitfinex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitfinex) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetOpenOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
log.Warnf(log.ExchangeSys,
|
||||
"Unable to convert timestamp '%s', leaving blank",
|
||||
resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].OriginalAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
Price: resp[i].Price,
|
||||
RemainingAmount: resp[i].RemainingAmount,
|
||||
@@ -540,56 +539,56 @@ func (b *Bitfinex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
|
||||
switch {
|
||||
case resp[i].IsLive:
|
||||
orderDetail.Status = string(exchange.ActiveOrderStatus)
|
||||
orderDetail.Status = order.Active
|
||||
case resp[i].IsCancelled:
|
||||
orderDetail.Status = string(exchange.CancelledOrderStatus)
|
||||
orderDetail.Status = order.Cancelled
|
||||
case resp[i].IsHidden:
|
||||
orderDetail.Status = string(exchange.HiddenOrderStatus)
|
||||
orderDetail.Status = order.Hidden
|
||||
default:
|
||||
orderDetail.Status = string(exchange.UnknownOrderStatus)
|
||||
orderDetail.Status = order.UnknownStatus
|
||||
}
|
||||
|
||||
// API docs discrepency. Example contains prefixed "exchange "
|
||||
// Return type suggests “market” / “limit” / “stop” / “trailing-stop”
|
||||
orderType := strings.Replace(resp[i].Type, "exchange ", "", 1)
|
||||
if orderType == "trailing-stop" {
|
||||
orderDetail.OrderType = exchange.TrailingStopOrderType
|
||||
orderDetail.OrderType = order.TrailingStop
|
||||
} else {
|
||||
orderDetail.OrderType = exchange.OrderType(strings.ToUpper(orderType))
|
||||
orderDetail.OrderType = order.Type(strings.ToUpper(orderType))
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
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 *Bitfinex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
var orders []exchange.OrderDetail
|
||||
func (b *Bitfinex) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
resp, err := b.GetInactiveOrders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := exchange.OrderSide(strings.ToUpper(resp[i].Side))
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
|
||||
}
|
||||
orderDate := time.Unix(timestamp, 0)
|
||||
|
||||
orderDetail := exchange.OrderDetail{
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp[i].OriginalAmount,
|
||||
OrderDate: orderDate,
|
||||
Exchange: b.Name,
|
||||
ID: fmt.Sprintf("%v", resp[i].OrderID),
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
OrderSide: orderSide,
|
||||
Price: resp[i].Price,
|
||||
RemainingAmount: resp[i].RemainingAmount,
|
||||
@@ -599,34 +598,34 @@ func (b *Bitfinex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
|
||||
|
||||
switch {
|
||||
case resp[i].IsLive:
|
||||
orderDetail.Status = string(exchange.ActiveOrderStatus)
|
||||
orderDetail.Status = order.Active
|
||||
case resp[i].IsCancelled:
|
||||
orderDetail.Status = string(exchange.CancelledOrderStatus)
|
||||
orderDetail.Status = order.Cancelled
|
||||
case resp[i].IsHidden:
|
||||
orderDetail.Status = string(exchange.HiddenOrderStatus)
|
||||
orderDetail.Status = order.Hidden
|
||||
default:
|
||||
orderDetail.Status = string(exchange.UnknownOrderStatus)
|
||||
orderDetail.Status = order.UnknownStatus
|
||||
}
|
||||
|
||||
// API docs discrepency. Example contains prefixed "exchange "
|
||||
// Return type suggests “market” / “limit” / “stop” / “trailing-stop”
|
||||
orderType := strings.Replace(resp[i].Type, "exchange ", "", 1)
|
||||
if orderType == "trailing-stop" {
|
||||
orderDetail.OrderType = exchange.TrailingStopOrderType
|
||||
orderDetail.OrderType = order.TrailingStop
|
||||
} else {
|
||||
orderDetail.OrderType = exchange.OrderType(strings.ToUpper(orderType))
|
||||
orderDetail.OrderType = order.Type(strings.ToUpper(orderType))
|
||||
}
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
for i := range getOrdersRequest.Currencies {
|
||||
b.appendOptionalDelimiter(&getOrdersRequest.Currencies[i])
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByType(&orders, req.OrderType)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
for i := range req.Currencies {
|
||||
b.appendOptionalDelimiter(&req.Currencies[i])
|
||||
}
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user