From 2f3b10edcc80f13dcc8ceb653e8012d83522fa0b Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Tue, 1 May 2018 15:10:36 +1000 Subject: [PATCH] Fix number conversion for BTCMarkets (#121) --- exchanges/btcmarkets/btcmarkets.go | 23 +++++++++++++++-------- exchanges/btcmarkets/btcmarkets_test.go | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index f2aabe78..af6c421d 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -147,12 +147,15 @@ func (b *BTCMarkets) GetTrades(firstPair, secondPair string, values url.Values) // orderside - example "Bid" or "Ask" // orderType - example "limit" // clientReq - example "abc-cdf-1000" -func (b *BTCMarkets) NewOrder(currency, instrument string, price, amount int64, orderSide, orderType, clientReq string) (int, error) { +func (b *BTCMarkets) NewOrder(currency, instrument string, price, amount float64, orderSide, orderType, clientReq string) (int, error) { + newPrice := int64(price * float64(common.SatoshisPerBTC)) + newVolume := int64(amount * float64(common.SatoshisPerBTC)) + order := OrderToGo{ Currency: common.StringToUpper(currency), Instrument: common.StringToUpper(instrument), - Price: price * common.SatoshisPerBTC, - Volume: amount * common.SatoshisPerBTC, + Price: newPrice, + Volume: newVolume, OrderSide: orderSide, OrderType: orderType, ClientRequestID: clientReq, @@ -302,9 +305,11 @@ func (b *BTCMarkets) GetAccountBalance() ([]AccountBalance, error) { } // WithdrawCrypto withdraws cryptocurrency into a designated address -func (b *BTCMarkets) WithdrawCrypto(amount int64, currency, address string) (string, error) { +func (b *BTCMarkets) WithdrawCrypto(amount float64, currency, address string) (string, error) { + newAmount := int64(amount * float64(common.SatoshisPerBTC)) + req := WithdrawRequestCrypto{ - Amount: amount, + Amount: newAmount, Currency: common.StringToUpper(currency), Address: address, } @@ -324,14 +329,16 @@ func (b *BTCMarkets) WithdrawCrypto(amount int64, currency, address string) (str // WithdrawAUD withdraws AUD into a designated bank address // Does not return a TxID! -func (b *BTCMarkets) WithdrawAUD(accountName, accountNumber, bankName, bsbNumber, currency string, amount int64) (string, error) { +func (b *BTCMarkets) WithdrawAUD(accountName, accountNumber, bankName, bsbNumber string, amount float64) (string, error) { + newAmount := int64(amount * float64(common.SatoshisPerBTC)) + req := WithdrawRequestAUD{ AccountName: accountName, AccountNumber: accountNumber, BankName: bankName, BSBNumber: bsbNumber, - Amount: amount, - Currency: common.StringToUpper(currency), + Amount: newAmount, + Currency: "AUD", } resp := Response{} diff --git a/exchanges/btcmarkets/btcmarkets_test.go b/exchanges/btcmarkets/btcmarkets_test.go index 0825cfb9..a55aa0ec 100644 --- a/exchanges/btcmarkets/btcmarkets_test.go +++ b/exchanges/btcmarkets/btcmarkets_test.go @@ -140,7 +140,7 @@ func TestWithdrawCrypto(t *testing.T) { func TestWithdrawAUD(t *testing.T) { t.Parallel() - _, err := bm.WithdrawAUD("BLA", "1337", "blawest", "1336", "BTC", 10000000) + _, err := bm.WithdrawAUD("BLA", "1337", "blawest", "1336", 10000000) if err == nil { t.Error("Test failed - WithdrawAUD() error", err) }