Currency package update (#247)

* Initial currency overhaul before service system implementation

* Remove redundant currency string in orderbook.Base
Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times
Add error handling for process orderbook

*  Remove redundant currency string in ticker.Price
 Unexport lastupdated field in ticker.Price
 Add error handling for process ticker function and fix tests

* Phase Two Update

* Update translations to use map type - thankyou to kempeng for spotting this

* Change pair method name from Display -> Format for better readability

* Fixes misspelling and tests

* Implement requested changes from GloriousCode

* Remove reduntant function and streamlined return in currency_translation.go

* Revert pair method naming conventions

* Change currency naming conventions

* Changed code type to exported Item type with underlying string to reduce complexity

* Added interim orderbook process method to orderbook.Base type

* Changed feebuilder struct field to currency.Pair

* Adds fall over system for backup fx providers

* deprecate function and children and fix linter issue with btcmarkets

* Fixed requested changes

* Fix bug and move mtx for rates

* Fixed after rebase oopsies

* Fix linter issues

* Fixes race conditions in testing functions

* Final phase coinmarketcap update

* fix linter issues

* Implement requested changes

* Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates

* Add a collection of tests to improve codecov

* After rebase oopsy fixes for btse

* Fix requested changes

* fix after rebase oopsies and add more efficient comparison checks within currency pair

* Fix linter issues
This commit is contained in:
Ryan O'Hara-Reid
2019-03-19 11:49:05 +11:00
committed by Adrian Gallagher
parent ed760e184e
commit 0990f9d118
189 changed files with 11982 additions and 8055 deletions

View File

@@ -13,7 +13,7 @@ import (
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -104,9 +104,9 @@ func (c *CoinbasePro) Setup(exch config.ExchangeConfig) {
c.RESTPollingDelay = exch.RESTPollingDelay
c.Verbose = exch.Verbose
c.Websocket.SetWsStatusAndConnection(exch.Websocket)
c.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
c.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
c.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
c.BaseCurrencies = exch.BaseCurrencies
c.AvailablePairs = exch.AvailablePairs
c.EnabledPairs = exch.EnabledPairs
if exch.UseSandbox {
c.APIUrl = coinbaseproSandboxAPIURL
}
@@ -798,7 +798,8 @@ func (c *CoinbasePro) SendHTTPRequest(path string, result interface{}) error {
// SendAuthenticatedHTTPRequest sends an authenticated HTTP reque
func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) (err error) {
if !c.AuthenticatedAPISupport {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, c.Name)
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
c.Name)
}
payload := []byte("")
@@ -824,7 +825,13 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
headers["CB-ACCESS-PASSPHRASE"] = c.ClientID
headers["Content-Type"] = "application/json"
return c.SendPayload(method, c.APIUrl+path, headers, bytes.NewBuffer(payload), result, true, c.Verbose)
return c.SendPayload(method,
c.APIUrl+path,
headers,
bytes.NewBuffer(payload),
result,
true,
c.Verbose)
}
// GetFee returns an estimate of fee based on type of transaction
@@ -836,11 +843,17 @@ func (c *CoinbasePro) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
if err != nil {
return 0, err
}
fee = c.calculateTradingFee(trailingVolume, feeBuilder.FirstCurrency, feeBuilder.Delimiter, feeBuilder.SecondCurrency, feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker)
fee = c.calculateTradingFee(trailingVolume,
feeBuilder.Pair.Base,
feeBuilder.Pair.Quote,
feeBuilder.Pair.Delimiter,
feeBuilder.PurchasePrice,
feeBuilder.Amount,
feeBuilder.IsMaker)
case exchange.InternationalBankWithdrawalFee:
fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem)
fee = getInternationalBankWithdrawalFee(feeBuilder.FiatCurrency)
case exchange.InternationalBankDepositFee:
fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem)
fee = getInternationalBankDepositFee(feeBuilder.FiatCurrency)
}
if fee < 0 {
@@ -850,10 +863,10 @@ func (c *CoinbasePro) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
return fee, nil
}
func (c *CoinbasePro) calculateTradingFee(trailingVolume []Volume, firstCurrency, delimiter, secondCurrency string, purchasePrice, amount float64, isMaker bool) float64 {
func (c *CoinbasePro) calculateTradingFee(trailingVolume []Volume, base, quote currency.Code, delimiter string, purchasePrice, amount float64, isMaker bool) float64 {
var fee float64
for _, i := range trailingVolume {
if strings.EqualFold(i.ProductID, firstCurrency+delimiter+secondCurrency) {
if strings.EqualFold(i.ProductID, base.String()+delimiter+quote.String()) {
switch {
case isMaker:
fee = 0
@@ -870,24 +883,24 @@ func (c *CoinbasePro) calculateTradingFee(trailingVolume []Volume, firstCurrency
return fee * amount * purchasePrice
}
func getInternationalBankWithdrawalFee(currency string) float64 {
func getInternationalBankWithdrawalFee(c currency.Code) float64 {
var fee float64
if currency == symbol.USD {
if c == currency.USD {
fee = 25
} else if currency == symbol.EUR {
} else if c == currency.EUR {
fee = 0.15
}
return fee
}
func getInternationalBankDepositFee(currency string) float64 {
func getInternationalBankDepositFee(c currency.Code) float64 {
var fee float64
if currency == symbol.USD {
if c == currency.USD {
fee = 10
} else if currency == symbol.EUR {
} else if c == currency.EUR {
fee = 0.15
}

View File

@@ -5,8 +5,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
)
@@ -224,13 +223,10 @@ func TestAuthRequests(t *testing.T) {
func setFeeBuilder() exchange.FeeBuilder {
return exchange.FeeBuilder{
Amount: 1,
Delimiter: "",
FeeType: exchange.CryptocurrencyTradeFee,
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.LTC,
IsMaker: false,
PurchasePrice: 1,
Amount: 1,
FeeType: exchange.CryptocurrencyTradeFee,
Pair: currency.NewPair(currency.BTC, currency.LTC),
PurchasePrice: 1,
}
}
@@ -292,7 +288,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.EUR
feeBuilder.FiatCurrency = currency.EUR
if resp, err := c.GetFee(feeBuilder); resp != float64(0.15) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -301,7 +297,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.USD
feeBuilder.FiatCurrency = currency.USD
if resp, err := c.GetFee(feeBuilder); resp != float64(25) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -318,7 +314,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0.003) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
@@ -330,7 +326,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0.003) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
@@ -342,7 +338,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0.003) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
@@ -354,7 +350,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0.002) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.002) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
}
@@ -366,7 +362,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0.001) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.001) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
}
@@ -378,7 +374,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, false); resp != float64(0) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
@@ -390,7 +386,7 @@ func TestCalculateTradingFee(t *testing.T) {
},
}
if resp := c.calculateTradingFee(volume, "btc", "_", "usd", 1, 1, true); resp != float64(0) {
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, true); resp != float64(0) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
}
@@ -412,8 +408,9 @@ func TestGetActiveOrders(t *testing.T) {
TestSetup(t)
var getOrdersRequest = exchange.GetOrdersRequest{
OrderType: exchange.AnyOrderType,
Currencies: []pair.CurrencyPair{pair.NewCurrencyPair(symbol.BTC, symbol.LTC)},
OrderType: exchange.AnyOrderType,
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
currency.LTC)},
}
_, err := c.GetActiveOrders(getOrdersRequest)
@@ -429,8 +426,9 @@ func TestGetOrderHistory(t *testing.T) {
TestSetup(t)
var getOrdersRequest = exchange.GetOrdersRequest{
OrderType: exchange.AnyOrderType,
Currencies: []pair.CurrencyPair{pair.NewCurrencyPair(symbol.BTC, symbol.LTC)},
OrderType: exchange.AnyOrderType,
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
currency.LTC)},
}
_, err := c.GetOrderHistory(getOrdersRequest)
@@ -459,10 +457,10 @@ func TestSubmitOrder(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var p = pair.CurrencyPair{
Delimiter: "-",
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.LTC,
var p = currency.Pair{
Delimiter: "-",
Base: currency.BTC,
Quote: currency.LTC,
}
response, err := c.SubmitOrder(p, exchange.BuyOrderSide, exchange.LimitOrderType, 1, 1, "clientId")
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
@@ -481,7 +479,7 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -508,7 +506,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -543,7 +541,7 @@ func TestWithdraw(t *testing.T) {
TestSetup(t)
var withdrawCryptoRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.LTC,
Currency: currency.LTC,
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
Description: "WITHDRAW IT ALL",
}
@@ -571,7 +569,7 @@ func TestWithdrawFiat(t *testing.T) {
var withdrawFiatRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.USD,
Currency: currency.USD,
BankName: "Federal Reserve Bank",
}
@@ -594,7 +592,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
var withdrawFiatRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.USD,
Currency: currency.USD,
BankName: "Federal Reserve Bank",
}
@@ -608,7 +606,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
}
func TestGetDepositAddress(t *testing.T) {
_, err := c.GetDepositAddress(symbol.BTC, "")
_, err := c.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error", err)
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -23,7 +23,7 @@ const (
// currencies
func (c *CoinbasePro) WebsocketSubscriber() error {
currencies := []string{}
for _, x := range c.EnabledPairs {
for _, x := range c.EnabledPairs.Strings() {
currency := x[0:3] + "-" + x[3:]
currencies = append(currencies, currency)
}
@@ -156,7 +156,7 @@ func (c *CoinbasePro) WsHandleData() {
c.Websocket.DataHandler <- exchange.TickerData{
Timestamp: time.Now(),
Pair: pair.NewCurrencyPairFromString(ticker.ProductID),
Pair: currency.NewPairFromString(ticker.ProductID),
AssetType: "SPOT",
Exchange: c.GetName(),
OpenPrice: ticker.Price,
@@ -230,12 +230,9 @@ func (c *CoinbasePro) ProcessSnapshot(snapshot WebsocketOrderbookSnapshot) error
orderbook.Item{Price: price, Amount: amount})
}
p := pair.NewCurrencyPairFromString(snapshot.ProductID)
pair := currency.NewPairFromString(snapshot.ProductID)
base.AssetType = "SPOT"
base.Pair = p
base.CurrencyPair = snapshot.ProductID
base.LastUpdated = time.Now()
base.Pair = pair
err := c.Websocket.Orderbook.LoadSnapshot(base, c.GetName(), false)
if err != nil {
@@ -243,7 +240,7 @@ func (c *CoinbasePro) ProcessSnapshot(snapshot WebsocketOrderbookSnapshot) error
}
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Pair: p,
Pair: pair,
Asset: "SPOT",
Exchange: c.GetName(),
}
@@ -270,7 +267,7 @@ func (c *CoinbasePro) ProcessUpdate(update WebsocketL2Update) error {
return errors.New("coibasepro_websocket.go error - no data in websocket update")
}
p := pair.NewCurrencyPairFromString(update.ProductID)
p := currency.NewPairFromString(update.ProductID)
err := c.Websocket.Orderbook.Update(Bids, Asks, p, time.Now(), c.GetName(), "SPOT")
if err != nil {

View File

@@ -8,7 +8,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -42,7 +42,14 @@ func (c *CoinbasePro) Run() {
currencies = append(currencies, x.ID[0:3]+x.ID[4:])
}
}
err = c.UpdateCurrencies(currencies, false, false)
var newCurrencies currency.Pairs
for _, p := range currencies {
newCurrencies = append(newCurrencies,
currency.NewPairFromString(p))
}
err = c.UpdateCurrencies(newCurrencies, false, false)
if err != nil {
log.Errorf("%s Failed to update available currencies.\n", c.GetName())
}
@@ -62,7 +69,7 @@ func (c *CoinbasePro) GetAccountInfo() (exchange.AccountInfo, error) {
var currencies []exchange.AccountCurrencyInfo
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = accountBalance[i].Currency
exchangeCurrency.CurrencyName = currency.NewCode(accountBalance[i].Currency)
exchangeCurrency.TotalValue = accountBalance[i].Available
exchangeCurrency.Hold = accountBalance[i].Hold
@@ -77,7 +84,7 @@ func (c *CoinbasePro) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (c *CoinbasePro) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (c *CoinbasePro) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := c.GetTicker(exchange.FormatExchangeCurrency(c.Name, p).String())
if err != nil {
@@ -95,12 +102,17 @@ func (c *CoinbasePro) UpdateTicker(p pair.CurrencyPair, assetType string) (ticke
tickerPrice.Last = tick.Price
tickerPrice.High = stats.High
tickerPrice.Low = stats.Low
ticker.ProcessTicker(c.GetName(), p, tickerPrice, assetType)
err = ticker.ProcessTicker(c.GetName(), tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
return ticker.GetTicker(c.Name, p, assetType)
}
// GetTickerPrice returns the ticker for a currency pair
func (c *CoinbasePro) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (c *CoinbasePro) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType)
if err != nil {
return c.UpdateTicker(p, assetType)
@@ -109,8 +121,8 @@ func (c *CoinbasePro) GetTickerPrice(p pair.CurrencyPair, assetType string) (tic
}
// GetOrderbookEx returns orderbook base on the currency pair
func (c *CoinbasePro) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.GetOrderbook(c.GetName(), p, assetType)
func (c *CoinbasePro) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.Get(c.GetName(), p, assetType)
if err != nil {
return c.UpdateOrderbook(p, assetType)
}
@@ -118,7 +130,7 @@ func (c *CoinbasePro) GetOrderbookEx(p pair.CurrencyPair, assetType string) (ord
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (c *CoinbasePro) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
func (c *CoinbasePro) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := c.GetOrderbook(exchange.FormatExchangeCurrency(c.Name, p).String(), 2)
if err != nil {
@@ -135,8 +147,16 @@ func (c *CoinbasePro) UpdateOrderbook(p pair.CurrencyPair, assetType string) (or
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: obNew.Asks[x].Amount, Price: obNew.Asks[x].Price})
}
orderbook.ProcessOrderbook(c.GetName(), p, orderBook, assetType)
return orderbook.GetOrderbook(c.Name, p, assetType)
orderBook.Pair = p
orderBook.ExchangeName = c.GetName()
orderBook.AssetType = assetType
err = orderBook.Process()
if err != nil {
return orderBook, err
}
return orderbook.Get(c.Name, p, assetType)
}
// GetFundingHistory returns funding history, deposits and
@@ -147,23 +167,36 @@ func (c *CoinbasePro) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (c *CoinbasePro) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
func (c *CoinbasePro) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
var resp []exchange.TradeHistory
return resp, common.ErrNotYetImplemented
}
// SubmitOrder submits a new order
func (c *CoinbasePro) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
func (c *CoinbasePro) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
var submitOrderResponse exchange.SubmitOrderResponse
var response string
var err error
switch orderType {
case exchange.MarketOrderType:
response, err = c.PlaceMarginOrder("", amount, amount, side.ToString(), p.Pair().String(), "")
response, err = c.PlaceMarginOrder("",
amount,
amount,
side.ToString(),
p.String(),
"")
case exchange.LimitOrderType:
response, err = c.PlaceLimitOrder("", price, amount, side.ToString(), "", "", p.Pair().String(), "", false)
response, err = c.PlaceLimitOrder("",
price,
amount,
side.ToString(),
"",
"",
p.String(),
"",
false)
default:
err = errors.New("order type not supported")
}
@@ -204,7 +237,7 @@ func (c *CoinbasePro) GetOrderInfo(orderID string) (exchange.OrderDetail, error)
}
// GetDepositAddress returns a deposit address for a specified currency
func (c *CoinbasePro) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
func (c *CoinbasePro) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error) {
return "", common.ErrFunctionNotSupported
}
@@ -262,7 +295,8 @@ func (c *CoinbasePro) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, err
func (c *CoinbasePro) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
var respOrders []GeneralizedOrderResponse
for _, currency := range getOrdersRequest.Currencies {
resp, err := c.GetOrders([]string{"open", "pending", "active"}, exchange.FormatExchangeCurrency(c.Name, currency).String())
resp, err := c.GetOrders([]string{"open", "pending", "active"},
exchange.FormatExchangeCurrency(c.Name, currency).String())
if err != nil {
return nil, err
}
@@ -271,7 +305,8 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest
var orders []exchange.OrderDetail
for _, order := range respOrders {
currency := pair.NewCurrencyPairDelimiter(order.ProductID, c.ConfigCurrencyPairFormat.Delimiter)
currency := currency.NewPairDelimiter(order.ProductID,
c.ConfigCurrencyPairFormat.Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(order.Side))
orderType := exchange.OrderType(strings.ToUpper(order.Type))
orderDate, err := time.Parse(time.RFC3339, order.CreatedAt)
@@ -304,7 +339,8 @@ func (c *CoinbasePro) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest
func (c *CoinbasePro) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
var respOrders []GeneralizedOrderResponse
for _, currency := range getOrdersRequest.Currencies {
resp, err := c.GetOrders([]string{"done", "settled"}, exchange.FormatExchangeCurrency(c.Name, currency).String())
resp, err := c.GetOrders([]string{"done", "settled"},
exchange.FormatExchangeCurrency(c.Name, currency).String())
if err != nil {
return nil, err
}
@@ -313,7 +349,8 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest
var orders []exchange.OrderDetail
for _, order := range respOrders {
currency := pair.NewCurrencyPairDelimiter(order.ProductID, c.ConfigCurrencyPairFormat.Delimiter)
currency := currency.NewPairDelimiter(order.ProductID,
c.ConfigCurrencyPairFormat.Delimiter)
orderSide := exchange.OrderSide(strings.ToUpper(order.Side))
orderType := exchange.OrderType(strings.ToUpper(order.Type))
orderDate, err := time.Parse(time.RFC3339, order.CreatedAt)
@@ -335,7 +372,8 @@ func (c *CoinbasePro) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest
}
exchange.FilterOrdersByType(&orders, getOrdersRequest.OrderType)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
getOrdersRequest.EndTicks)
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
return orders, nil