Skip to content

Commit

Permalink
Deposit address wrapper Update (thrasher-corp#232)
Browse files Browse the repository at this point in the history
* Add get deposit address and fix authentication issue for ZB exchange

*  Add get deposit address for Yobit exchange

* Add get deposit address for Poloniex exchange

* Add get deposit address for LocalBitcoins exchange

* Remove support for deposit address on Liqui exchange

*  Add get deposit address for LakeBTC exchange

* Add notes as to the reason of non implementation

* Add get deposit address for Kraken exchange

* Add get deposit address for HitBTC exchange

*  Add get deposit address for GateIO exchange

* Add get deposit address for Exmo exchange

*  Remove support for deposit address on Coinut exchange

* Add test case for BTC Markets function still not supported yet.

*  Add get deposit address for Bittrex exchange

* Add get deposit address for Bitstamp exchange

* Add get deposit address for Bitmex exchange
Rm unused swagger.json file in Bitmex exchange

* Add get deposit address for Bithumb exchange

* Add get deposit address for Binance exchange
Fix bug in Authenticated requests, concatenates sig string on end of query

* Remove support for deposit address on ANX exchange

* Updated account type to segregate multiple accounts on an exchange.

* Fix requested changes

* Add get deposit address for Bitfinex exchange
Add parameter for getting deposit address to wrapper

* Add get deposit address for ANX exchange

* Fix misspelling in Poloniex

* Drop working field and initialisation of zero value for Account Type

* Change switch to symbol package currency code
  • Loading branch information
shazbert authored and thrasher- committed Jan 17, 2019
1 parent 88303b8 commit 84a6735
Show file tree
Hide file tree
Showing 75 changed files with 1,227 additions and 6,552 deletions.
13 changes: 10 additions & 3 deletions exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@ import (
// Alphapoint exchange
func (a *Alphapoint) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = a.GetName()
response.Exchange = a.GetName()
account, err := a.GetAccountInformation()
if err != nil {
return response, err
}

var currencies []exchange.AccountCurrencyInfo
for i := 0; i < len(account.Currencies); i++ {
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = account.Currencies[i].Name
exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance)
exchangeCurrency.Hold = float64(account.Currencies[i].Hold)

response.Currencies = append(response.Currencies, exchangeCurrency)
currencies = append(currencies, exchangeCurrency)
}

response.Accounts = append(response.Accounts, exchange.Account{
Currencies: currencies,
})

return response, nil
}

Expand Down Expand Up @@ -164,7 +171,7 @@ func (a *Alphapoint) GetOrderInfo(orderID int64) (float64, error) {
}

// GetDepositAddress returns a deposit address for a specified currency
func (a *Alphapoint) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, error) {
func (a *Alphapoint) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
addreses, err := a.GetDepositAddresses()
if err != nil {
return "", err
Expand Down
1 change: 0 additions & 1 deletion exchanges/anx/anx.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ func (a *ANX) GetDepositAddressByCurrency(currency, name string, new bool) (stri
}

err := a.SendAuthenticatedHTTPRequest(path, request, &response)

if err != nil {
return "", err
}
Expand Down
14 changes: 14 additions & 0 deletions exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,17 @@ func TestWithdrawInternationalBank(t *testing.T) {
t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err)
}
}

func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, err := a.GetDepositAddress(symbol.BTC, "")
if err != nil {
t.Error("Test Failed - GetDepositAddress() error", err)
}
} else {
_, err := a.GetDepositAddress(symbol.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
}
}
}
10 changes: 6 additions & 4 deletions exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ func (a *ANX) GetAccountInfo() (exchange.AccountInfo, error) {
})
}

info.ExchangeName = a.GetName()
info.Currencies = balance
info.Exchange = a.GetName()
info.Accounts = append(info.Accounts, exchange.Account{
Currencies: balance,
})

return info, nil
}
Expand Down Expand Up @@ -305,8 +307,8 @@ func (a *ANX) GetOrderInfo(orderID int64) (exchange.OrderDetail, error) {
}

// GetDepositAddress returns a deposit address for a specified currency
func (a *ANX) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, error) {
return "", common.ErrNotYetImplemented
func (a *ANX) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
return a.GetDepositAddressByCurrency(cryptocurrency.String(), "", false)
}

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
Expand Down
44 changes: 34 additions & 10 deletions exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/url"
Expand Down Expand Up @@ -603,17 +604,36 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
signature := params.Encode()
hmacSigned := common.GetHMAC(common.HashSHA256, []byte(signature), []byte(b.APISecret))
hmacSignedStr := common.HexEncodeToString(hmacSigned)
params.Set("signature", hmacSignedStr)

