mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
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:
committed by
Adrian Gallagher
parent
ed760e184e
commit
0990f9d118
@@ -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"
|
||||
@@ -97,9 +97,9 @@ func (b *Bithumb) 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
|
||||
err := b.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -614,11 +614,11 @@ func (b *Bithumb) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount)
|
||||
case exchange.CyptocurrencyDepositFee:
|
||||
fee = getDepositFee(feeBuilder.FirstCurrency, feeBuilder.Amount)
|
||||
fee = getDepositFee(feeBuilder.Pair.Base, feeBuilder.Amount)
|
||||
case exchange.CryptocurrencyWithdrawalFee:
|
||||
fee = getWithdrawalFee(feeBuilder.FirstCurrency)
|
||||
fee = getWithdrawalFee(feeBuilder.Pair.Base)
|
||||
case exchange.InternationalBankWithdrawalFee:
|
||||
fee = getWithdrawalFee(feeBuilder.CurrencyItem)
|
||||
fee = getWithdrawalFee(feeBuilder.FiatCurrency)
|
||||
}
|
||||
if fee < 0 {
|
||||
fee = 0
|
||||
@@ -633,31 +633,31 @@ func calculateTradingFee(purchasePrice, amount float64) float64 {
|
||||
}
|
||||
|
||||
// getDepositFee returns fee on a currency when depositing small amounts to bithumb
|
||||
func getDepositFee(currency string, amount float64) float64 {
|
||||
func getDepositFee(c currency.Code, amount float64) float64 {
|
||||
var fee float64
|
||||
|
||||
switch currency {
|
||||
case symbol.BTC:
|
||||
switch c {
|
||||
case currency.BTC:
|
||||
if amount <= 0.005 {
|
||||
fee = 0.001
|
||||
}
|
||||
case symbol.LTC:
|
||||
case currency.LTC:
|
||||
if amount <= 0.3 {
|
||||
fee = 0.01
|
||||
}
|
||||
case symbol.DASH:
|
||||
case currency.DASH:
|
||||
if amount <= 0.04 {
|
||||
fee = 0.01
|
||||
}
|
||||
case symbol.BCH:
|
||||
case currency.BCH:
|
||||
if amount <= 0.03 {
|
||||
fee = 0.001
|
||||
}
|
||||
case symbol.ZEC:
|
||||
case currency.ZEC:
|
||||
if amount <= 0.02 {
|
||||
fee = 0.001
|
||||
}
|
||||
case symbol.BTG:
|
||||
case currency.BTG:
|
||||
if amount <= 0.15 {
|
||||
fee = 0.001
|
||||
}
|
||||
@@ -667,8 +667,8 @@ func getDepositFee(currency string, amount float64) float64 {
|
||||
}
|
||||
|
||||
// getWithdrawalFee returns fee on a currency when withdrawing out of bithumb
|
||||
func getWithdrawalFee(currency string) float64 {
|
||||
return WithdrawalFees[currency]
|
||||
func getWithdrawalFee(c currency.Code) float64 {
|
||||
return WithdrawalFees[c]
|
||||
}
|
||||
|
||||
var errCode = map[string]string{
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -195,13 +194,10 @@ func TestMarketSellOrder(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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +256,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(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
@@ -269,7 +265,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(0) || err != nil {
|
||||
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
||||
t.Error(err)
|
||||
@@ -338,10 +334,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 := b.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 1, "clientId")
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
@@ -359,7 +355,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",
|
||||
@@ -385,7 +381,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",
|
||||
@@ -424,12 +420,12 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
curr := pair.NewCurrencyPairFromString("BTCUSD")
|
||||
curr := currency.NewPairFromString("BTCUSD")
|
||||
_, err := b.ModifyOrder(exchange.ModifyOrder{OrderID: "1337",
|
||||
Price: 100,
|
||||
Amount: 1000,
|
||||
OrderSide: exchange.SellOrderSide,
|
||||
Currency: curr})
|
||||
Price: 100,
|
||||
Amount: 1000,
|
||||
OrderSide: exchange.SellOrderSide,
|
||||
CurrencyPair: curr})
|
||||
if err == nil {
|
||||
t.Error("Test Failed - ModifyOrder() error")
|
||||
}
|
||||
@@ -444,7 +440,7 @@ func TestWithdraw(t *testing.T) {
|
||||
|
||||
var withdrawCryptoRequest = exchange.WithdrawRequest{
|
||||
Amount: 100,
|
||||
Currency: symbol.BTC,
|
||||
Currency: currency.BTC,
|
||||
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
@@ -468,7 +464,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
|
||||
var withdrawFiatRequest = exchange.WithdrawRequest{
|
||||
Amount: 100,
|
||||
Currency: symbol.KRW,
|
||||
Currency: currency.KRW,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: 12345,
|
||||
@@ -477,7 +473,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "Hyrule",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: symbol.KRW,
|
||||
WireCurrency: currency.KRW.String(),
|
||||
SwiftCode: "Taylor",
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
@@ -510,12 +506,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if testAPIKey != "" && testAPISecret != "" {
|
||||
_, 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")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package bithumb
|
||||
|
||||
import "github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||
import "github.com/thrasher-/gocryptotrader/currency"
|
||||
|
||||
// Ticker holds ticker data
|
||||
type Ticker struct {
|
||||
@@ -225,51 +225,51 @@ type MarketSell struct {
|
||||
|
||||
// WithdrawalFees the large list of predefined withdrawal fees
|
||||
// Prone to change
|
||||
var WithdrawalFees = map[string]float64{
|
||||
symbol.KRW: 1000,
|
||||
symbol.BTC: 0.001,
|
||||
symbol.ETH: 0.01,
|
||||
symbol.DASH: 0.01,
|
||||
symbol.LTC: 0.01,
|
||||
symbol.ETC: 0.01,
|
||||
symbol.XRP: 1,
|
||||
symbol.BCH: 0.001,
|
||||
symbol.XMR: 0.05,
|
||||
symbol.ZEC: 0.001,
|
||||
symbol.QTUM: 0.05,
|
||||
symbol.BTG: 0.001,
|
||||
symbol.ICX: 1,
|
||||
symbol.TRX: 5,
|
||||
symbol.ELF: 5,
|
||||
symbol.MITH: 5,
|
||||
symbol.MCO: 0.5,
|
||||
symbol.OMG: 0.4,
|
||||
symbol.KNC: 3,
|
||||
symbol.GNT: 12,
|
||||
symbol.HSR: 0.2,
|
||||
symbol.ZIL: 30,
|
||||
symbol.ETHOS: 2,
|
||||
symbol.PAY: 2.4,
|
||||
symbol.WAX: 5,
|
||||
symbol.POWR: 5,
|
||||
symbol.LRC: 10,
|
||||
symbol.GTO: 15,
|
||||
symbol.STEEM: 0.01,
|
||||
symbol.STRAT: 0.2,
|
||||
symbol.PPT: 0.5,
|
||||
symbol.CTXC: 4,
|
||||
symbol.CMT: 20,
|
||||
symbol.THETA: 24,
|
||||
symbol.WTC: 0.7,
|
||||
symbol.ITC: 5,
|
||||
symbol.TRUE: 4,
|
||||
symbol.ABT: 5,
|
||||
symbol.RNT: 20,
|
||||
symbol.PLY: 20,
|
||||
symbol.WAVES: 0.01,
|
||||
symbol.LINK: 10,
|
||||
symbol.ENJ: 35,
|
||||
symbol.PST: 30,
|
||||
var WithdrawalFees = map[currency.Code]float64{
|
||||
currency.KRW: 1000,
|
||||
currency.BTC: 0.001,
|
||||
currency.ETH: 0.01,
|
||||
currency.DASH: 0.01,
|
||||
currency.LTC: 0.01,
|
||||
currency.ETC: 0.01,
|
||||
currency.XRP: 1,
|
||||
currency.BCH: 0.001,
|
||||
currency.XMR: 0.05,
|
||||
currency.ZEC: 0.001,
|
||||
currency.QTUM: 0.05,
|
||||
currency.BTG: 0.001,
|
||||
currency.ICX: 1,
|
||||
currency.TRX: 5,
|
||||
currency.ELF: 5,
|
||||
currency.MITH: 5,
|
||||
currency.MCO: 0.5,
|
||||
currency.OMG: 0.4,
|
||||
currency.KNC: 3,
|
||||
currency.GNT: 12,
|
||||
currency.HSR: 0.2,
|
||||
currency.ZIL: 30,
|
||||
currency.ETHOS: 2,
|
||||
currency.PAY: 2.4,
|
||||
currency.WAX: 5,
|
||||
currency.POWR: 5,
|
||||
currency.LRC: 10,
|
||||
currency.GTO: 15,
|
||||
currency.STEEM: 0.01,
|
||||
currency.STRAT: 0.2,
|
||||
currency.PPT: 0.5,
|
||||
currency.CTXC: 4,
|
||||
currency.CMT: 20,
|
||||
currency.THETA: 24,
|
||||
currency.WTC: 0.7,
|
||||
currency.ITC: 5,
|
||||
currency.TRUE: 4,
|
||||
currency.ABT: 5,
|
||||
currency.RNT: 20,
|
||||
currency.PLY: 20,
|
||||
currency.WAVES: 0.01,
|
||||
currency.LINK: 10,
|
||||
currency.ENJ: 35,
|
||||
currency.PST: 30,
|
||||
}
|
||||
|
||||
// FullBalance defines a return type with full balance data
|
||||
|
||||
@@ -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"
|
||||
@@ -38,7 +37,13 @@ func (b *Bithumb) Run() {
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||
} else {
|
||||
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
||||
var newExchangeProducts currency.Pairs
|
||||
for _, p := range exchangeProducts {
|
||||
newExchangeProducts = append(newExchangeProducts,
|
||||
currency.NewPairFromString(p))
|
||||
}
|
||||
|
||||
err = b.UpdateCurrencies(newExchangeProducts, false, false)
|
||||
if err != nil {
|
||||
log.Errorf("%s Failed to update available symbols.\n", b.GetName())
|
||||
}
|
||||
@@ -60,7 +65,7 @@ func (b *Bithumb) GetTradingPairs() ([]string, error) {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bithumb) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (b *Bithumb) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
var tickerPrice ticker.Price
|
||||
|
||||
tickers, err := b.GetAllTickers()
|
||||
@@ -69,7 +74,7 @@ func (b *Bithumb) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pr
|
||||
}
|
||||
|
||||
for _, x := range b.GetEnabledCurrencies() {
|
||||
currency := x.FirstCurrency.String()
|
||||
currency := x.Base.String()
|
||||
var tp ticker.Price
|
||||
tp.Pair = x
|
||||
tp.Ask = tickers[currency].SellPrice
|
||||
@@ -78,13 +83,17 @@ func (b *Bithumb) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pr
|
||||
tp.Last = tickers[currency].ClosingPrice
|
||||
tp.Volume = tickers[currency].Volume1Day
|
||||
tp.High = tickers[currency].MaxPrice
|
||||
ticker.ProcessTicker(b.Name, x, tp, assetType)
|
||||
|
||||
err = ticker.ProcessTicker(b.Name, tp, assetType)
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
}
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currency pair
|
||||
func (b *Bithumb) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
|
||||
func (b *Bithumb) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p, assetType)
|
||||
@@ -93,8 +102,8 @@ func (b *Bithumb) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns orderbook base on the currency pair
|
||||
func (b *Bithumb) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.GetOrderbook(b.GetName(), currency, assetType)
|
||||
func (b *Bithumb) GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(b.GetName(), currency, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateOrderbook(currency, assetType)
|
||||
}
|
||||
@@ -102,9 +111,9 @@ func (b *Bithumb) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bithumb) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
|
||||
func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
currency := p.FirstCurrency.String()
|
||||
currency := p.Base.String()
|
||||
|
||||
orderbookNew, err := b.GetOrderBook(currency)
|
||||
if err != nil {
|
||||
@@ -119,8 +128,16 @@ func (b *Bithumb) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderb
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: asks.Quantity, Price: asks.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
|
||||
@@ -141,7 +158,7 @@ func (b *Bithumb) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
}
|
||||
|
||||
exchangeBalances = append(exchangeBalances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: key,
|
||||
CurrencyName: currency.NewCode(key),
|
||||
TotalValue: totalAmount,
|
||||
Hold: hold,
|
||||
})
|
||||
@@ -163,7 +180,7 @@ func (b *Bithumb) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
}
|
||||
|
||||
// GetExchangeHistory returns historic trade data since exchange opening.
|
||||
func (b *Bithumb) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
func (b *Bithumb) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
|
||||
var resp []exchange.TradeHistory
|
||||
|
||||
return resp, common.ErrNotYetImplemented
|
||||
@@ -171,17 +188,17 @@ func (b *Bithumb) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]e
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: Fill this out to support limit orders
|
||||
func (b *Bithumb) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ exchange.OrderType, amount, _ float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
func (b *Bithumb) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.OrderType, amount, _ float64, _ string) (exchange.SubmitOrderResponse, error) {
|
||||
var submitOrderResponse exchange.SubmitOrderResponse
|
||||
var err error
|
||||
var orderID string
|
||||
if side == exchange.BuyOrderSide {
|
||||
var result MarketBuy
|
||||
result, err = b.MarketBuyOrder(p.FirstCurrency.String(), amount)
|
||||
result, err = b.MarketBuyOrder(p.Base.String(), amount)
|
||||
orderID = result.OrderID
|
||||
} else if side == exchange.SellOrderSide {
|
||||
var result MarketSell
|
||||
result, err = b.MarketSellOrder(p.FirstCurrency.String(), amount)
|
||||
result, err = b.MarketSellOrder(p.Base.String(), amount)
|
||||
orderID = result.OrderID
|
||||
}
|
||||
|
||||
@@ -200,7 +217,7 @@ func (b *Bithumb) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, _ ex
|
||||
// market conversion
|
||||
func (b *Bithumb) ModifyOrder(action exchange.ModifyOrder) (string, error) {
|
||||
order, err := b.ModifyTrade(action.OrderID,
|
||||
action.Currency.FirstCurrency.String(),
|
||||
action.CurrencyPair.Base.String(),
|
||||
common.StringToLower(action.OrderSide.ToString()),
|
||||
action.Amount,
|
||||
int64(action.Price))
|
||||
@@ -214,7 +231,9 @@ func (b *Bithumb) ModifyOrder(action exchange.ModifyOrder) (string, error) {
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bithumb) CancelOrder(order exchange.OrderCancellation) error {
|
||||
_, err := b.CancelTrade(order.Side.ToString(), order.OrderID, order.CurrencyPair.FirstCurrency.String())
|
||||
_, err := b.CancelTrade(order.Side.ToString(),
|
||||
order.OrderID,
|
||||
order.CurrencyPair.Base.String())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -226,7 +245,11 @@ func (b *Bithumb) CancelAllOrders(orderCancellation exchange.OrderCancellation)
|
||||
var allOrders []OrderData
|
||||
|
||||
for _, currency := range b.GetEnabledCurrencies() {
|
||||
orders, err := b.GetOrders("", orderCancellation.Side.ToString(), "100", "", currency.FirstCurrency.String())
|
||||
orders, err := b.GetOrders("",
|
||||
orderCancellation.Side.ToString(),
|
||||
"100",
|
||||
"",
|
||||
currency.Base.String())
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
@@ -234,7 +257,9 @@ func (b *Bithumb) CancelAllOrders(orderCancellation exchange.OrderCancellation)
|
||||
}
|
||||
|
||||
for _, order := range allOrders {
|
||||
_, err := b.CancelTrade(orderCancellation.Side.ToString(), order.OrderID, orderCancellation.CurrencyPair.FirstCurrency.String())
|
||||
_, err := b.CancelTrade(orderCancellation.Side.ToString(),
|
||||
order.OrderID,
|
||||
orderCancellation.CurrencyPair.Base.String())
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[order.OrderID] = err.Error()
|
||||
}
|
||||
@@ -250,7 +275,7 @@ func (b *Bithumb) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (b *Bithumb) GetDepositAddress(cryptocurrency pair.CurrencyItem, _ string) (string, error) {
|
||||
func (b *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
addr, err := b.GetWalletAddress(cryptocurrency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -272,7 +297,7 @@ func (b *Bithumb) WithdrawFiatFunds(withdrawRequest exchange.WithdrawRequest) (s
|
||||
if math.Mod(withdrawRequest.Amount, 1) != 0 {
|
||||
return "", errors.New("currency KRW does not support decimal places")
|
||||
}
|
||||
if withdrawRequest.Currency.String() != symbol.KRW {
|
||||
if withdrawRequest.Currency != currency.KRW {
|
||||
return "", errors.New("only KRW is supported")
|
||||
}
|
||||
bankDetails := fmt.Sprintf("%v_%v", withdrawRequest.BankCode, withdrawRequest.BankName)
|
||||
@@ -326,7 +351,9 @@ func (b *Bithumb) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
Price: order.Price,
|
||||
RemainingAmount: order.UnitsRemaining,
|
||||
Status: string(exchange.ActiveOrderStatus),
|
||||
CurrencyPair: pair.NewCurrencyPairWithDelimiter(order.OrderCurrency, order.PaymentCurrency, b.ConfigCurrencyPairFormat.Delimiter),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(order.OrderCurrency,
|
||||
order.PaymentCurrency,
|
||||
b.ConfigCurrencyPairFormat.Delimiter),
|
||||
}
|
||||
|
||||
if order.Type == "bid" {
|
||||
@@ -339,7 +366,8 @@ func (b *Bithumb) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
|
||||
return orders, nil
|
||||
@@ -367,7 +395,9 @@ func (b *Bithumb) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
OrderDate: orderDate,
|
||||
Price: order.Price,
|
||||
RemainingAmount: order.UnitsRemaining,
|
||||
CurrencyPair: pair.NewCurrencyPairWithDelimiter(order.OrderCurrency, order.PaymentCurrency, b.ConfigCurrencyPairFormat.Delimiter),
|
||||
CurrencyPair: currency.NewPairWithDelimiter(order.OrderCurrency,
|
||||
order.PaymentCurrency,
|
||||
b.ConfigCurrencyPairFormat.Delimiter),
|
||||
}
|
||||
|
||||
if order.Type == "bid" {
|
||||
@@ -380,7 +410,8 @@ func (b *Bithumb) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([
|
||||
}
|
||||
|
||||
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
|
||||
getOrdersRequest.EndTicks)
|
||||
exchange.FilterOrdersByCurrencies(&orders, getOrdersRequest.Currencies)
|
||||
|
||||
return orders, nil
|
||||
|
||||
Reference in New Issue
Block a user