mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +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"
|
||||
)
|
||||
@@ -154,7 +155,7 @@ func (k *Kraken) GetTicker(symbol string) (Ticker, error) {
|
||||
// GetTickers supports fetching multiple tickers from Kraken
|
||||
// pairList must be in the format pairs separated by commas
|
||||
// ("LTCUSD,ETCUSD")
|
||||
func (k *Kraken) GetTickers(pairList string) (Tickers, error) {
|
||||
func (k *Kraken) GetTickers(pairList string) (map[string]Ticker, error) {
|
||||
values := url.Values{}
|
||||
values.Set("pair", pairList)
|
||||
|
||||
@@ -175,7 +176,7 @@ func (k *Kraken) GetTickers(pairList string) (Tickers, error) {
|
||||
return nil, fmt.Errorf("%s error: %s", k.Name, resp.Error)
|
||||
}
|
||||
|
||||
tickers := make(Tickers)
|
||||
tickers := make(map[string]Ticker)
|
||||
|
||||
for i := range resp.Data {
|
||||
tick := Ticker{}
|
||||
@@ -763,7 +764,7 @@ func (k *Kraken) AddOrder(symbol, side, orderType string, volume, price, price2,
|
||||
"volume": {strconv.FormatFloat(volume, 'f', -1, 64)},
|
||||
}
|
||||
|
||||
if orderType == exchange.LimitOrderType.ToLower().ToString() || price > 0 {
|
||||
if orderType == order.Limit.Lower() || price > 0 {
|
||||
params.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,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"
|
||||
)
|
||||
@@ -244,7 +245,7 @@ func TestAddOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
args := AddOrderOptions{OrderFlags: "fcib"}
|
||||
_, err := k.AddOrder("XXBTZUSD",
|
||||
exchange.SellOrderSide.ToLower().ToString(), exchange.LimitOrderType.ToLower().ToString(),
|
||||
order.Sell.Lower(), order.Limit.Lower(),
|
||||
0.00000001, 0, 0, 0, &args)
|
||||
if err == nil {
|
||||
t.Error("AddOrder() Expected error")
|
||||
@@ -387,8 +388,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
k.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := k.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -404,8 +405,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
k.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
|
||||
_, err := k.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -431,13 +432,13 @@ 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{
|
||||
Base: currency.XBT,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
OrderSide: exchange.BuyOrderSide,
|
||||
OrderType: exchange.LimitOrderType,
|
||||
OrderSide: order.Buy,
|
||||
OrderType: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
@@ -461,7 +462,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",
|
||||
@@ -488,7 +489,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",
|
||||
@@ -504,8 +505,8 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +527,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
|
||||
// TestModifyOrder wrapper test
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
_, err := k.ModifyOrder(&exchange.ModifyOrder{})
|
||||
_, err := k.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package kraken
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -12,6 +13,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"
|
||||
@@ -203,7 +205,10 @@ func (k *Kraken) Run() {
|
||||
|
||||
err := k.UpdatePairs(enabledPairs, asset.Spot, true, true)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update currencies. Err: %s\n", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update currencies. Err: %s\n",
|
||||
k.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +218,10 @@ func (k *Kraken) Run() {
|
||||
|
||||
err := k.UpdateTradablePairs(forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", k.Name, err)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
k.Name,
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +246,10 @@ func (k *Kraken) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
if v.Quote[0] == 'Z' || v.Quote[0] == 'X' {
|
||||
v.Quote = v.Quote[1:]
|
||||
}
|
||||
products = append(products, fmt.Sprintf("%v%v%v", v.Base, k.GetPairFormat(asset, false).Delimiter, v.Quote))
|
||||
products = append(products, fmt.Sprintf("%v%v%v",
|
||||
v.Base,
|
||||
k.GetPairFormat(asset, false).Delimiter,
|
||||
v.Quote))
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
@@ -268,12 +279,11 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
|
||||
}
|
||||
|
||||
for i := range pairs {
|
||||
for curr, v := range tickers {
|
||||
for c, t := range tickers {
|
||||
pairFmt := k.FormatExchangeCurrency(pairs[i], assetType).String()
|
||||
if !strings.EqualFold(pairFmt, curr) {
|
||||
var altCurrency string
|
||||
var ok bool
|
||||
if altCurrency, ok = assetPairMap[curr]; !ok {
|
||||
if !strings.EqualFold(pairFmt, c) {
|
||||
altCurrency, ok := assetPairMap[c]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(pairFmt, altCurrency) {
|
||||
@@ -282,13 +292,13 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pri
|
||||
}
|
||||
|
||||
tickerPrice = ticker.Price{
|
||||
Last: v.Last,
|
||||
High: v.High,
|
||||
Low: v.Low,
|
||||
Bid: v.Bid,
|
||||
Ask: v.Ask,
|
||||
Volume: v.Volume,
|
||||
Open: v.Open,
|
||||
Last: t.Last,
|
||||
High: t.High,
|
||||
Low: t.Low,
|
||||
Bid: t.Bid,
|
||||
Ask: t.Ask,
|
||||
Volume: t.Volume,
|
||||
Open: t.Open,
|
||||
Pair: pairs[i],
|
||||
}
|
||||
err = ticker.ProcessTicker(k.Name, &tickerPrice, assetType)
|
||||
@@ -359,10 +369,10 @@ func (k *Kraken) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
var balances []exchange.AccountCurrencyInfo
|
||||
for key, data := range bal {
|
||||
for key := range bal {
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(key),
|
||||
TotalValue: data,
|
||||
TotalValue: bal[key],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -386,25 +396,20 @@ func (k *Kraken) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]ex
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (k *Kraken) 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 (k *Kraken) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
|
||||
var args = AddOrderOptions{}
|
||||
response, err := k.AddOrder(order.Pair.String(),
|
||||
order.OrderSide.ToString(),
|
||||
order.OrderType.ToString(),
|
||||
order.Amount,
|
||||
order.Price,
|
||||
response, err := k.AddOrder(s.Pair.String(),
|
||||
s.OrderSide.String(),
|
||||
s.OrderType.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
0,
|
||||
0,
|
||||
&args)
|
||||
&AddOrderOptions{})
|
||||
if len(response.TransactionIds) > 0 {
|
||||
submitOrderResponse.OrderID = strings.Join(response.TransactionIds, ", ")
|
||||
}
|
||||
@@ -416,21 +421,21 @@ func (k *Kraken) SubmitOrder(order *exchange.OrderSubmission) (exchange.SubmitOr
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (k *Kraken) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
|
||||
func (k *Kraken) ModifyOrder(action *order.Modify) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (k *Kraken) CancelOrder(order *exchange.OrderCancellation) error {
|
||||
func (k *Kraken) CancelOrder(order *order.Cancel) error {
|
||||
_, err := k.CancelExistingOrder(order.OrderID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
func (k *Kraken) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
var emptyOrderOptions OrderInfoOptions
|
||||
openOrders, err := k.GetOpenOrders(emptyOrderOptions)
|
||||
@@ -441,7 +446,7 @@ func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
for orderID := range openOrders.Open {
|
||||
_, err = k.CancelExistingOrder(orderID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[orderID] = err.Error()
|
||||
cancelAllOrdersResponse.Status[orderID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,8 +454,8 @@ func (k *Kraken) CancelAllOrders(_ *exchange.OrderCancellation) (exchange.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (k *Kraken) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
var orderDetail exchange.OrderDetail
|
||||
func (k *Kraken) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
@@ -506,20 +511,20 @@ func (k *Kraken) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (k *Kraken) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (k *Kraken) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
resp, err := k.GetOpenOrders(OrderInfoOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Open {
|
||||
symbol := currency.NewPairFromString(resp.Open[i].Description.Pair)
|
||||
orderDate := time.Unix(int64(resp.Open[i].StartTime), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(resp.Open[i].Description.Type))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Open[i].Description.OrderType))
|
||||
side := order.Side(strings.ToUpper(resp.Open[i].Description.Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Open[i].Description.OrderType))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: i,
|
||||
Amount: resp.Open[i].Volume,
|
||||
RemainingAmount: (resp.Open[i].Volume - resp.Open[i].VolumeExecuted),
|
||||
@@ -533,22 +538,21 @@ func (k *Kraken) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, req.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
|
||||
func (k *Kraken) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
req := GetClosedOrdersOptions{}
|
||||
if getOrdersRequest.StartTicks.Unix() > 0 {
|
||||
req.Start = fmt.Sprintf("%v", getOrdersRequest.StartTicks.Unix())
|
||||
req.Start = strconv.FormatInt(getOrdersRequest.StartTicks.Unix(), 10)
|
||||
}
|
||||
if getOrdersRequest.EndTicks.Unix() > 0 {
|
||||
req.End = fmt.Sprintf("%v", getOrdersRequest.EndTicks.Unix())
|
||||
req.End = strconv.FormatInt(getOrdersRequest.EndTicks.Unix(), 10)
|
||||
}
|
||||
|
||||
resp, err := k.GetClosedOrders(req)
|
||||
@@ -556,14 +560,14 @@ func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []exchange.OrderDetail
|
||||
var orders []order.Detail
|
||||
for i := range resp.Closed {
|
||||
symbol := currency.NewPairFromString(resp.Closed[i].Description.Pair)
|
||||
orderDate := time.Unix(int64(resp.Closed[i].StartTime), 0)
|
||||
side := exchange.OrderSide(strings.ToUpper(resp.Closed[i].Description.Type))
|
||||
orderType := exchange.OrderType(strings.ToUpper(resp.Closed[i].Description.OrderType))
|
||||
side := order.Side(strings.ToUpper(resp.Closed[i].Description.Type))
|
||||
orderType := order.Type(strings.ToUpper(resp.Closed[i].Description.OrderType))
|
||||
|
||||
orders = append(orders, exchange.OrderDetail{
|
||||
orders = append(orders, order.Detail{
|
||||
ID: i,
|
||||
Amount: resp.Closed[i].Volume,
|
||||
RemainingAmount: (resp.Closed[i].Volume - resp.Closed[i].VolumeExecuted),
|
||||
@@ -577,8 +581,8 @@ func (k *Kraken) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([
|
||||
})
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
order.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
order.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user