headers := make(map[string]string)
headers["X-MBX-APIKEY"] = b.APIKey

if b.Verbose {
log.Debugf("sent path: \n%s\n", path)
log.Debugf("sent path: %s", path)
}

path = common.EncodeURLValues(path, params)
path += fmt.Sprintf("&signature=%s", hmacSignedStr)

interim := json.RawMessage{}

errCap := struct {
Success bool `json:"success"`
Message string `json:"msg"`
}{}

return b.SendPayload(method, path, headers, bytes.NewBufferString(""), result, true, b.Verbose)
err := b.SendPayload(method, path, headers, bytes.NewBuffer(nil), &interim, true, b.Verbose)
if err != nil {
return err
}

if err := common.JSONDecode(interim, &errCap); err == nil {
if !errCap.Success && errCap.Message != "" {
return errors.New(errCap.Message)
}
}

return common.JSONDecode(interim, result)
}

// CheckLimit checks value against a variable list
Expand Down Expand Up @@ -742,15 +762,19 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
}

//GetDepositAddressForCurrency retrieves the wallet address for a given currency
func (b *Binance) GetDepositAddressForCurrency(currency string) error {
func (b *Binance) GetDepositAddressForCurrency(currency string) (string, error) {
path := fmt.Sprintf("%s%s", b.APIUrl, depositAddress)
var resp interface{}

resp := struct {
Address string `json:"address"`
Success bool `json:"success"`
AddressTag string `json:"addressTag"`
}{}

params := url.Values{}
params.Set("asset", currency)
params.Set("status", "true")

if err := b.SendAuthHTTPRequest("GET", path, params, &resp); err != nil {
return err
}

return nil
return resp.Address,
b.SendAuthHTTPRequest("GET", path, params, &resp)
}
19 changes: 16 additions & 3 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"testing"

"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/config"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
)

Expand Down Expand Up @@ -425,7 +424,7 @@ func TestGetAccountInfo(t *testing.T) {

_, err := b.GetAccountInfo()
if err != nil {
t.Error("test failed - GetAccountInfo() error:", err)
t.Error("test failed - GetAccountInfo() error", err)
}
}

Expand Down Expand Up @@ -491,3 +490,17 @@ func TestWithdrawInternationalBank(t *testing.T) {
t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err)
}
}

func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, err := b.GetDepositAddress(symbol.BTC, "")
if err != nil {
t.Error("Test Failed - GetDepositAddress() error", err)
}
} else {
_, err := b.GetDepositAddress(symbol.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
}
}
}
11 changes: 7 additions & 4 deletions exchanges/binance/binance_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ func (b *Binance) GetAccountInfo() (exchange.AccountInfo, error) {
})
}

info.ExchangeName = b.GetName()
info.Currencies = currencyBalance
info.Exchange = b.GetName()
info.Accounts = append(info.Accounts, exchange.Account{
Currencies: currencyBalance,
})

return info, nil
}

Expand Down Expand Up @@ -264,8 +267,8 @@ func (b *Binance) GetOrderInfo(orderID int64) (exchange.OrderDetail, error) {
}

// GetDepositAddress returns a deposit address for a specified currency
func (b *Binance) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, error) {
return "", common.ErrNotYetImplemented
func (b *Binance) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
return b.GetDepositAddressForCurrency(cryptocurrency.String())
}

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
Expand Down
28 changes: 28 additions & 0 deletions exchanges/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,3 +1087,31 @@ func (b *Bitfinex) ConvertSymbolToWithdrawalType(currency string) string {
return common.StringToLower(currency)
}
}

// ConvertSymbolToDepositMethod returns a converted currency deposit method
func (b *Bitfinex) ConvertSymbolToDepositMethod(currency string) (method string, err error) {
switch currency {
case symbol.BTC:
method = "bitcoin"
case symbol.LTC:
method = "litecoin"
case symbol.ETH:
method = "ethereum"
case symbol.ETC:
method = "ethereumc"
case symbol.USDT:
method = "tetheruso"
case symbol.ZEC:
method = "zcash"
case symbol.XMR:
method = "monero"
case symbol.BCH:
method = "bcash"
case symbol.MIOTA:
method = "iota"
default:
err = fmt.Errorf("currency %s not supported in method list",
currency)
}
return
}
20 changes: 17 additions & 3 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ func TestGetSymbolsDetails(t *testing.T) {
}

