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/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 (b *Bitstamp) Setup(exch config.ExchangeConfig) {
b.RESTPollingDelay = exch.RESTPollingDelay
b.Verbose = exch.Verbose
b.Websocket.SetWsStatusAndConnection(exch.Websocket)
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
b.BaseCurrencies = exch.BaseCurrencies
b.AvailablePairs = exch.AvailablePairs
b.EnabledPairs = exch.EnabledPairs
b.APIKey = exch.APIKey
b.APISecret = exch.APISecret
b.SetAPIKeys(exch.APIKey, exch.APISecret, b.ClientID, false)
@@ -154,7 +154,10 @@ func (b *Bitstamp) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
if err != nil {
return 0, err
}
fee = b.CalculateTradingFee(feeBuilder.FirstCurrency+feeBuilder.SecondCurrency, feeBuilder.PurchasePrice, feeBuilder.Amount)
fee = b.CalculateTradingFee(feeBuilder.Pair.Base,
feeBuilder.Pair.Quote,
feeBuilder.PurchasePrice,
feeBuilder.Amount)
case exchange.CyptocurrencyDepositFee:
fee = 0
case exchange.InternationalBankDepositFee:
@@ -192,19 +195,19 @@ func getInternationalBankDepositFee(amount float64) float64 {
}
// CalculateTradingFee returns fee on a currency pair
func (b *Bitstamp) CalculateTradingFee(currency string, purchasePrice, amount float64) float64 {
func (b *Bitstamp) CalculateTradingFee(base, quote currency.Code, purchasePrice, amount float64) float64 {
var fee float64
switch currency {
case symbol.BTC + symbol.USD:
switch base.String() + quote.String() {
case currency.BTC.String() + currency.USD.String():
fee = b.Balance.BTCUSDFee
case symbol.BTC + symbol.EUR:
case currency.BTC.String() + currency.EUR.String():
fee = b.Balance.BTCEURFee
case symbol.XRP + symbol.EUR:
case currency.XRP.String() + currency.EUR.String():
fee = b.Balance.XRPEURFee
case symbol.XRP + symbol.USD:
case currency.XRP.String() + currency.USD.String():
fee = b.Balance.XRPUSDFee
case symbol.EUR + symbol.USD:
case currency.EUR.String() + currency.USD.String():
fee = b.Balance.EURUSDFee
default:
fee = 0
@@ -572,27 +575,27 @@ func (b *Bitstamp) OpenInternationalBankWithdrawal(amount float64, currency,
// GetCryptoDepositAddress returns a depositing address by crypto
// crypto - example "btc", "ltc", "eth", "xrp" or "bch"
func (b *Bitstamp) GetCryptoDepositAddress(crypto string) (string, error) {
func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error) {
var resp string
switch crypto {
case symbol.BTC:
case currency.BTC:
return resp,
b.SendAuthenticatedHTTPRequest(bitstampAPIBitcoinDeposit, false, nil, &resp)
case symbol.LTC:
case currency.LTC:
return resp,
b.SendAuthenticatedHTTPRequest(bitstampAPILitecoinDeposit, true, nil, &resp)
case symbol.ETH:
case currency.ETH:
return resp,
b.SendAuthenticatedHTTPRequest(bitstampAPIEthereumDeposit, true, nil, &resp)
case symbol.XRP:
case currency.XRP:
return resp,
b.SendAuthenticatedHTTPRequest(bitstampAPIXrpDeposit, true, nil, &resp)
case symbol.BCH:
case currency.BCH:
return resp,
b.SendAuthenticatedHTTPRequest(bitstampAPIBitcoinCashDeposit, true, nil, &resp)

View File

@@ -6,8 +6,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"
)
@@ -64,13 +63,10 @@ func TestSetup(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,
}
}
@@ -130,7 +126,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.HKD
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(7.5) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(7.5), resp)
t.Error(err)
@@ -139,7 +135,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.HKD
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(15) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(15), resp)
t.Error(err)
@@ -153,27 +149,29 @@ func TestCalculateTradingFee(t *testing.T) {
b.Balance.BTCUSDFee = 1
b.Balance.BTCEURFee = 0
if resp := b.CalculateTradingFee(symbol.BTC+symbol.USD, 0, 0); resp != 0 {
if resp := b.CalculateTradingFee(currency.BTC, currency.USD, 0, 0); resp != 0 {
t.Error("Test Failed - GetFee() error")
}
if resp := b.CalculateTradingFee(symbol.BTC+symbol.USD, 2, 2); resp != float64(4) {
if resp := b.CalculateTradingFee(currency.BTC, currency.USD, 2, 2); resp != float64(4) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(4), resp)
}
if resp := b.CalculateTradingFee(symbol.BTC+symbol.EUR, 2, 2); resp != float64(0) {
if resp := b.CalculateTradingFee(currency.BTC, currency.EUR, 2, 2); resp != float64(0) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
if resp := b.CalculateTradingFee("bla", 0, 0); resp != 0 {
dummy1, dummy2 := currency.NewCode(""), currency.NewCode("")
if resp := b.CalculateTradingFee(dummy1, dummy2, 0, 0); resp != 0 {
t.Error("Test Failed - GetFee() error")
}
}
func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := b.GetTicker(symbol.BTC+symbol.USD, false)
_, err := b.GetTicker(currency.BTC.String()+currency.USD.String(), false)
if err != nil {
t.Error("Test Failed - GetTicker() error", err)
}
_, err = b.GetTicker(symbol.BTC+symbol.USD, true)
_, err = b.GetTicker(currency.BTC.String()+currency.USD.String(), true)
if err != nil {
t.Error("Test Failed - GetTicker() error", err)
}
@@ -181,7 +179,7 @@ func TestGetTicker(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := b.GetOrderbook(symbol.BTC + symbol.USD)
_, err := b.GetOrderbook(currency.BTC.String() + currency.USD.String())
if err != nil {
t.Error("Test Failed - GetOrderbook() error", err)
}
@@ -200,7 +198,7 @@ func TestGetTransactions(t *testing.T) {
value := url.Values{}
value.Set("time", "hour")
_, err := b.GetTransactions(symbol.BTC+symbol.USD, value)
_, err := b.GetTransactions(currency.BTC.String()+currency.USD.String(), value)
if err != nil {
t.Error("Test Failed - GetTransactions() error", err)
}
@@ -325,7 +323,7 @@ func TestCryptoWithdrawal(t *testing.T) {
func TestGetBitcoinDepositAddress(t *testing.T) {
t.Parallel()
_, err := b.GetCryptoDepositAddress("btc")
_, err := b.GetCryptoDepositAddress(currency.BTC)
if err == nil {
t.Error("Test Failed - GetCryptoDepositAddress() error", err)
}
@@ -418,10 +416,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.USD,
var p = currency.Pair{
Delimiter: "",
Base: currency.BTC,
Quote: currency.USD,
}
response, err := b.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 1, "clientId")
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
@@ -439,7 +437,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",
@@ -465,7 +463,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",
@@ -500,7 +498,7 @@ func TestWithdraw(t *testing.T) {
TestSetup(t)
var withdrawCryptoRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.BTC,
Currency: currency.BTC,
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
Description: "WITHDRAW IT ALL",
}
@@ -528,7 +526,7 @@ func TestWithdrawFiat(t *testing.T) {
var withdrawFiatRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.USD,
Currency: currency.USD,
Description: "WITHDRAW IT ALL",
BankAccountName: "Satoshi Nakamoto",
BankAccountNumber: 12345,
@@ -536,7 +534,7 @@ func TestWithdrawFiat(t *testing.T) {
BankCity: "Tarry Town",
BankCountry: "AU",
BankName: "Federal Reserve Bank",
WireCurrency: symbol.USD,
WireCurrency: currency.USD.String(),
SwiftCode: "CTBAAU2S",
RequiresIntermediaryBank: false,
IsExpressWire: false,
@@ -563,7 +561,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
var withdrawFiatRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.USD,
Currency: currency.USD,
Description: "WITHDRAW IT ALL",
BankAccountName: "Satoshi Nakamoto",
BankAccountNumber: 12345,
@@ -571,7 +569,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
BankCity: "Tarry Town",
BankCountry: "AU",
BankName: "Federal Reserve Bank",
WireCurrency: symbol.USD,
WireCurrency: currency.USD.String(),
SwiftCode: "CTBAAU2S",
RequiresIntermediaryBank: false,
IsExpressWire: false,
@@ -596,12 +594,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() && customerID != "" {
_, err := b.GetDepositAddress(symbol.BTC, "")
_, err := b.GetDepositAddress(currency.BTC, "")
if err != nil {
t.Error("Test Failed - GetDepositAddress error", err)
}
} else {
_, err := b.GetDepositAddress(symbol.BTC, "")
_, err := b.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress error cannot be 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"
log "github.com/thrasher-/gocryptotrader/logger"
@@ -60,7 +60,7 @@ func (b *Bitstamp) findPairFromChannel(channelName string) (string, error) {
tradingPair := strings.ToUpper(split[len(split)-1])
for _, enabledPair := range b.EnabledPairs {
if enabledPair == tradingPair {
if enabledPair.String() == tradingPair {
return tradingPair, nil
}
}
@@ -102,7 +102,7 @@ func (b *Bitstamp) WsConnect() error {
go b.WsReadData()
for _, p := range b.GetEnabledCurrencies() {
orderbookSeed, err := b.GetOrderbook(p.Pair().String())
orderbookSeed, err := b.GetOrderbook(p.String())
if err != nil {
return err
}
@@ -127,9 +127,7 @@ func (b *Bitstamp) WsConnect() error {
newOrderbook.Asks = asks
newOrderbook.Bids = bids
newOrderbook.CurrencyPair = p.Pair().String()
newOrderbook.Pair = p
newOrderbook.LastUpdated = time.Unix(0, orderbookSeed.Timestamp)
newOrderbook.AssetType = "SPOT"
err = b.Websocket.Orderbook.LoadSnapshot(newOrderbook, b.GetName(), false)
@@ -144,7 +142,7 @@ func (b *Bitstamp) WsConnect() error {
}
err = b.WebsocketConn.Client.Subscribe(fmt.Sprintf("live_trades_%s",
strings.ToLower(p.Pair().String())))
p.Lower().String()))
if err != nil {
return fmt.Errorf("%s Websocket Trade subscription error: %s",
@@ -153,7 +151,7 @@ func (b *Bitstamp) WsConnect() error {
}
err = b.WebsocketConn.Client.Subscribe(fmt.Sprintf("diff_order_book_%s",
strings.ToLower(p.Pair().String())))
p.Lower().String()))
if err != nil {
return fmt.Errorf("%s Websocket Trade subscription error: %s",
@@ -194,7 +192,7 @@ func (b *Bitstamp) WsReadData() {
}
currencyPair := common.SplitStrings(data.Channel, "_")
p := pair.NewCurrencyPairFromString(common.StringToUpper(currencyPair[3]))
p := currency.NewPairFromString(common.StringToUpper(currencyPair[3]))
err = b.WsUpdateOrderbook(result, p, "SPOT")
if err != nil {
@@ -217,7 +215,7 @@ func (b *Bitstamp) WsReadData() {
b.Websocket.DataHandler <- exchange.TradeData{
Price: result.Price,
Amount: result.Amount,
CurrencyPair: pair.NewCurrencyPairFromString(currencyPair[2]),
CurrencyPair: currency.NewPairFromString(currencyPair[2]),
Exchange: b.GetName(),
AssetType: "SPOT",
}
@@ -226,7 +224,7 @@ func (b *Bitstamp) WsReadData() {
}
// WsUpdateOrderbook updates local cache of orderbook information
func (b *Bitstamp) WsUpdateOrderbook(ob PusherOrderbook, p pair.CurrencyPair, assetType string) error {
func (b *Bitstamp) WsUpdateOrderbook(ob PusherOrderbook, p currency.Pair, assetType string) error {
if len(ob.Asks) == 0 && len(ob.Bids) == 0 {
return errors.New("bitstamp_websocket.go error - no orderbook data")
}

View File

@@ -9,8 +9,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -46,7 +45,14 @@ func (b *Bitstamp) Run() {
p := strings.Split(pairs[x].Name, "/")
currencies = append(currencies, p[0]+p[1])
}
err = b.UpdateCurrencies(currencies, false, false)
var newCurrencies currency.Pairs
for _, p := range currencies {
newCurrencies = append(newCurrencies,
currency.NewPairFromString(p))
}
err = b.UpdateCurrencies(newCurrencies, false, false)
if err != nil {
log.Errorf("%s Failed to update available currencies.\n", b.Name)
}
@@ -54,9 +60,9 @@ func (b *Bitstamp) Run() {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (b *Bitstamp) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTicker(p.Pair().String(), false)
tick, err := b.GetTicker(p.String(), false)
if err != nil {
return tickerPrice, err
@@ -68,12 +74,17 @@ func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.P
tickerPrice.Last = tick.Last
tickerPrice.Volume = tick.Volume
tickerPrice.High = tick.High
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
err = ticker.ProcessTicker(b.GetName(), tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
return ticker.GetTicker(b.Name, p, assetType)
}
// GetTickerPrice returns the ticker for a currency pair
func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (b *Bitstamp) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
tick, err := ticker.GetTicker(b.GetName(), p, assetType)
if err != nil {
return b.UpdateTicker(p, assetType)
@@ -88,8 +99,8 @@ func (b *Bitstamp) GetFeeByType(feeBuilder exchange.FeeBuilder) (float64, error)
}
// GetOrderbookEx returns the orderbook for a currency pair
func (b *Bitstamp) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p, assetType)
func (b *Bitstamp) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.Get(b.GetName(), p, assetType)
if err != nil {
return b.UpdateOrderbook(p, assetType)
}
@@ -97,9 +108,9 @@ func (b *Bitstamp) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderb
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitstamp) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(p.Pair().String())
orderbookNew, err := b.GetOrderbook(p.String())
if err != nil {
return orderBook, err
}
@@ -114,8 +125,16 @@ func (b *Bitstamp) UpdateOrderbook(p pair.CurrencyPair, assetType string) (order
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Amount, Price: data.Price})
}
orderbook.ProcessOrderbook(b.GetName(), p, orderBook, assetType)
return orderbook.GetOrderbook(b.Name, p, assetType)
orderBook.Pair = p
orderBook.ExchangeName = b.GetName()
orderBook.AssetType = assetType
err = orderBook.Process()
if err != nil {
return orderBook, err
}
return orderbook.Get(b.Name, p, assetType)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
@@ -130,22 +149,22 @@ func (b *Bitstamp) GetAccountInfo() (exchange.AccountInfo, error) {
var currencies = []exchange.AccountCurrencyInfo{
{
CurrencyName: "BTC",
CurrencyName: currency.BTC,
TotalValue: accountBalance.BTCAvailable,
Hold: accountBalance.BTCReserved,
},
{
CurrencyName: "XRP",
CurrencyName: currency.XRP,
TotalValue: accountBalance.XRPAvailable,
Hold: accountBalance.XRPReserved,
},
{
CurrencyName: "USD",
CurrencyName: currency.USD,
TotalValue: accountBalance.USDAvailable,
Hold: accountBalance.USDReserved,
},
{
CurrencyName: "EUR",
CurrencyName: currency.EUR,
TotalValue: accountBalance.EURAvailable,
Hold: accountBalance.EURReserved,
},
@@ -165,18 +184,18 @@ func (b *Bitstamp) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (b *Bitstamp) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
func (b *Bitstamp) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
var resp []exchange.TradeHistory
return resp, common.ErrNotYetImplemented
}
// SubmitOrder submits a new order
func (b *Bitstamp) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
func (b *Bitstamp) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, _ string) (exchange.SubmitOrderResponse, error) {
var submitOrderResponse exchange.SubmitOrderResponse
buy := side == exchange.BuyOrderSide
market := orderType == exchange.MarketOrderType
response, err := b.PlaceOrder(p.Pair().String(), price, amount, buy, market)
response, err := b.PlaceOrder(p.String(), price, amount, buy, market)
if response.ID > 0 {
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.ID)
@@ -224,8 +243,8 @@ func (b *Bitstamp) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
}
// GetDepositAddress returns a deposit address for a specified currency
func (b *Bitstamp) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
return b.GetCryptoDepositAddress(cryptocurrency.String())
func (b *Bitstamp) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
return b.GetCryptoDepositAddress(cryptocurrency)
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
@@ -290,7 +309,7 @@ func (b *Bitstamp) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) (
if len(getOrdersRequest.Currencies) != 1 {
currPair = "all"
} else {
currPair = getOrdersRequest.Currencies[0].Pair().String()
currPair = getOrdersRequest.Currencies[0].String()
}
resp, err := b.GetOpenOrders(currPair)
@@ -299,17 +318,15 @@ func (b *Bitstamp) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) (
}
for _, order := range resp {
symbolOne := order.Currency[0:3]
symbolTwo := order.Currency[len(order.Currency)-3:]
orderDate := time.Unix(order.Date, 0)
orders = append(orders, exchange.OrderDetail{
Amount: order.Amount,
ID: fmt.Sprintf("%v", order.ID),
Price: order.Price,
OrderDate: orderDate,
CurrencyPair: pair.NewCurrencyPair(symbolOne, symbolTwo),
Exchange: b.Name,
Amount: order.Amount,
ID: fmt.Sprintf("%v", order.ID),
Price: order.Price,
OrderDate: orderDate,
CurrencyPair: currency.NewPairFromStrings(order.Currency[0:3],
order.Currency[len(order.Currency)-3:]),
Exchange: b.Name,
})
}
@@ -324,7 +341,7 @@ func (b *Bitstamp) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) (
func (b *Bitstamp) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]exchange.OrderDetail, error) {
var currPair string
if len(getOrdersRequest.Currencies) == 1 {
currPair = getOrdersRequest.Currencies[0].Pair().String()
currPair = getOrdersRequest.Currencies[0].String()
}
resp, err := b.GetUserTransactions(currPair)
if err != nil {
@@ -336,30 +353,31 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) (
if order.Type != 2 {
continue
}
quoteCurrency := ""
baseCurrency := ""
var quoteCurrency, baseCurrency currency.Code
switch {
case order.BTC > 0:
baseCurrency = symbol.BTC
baseCurrency = currency.BTC
case order.XRP > 0:
baseCurrency = symbol.XRP
baseCurrency = currency.XRP
default:
log.Warnf("no base currency found for OrderID '%v'", order.OrderID)
}
switch {
case order.USD > 0:
quoteCurrency = symbol.USD
quoteCurrency = currency.USD
case order.EUR > 0:
quoteCurrency = symbol.EUR
quoteCurrency = currency.EUR
default:
log.Warnf("no quote currency found for orderID '%v'", order.OrderID)
}
var currPair pair.CurrencyPair
if quoteCurrency != "" && baseCurrency != "" {
currPair = pair.NewCurrencyPairWithDelimiter(baseCurrency, quoteCurrency, b.ConfigCurrencyPairFormat.Delimiter)
var currPair currency.Pair
if quoteCurrency.String() != "" && baseCurrency.String() != "" {
currPair = currency.NewPairWithDelimiter(baseCurrency.String(),
quoteCurrency.String(),
b.ConfigCurrencyPairFormat.Delimiter)
}
orderDate := time.Unix(order.Date, 0)
@@ -371,7 +389,8 @@ func (b *Bitstamp) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) (
})
}
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
getOrdersRequest.EndTicks)
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
return orders, nil