Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Examples

johnnycoinbase edited this page Jan 10, 2019 · 1 revision

User accounts

Get a list of user accounts

coinbase.accountResource.list { result in
    switch result {
    case .success(let accountsList):
        // ...
    case .failure(let error):
        // ..
    }
}

Get a specific account

coinbase.accountResource.account(id: <account_id>, completion: completion)

Change account name

coinbase.accountResource.updateAccount(id: <account_id>, name: <new_name>, completion: completion)

Delete account

coinbase.accountResource.deleteAccount(id: <account_id>, completion: completion)

Transactions

Send money

let sendParameters = SendTransactionParameters(to: "[email protected]",
                                               amount: "0.01",
                                               currency: "BTC",
                                               description: "Thanks for the coffee!")
            
coinbase.transactionResource.send(accountID: <account_id>,
                                  twoFactorAuthToken: <2fa_token>,
                                  parameters: sendParameters, 
                                  completion: completion)

The to parameter can be a bitcoin address, bitcoin cash address, litecoin address, ethereum address, or an email of the recipient. The description parameter is a note which will be included in the email that the recipient receives.

let sendParameters = SendTransactionParameters(to: "[email protected]",
                                               amount: "2.55",
                                               currency: "USD",
                                               description: "Thanks for the coffee!")
            
coinbase.transactionResource.send(accountID: <account_id>,
                                  twoFactorAuthToken: <2fa_token>,
                                  parameters: sendParameters, 
                                  completion: completion)

Note

Reed about Two factor authentication

Request money

let requestParameters = RequestTransactionParameters(to: "[email protected]", 
                                                     amount: "0.01",
                                                     currency: "BTC",
                                                     description: "Invoice for window cleaning")

coinbase.transactionResource.request(accountID: <account_id>, 
                                     parameters: requestParameters, 
                                     completion: completion)

This will send an email to the recipient, requesting payment.

The request can be re-sent

coinbase.transactionResource.resendRequest(accountID: <account_id>,
                                           transactionID: <transaction_id>, 
                                           completion: completion)

or canceled

coinbase.transactionResource.cancelRequest(accountID: <account_id>,
                                           transactionID: <transaction_id>, 
                                           completion: completion)

To fulfill the request a recipient should call

coinbase.transactionResource.completeRequest(accountID: <account_id>,
                                             transactionID: <transaction_id>, 
                                             completion: completion)

List transactions

The result list is in descending order by default (newest item first). Default limit is set to 25.

coinbase.transactionResource.list(accountID: <account_id>, 
                                  completion: completion)

Get a transaction

This will fetch a transaction with all fields expanded:

coinbase.transactionResource.transaction(accountID: <account_id>,
                                         transactionID: <transaction_id>,
                                         expandOptions: [.all], 
                                         completion: completion)

Buy or Sell crypto currency

Buying and selling requires user to add a payment method through the web app first.

Then you can place buy/sell order and pass an amount of crypto currency you want to buy/sell.

For buy:

let buyParameters = BuySellParameters(amount: "0.01", 
                                      currency: "BTC", 
                                      paymentMethod: <payment_method_id>)

coinbase.buyResource.placeOrder(accountID: <account_id>,
                                parameters: buyParameters,
                                completion: completion)

For sell:

let sellParameters = BuySellParameters(amount: "0.01", 
                                       currency: "BTC", 
                                       paymentMethod: <payment_method_id>)

coinbase.sellResource.placeOrder(accountID: <account_id>,
                                 parameters: sellParameters,
                                 completion: completion)

Listing Buy/Sell History

You can use list to view history of buys and sells.

For history of buys:

coinbase.buyResource.list(accountID: <account_id>, 
                          completion: completion)

For history of sells:

coinbase.sellResource.list(accountID: <account_id>, 
                           completion: completion)