func TestGetAccountInfo(t *testing.T) {
if b.APIKey == "" || b.APISecret == "" {
if !areTestAPIKeysSet() {
t.SkipNow()
}
t.Parallel()

_, err := b.GetAccountInfo()
if err == nil {
t.Error("Test Failed - GetAccountInfo error")
if err != nil {
t.Error("Test Failed - GetAccountInfo error", err)
}
}

Expand Down Expand Up @@ -903,3 +903,17 @@ func TestWithdrawInternationalBank(t *testing.T) {
t.Errorf("Withdraw failed to be placed: %v", err)
}
}

func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, err := b.GetDepositAddress(symbol.BTC, "deposit")
if err != nil {
t.Error("Test Failed - GetDepositAddress() error", err)
}
} else {
_, err := b.GetDepositAddress(symbol.BTC, "deposit")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
}
}
}
60 changes: 28 additions & 32 deletions exchanges/bitfinex/bitfinex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,46 +118,32 @@ func (b *Bitfinex) UpdateOrderbook(p pair.CurrencyPair, assetType string) (order
// Bitfinex exchange
func (b *Bitfinex) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = b.GetName()
response.Exchange = b.GetName()
accountBalance, err := b.GetAccountBalance()
if err != nil {
return response, err
}
if !b.Enabled {
return response, nil
}

type bfxCoins struct {
OnHold float64
Available float64
var Accounts = []exchange.Account{
{ID: "deposit"},
{ID: "exchange"},
{ID: "trading"},
}

accounts := make(map[string]bfxCoins)

for i := range accountBalance {
onHold := accountBalance[i].Amount - accountBalance[i].Available
coins := bfxCoins{
OnHold: onHold,
Available: accountBalance[i].Available,
}
result, ok := accounts[accountBalance[i].Currency]
if !ok {
accounts[accountBalance[i].Currency] = coins
} else {
result.Available += accountBalance[i].Available
result.OnHold += onHold
accounts[accountBalance[i].Currency] = result
for _, bal := range accountBalance {
for i := range Accounts {
if Accounts[i].ID == bal.Type {
Accounts[i].Currencies = append(Accounts[i].Currencies,
exchange.AccountCurrencyInfo{
CurrencyName: bal.Currency,
TotalValue: bal.Amount,
Hold: bal.Amount - bal.Available,
})
}
}
}

for x, y := range accounts {
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = common.StringToUpper(x)
exchangeCurrency.TotalValue = y.Available + y.OnHold
exchangeCurrency.Hold = y.OnHold
response.Currencies = append(response.Currencies, exchangeCurrency)
}

response.Accounts = Accounts
return response, nil
}

Expand Down Expand Up @@ -229,8 +215,18 @@ func (b *Bitfinex) GetOrderInfo(orderID int64) (exchange.OrderDetail, error) {
}

// GetDepositAddress returns a deposit address for a specified currency
func (b *Bitfinex) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, error) {
return "", common.ErrNotYetImplemented
func (b *Bitfinex) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
method, err := b.ConvertSymbolToDepositMethod(cryptocurrency.String())
if err != nil {
return "", err
}

resp, err := b.NewDeposit(method, accountID, 0)
if err != nil {
return "", err
}

return resp.Address, nil
}

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bitflyer/bitflyer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (b *Bitflyer) UpdateOrderbook(p pair.CurrencyPair, assetType string) (order
// Bitflyer exchange
func (b *Bitflyer) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = b.GetName()
response.Exchange = b.GetName()
// accountBalance, err := b.GetAccountBalance()
// if err != nil {
// return response, err
Expand Down Expand Up @@ -184,7 +184,7 @@ func (b *Bitflyer) GetOrderInfo(orderID int64) (exchange.OrderDetail, error) {
}

// GetDepositAddress returns a deposit address for a specified currency
func (b *Bitflyer) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, error) {
func (b *Bitflyer) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
return "", common.ErrNotYetImplemented
}

Expand Down
Loading

0 comments on commit 84a6735

Please sign in to comment.