github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v2/rest/wallet.go (about) 1 package rest 2 3 import ( 4 "strconv" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/common" 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/notification" 8 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/wallet" 9 ) 10 11 // WalletService manages data flow for the Wallet API endpoint 12 type WalletService struct { 13 requestFactory 14 Synchronous 15 } 16 17 // Retrieves all of the wallets for the account 18 // see https://docs.bitfinex.com/reference#rest-auth-wallets for more info 19 func (s *WalletService) Wallet() (*wallet.Snapshot, error) { 20 req, err := s.requestFactory.NewAuthenticatedRequest(common.PermissionRead, "wallets") 21 if err != nil { 22 return nil, err 23 } 24 raw, err := s.Request(req) 25 if err != nil { 26 return nil, err 27 } 28 29 os, err := wallet.SnapshotFromRaw(raw) 30 if err != nil { 31 return nil, err 32 } 33 34 return os, nil 35 } 36 37 // Submits a request to transfer funds from one Bitfinex wallet to another 38 // see https://docs.bitfinex.com/reference#transfer-between-wallets for more info 39 func (ws *WalletService) Transfer(from, to, currency, currencyTo string, amount float64) (*notification.Notification, error) { 40 body := map[string]interface{}{ 41 "from": from, 42 "to": to, 43 "currency": currency, 44 "currency_to": currencyTo, 45 "amount": strconv.FormatFloat(amount, 'f', -1, 64), 46 } 47 req, err := ws.requestFactory.NewAuthenticatedRequestWithData(common.PermissionWrite, "transfer", body) 48 if err != nil { 49 return nil, err 50 } 51 raw, err := ws.Request(req) 52 if err != nil { 53 return nil, err 54 } 55 return notification.FromRaw(raw) 56 } 57 58 func (ws *WalletService) depositAddress(wallet string, method string, renew int) (*notification.Notification, error) { 59 body := map[string]interface{}{ 60 "wallet": wallet, 61 "method": method, 62 "op_renew": renew, 63 } 64 req, err := ws.requestFactory.NewAuthenticatedRequestWithData(common.PermissionWrite, "deposit/address", body) 65 if err != nil { 66 return nil, err 67 } 68 raw, err := ws.Request(req) 69 if err != nil { 70 return nil, err 71 } 72 return notification.FromRaw(raw) 73 } 74 75 // Retrieves the deposit address for the given Bitfinex wallet 76 // see https://docs.bitfinex.com/reference#deposit-address for more info 77 func (ws *WalletService) DepositAddress(wallet, method string) (*notification.Notification, error) { 78 return ws.depositAddress(wallet, method, 0) 79 } 80 81 // Submits a request to create a new deposit address for the give Bitfinex wallet. Old addresses are still valid. 82 // See https://docs.bitfinex.com/reference#deposit-address for more info 83 func (ws *WalletService) CreateDepositAddress(wallet, method string) (*notification.Notification, error) { 84 return ws.depositAddress(wallet, method, 1) 85 } 86 87 // Submits a request to withdraw funds from the given Bitfinex wallet to the given address 88 // See https://docs.bitfinex.com/reference#withdraw for more info 89 func (ws *WalletService) Withdraw(wallet, method string, amount float64, address string) (*notification.Notification, error) { 90 body := map[string]interface{}{ 91 "wallet": wallet, 92 "method": method, 93 "amount": strconv.FormatFloat(amount, 'f', -1, 64), 94 "address": address, 95 } 96 req, err := ws.requestFactory.NewAuthenticatedRequestWithData(common.PermissionWrite, "withdraw", body) 97 if err != nil { 98 return nil, err 99 } 100 raw, err := ws.Request(req) 101 if err != nil { 102 return nil, err 103 } 104 return notification.FromRaw(raw) 105 }