github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/wallet.go (about)

     1  package bitfinex
     2  
     3  import "strconv"
     4  
     5  const (
     6  	WALLET_TRADING  = "trading"
     7  	WALLET_EXCHANGE = "exchange"
     8  	WALLET_DEPOSIT  = "deposit"
     9  )
    10  
    11  type WalletService struct {
    12  	client *Client
    13  }
    14  
    15  type TransferStatus struct {
    16  	Status  string
    17  	Message string
    18  }
    19  
    20  // Transfer funds between wallets
    21  func (c *WalletService) Transfer(amount float64, currency, from, to string) ([]TransferStatus, error) {
    22  
    23  	payload := map[string]interface{}{
    24  		"amount":     strconv.FormatFloat(amount, 'f', -1, 32),
    25  		"currency":   currency,
    26  		"walletfrom": from,
    27  		"walletto":   to,
    28  	}
    29  
    30  	req, err := c.client.newAuthenticatedRequest("GET", "transfer", payload)
    31  
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	status := make([]TransferStatus, 0)
    37  
    38  	_, err = c.client.do(req, &status)
    39  
    40  	return status, err
    41  }
    42  
    43  type WithdrawStatus struct {
    44  	Status       string
    45  	Message      string
    46  	WithdrawalID int `json:"withdrawal_id"`
    47  }
    48  
    49  // Withdraw a cryptocurrency to a digital wallet
    50  func (c *WalletService) WithdrawCrypto(amount float64, currency, wallet, destinationAddress string) ([]WithdrawStatus, error) {
    51  
    52  	payload := map[string]interface{}{
    53  		"amount":         strconv.FormatFloat(amount, 'f', -1, 32),
    54  		"walletselected": wallet,
    55  		"withdraw_type":  currency,
    56  		"address":        destinationAddress,
    57  	}
    58  
    59  	req, err := c.client.newAuthenticatedRequest("POST", "withdraw", payload)
    60  
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	status := make([]WithdrawStatus, 0)
    66  
    67  	_, err = c.client.do(req, &status)
    68  
    69  	return status, err
    70  
    71  }
    72  
    73  type BankAccount struct {
    74  	AccountName   string // Account name
    75  	AccountNumber string // Account number or IBAN
    76  	BankName      string // Bank Name
    77  	BankAddress   string // Bank Address
    78  	BankCity      string // Bank City
    79  	BankCountry   string // Bank Country
    80  	SwiftCode     string // SWIFT Code
    81  }
    82  
    83  func (c *WalletService) WithdrawWire(amount float64, expressWire bool, wallet string, beneficiaryBank, intermediaryBank BankAccount, message string) ([]WithdrawStatus, error) {
    84  
    85  	var express int
    86  	if expressWire {
    87  		express = 1
    88  	} else {
    89  		express = 0
    90  	}
    91  
    92  	payload := map[string]interface{}{
    93  		"amount":                    strconv.FormatFloat(amount, 'f', -1, 32),
    94  		"walletselected":            wallet,
    95  		"withdraw_type":             "wire",
    96  		"expressWire":               express,
    97  		"account_name":              beneficiaryBank.AccountName,
    98  		"account_number":            beneficiaryBank.AccountNumber,
    99  		"bank_name":                 beneficiaryBank.BankName,
   100  		"bank_address":              beneficiaryBank.BankAddress,
   101  		"bank_city":                 beneficiaryBank.BankCity,
   102  		"bank_country":              beneficiaryBank.BankCountry,
   103  		"swift":                     beneficiaryBank.SwiftCode,
   104  		"detail_payment":            message,
   105  		"intermediary_bank_account": intermediaryBank.AccountNumber,
   106  		"intermediary_bank_address": intermediaryBank.BankAddress,
   107  		"intermediary_bank_city":    intermediaryBank.BankCity,
   108  		"intermediary_bank_country": intermediaryBank.BankCountry,
   109  		"intermediary_bank_swift":   intermediaryBank.SwiftCode,
   110  	}
   111  
   112  	req, err := c.client.newAuthenticatedRequest("GET", "withdraw", payload)
   113  
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  
   118  	status := make([]WithdrawStatus, 0)
   119  
   120  	_, err = c.client.do(req, &status)
   121  
   122  	return status, err
   123  
   124  }