Wallet

The Wallet Page handles the buying, selling, sending and receiving of cryptocurrencies.

To get started with using the Wallet class, import it from the buycoins package:

wallet.py
from buycoins import Wallet

You can use the class directly using Wallet().method_name or instantiate the class into a variable and use:

wallet = Wallet()
wallet.method_name(**args)

buy_crypto(currency, coin_amount)

This method is used to buy an amount coin_amount of the supplied currency.

Example:

wallet.py
from buycoins import Wallet

wallet = Wallet()

buy_bitcoin = wallet.buy_crypto(currency="bitcoin", coin_amount=0.05)

print(buy_bitcoin)

This printed response:

{
    "id": "QnV5Y29pbnNQcmljZS05NjNmZTExOS02ZGVhLTRlMDItYTc3NC1lZjViYjk3YWZiNGE=",
    "cryptocurrency": "bitcoin",
    "status": "processing",
    "totalCoinAmount": 0.05,
    "side": "buy",
}

sell_ crypto(currency, coin_amount)

This method sells an amount coin_amount of the suppliedcurrency at the current BuyCoin's price.

Example:

wallet.py
from buycoins import Wallet

wallet = Wallet()

sell_bitcoin = wallet.sell_crypto(currency="bitcoin", coin_amount=0.05)

print(sell_bitcoin)

The printed response:

{
    "id": "QnV5Y29pbnNQcmljZS05NjNmZTExOS02ZGVhLTRlMDItYTc3NC1lZjViYjk3YWZiNGE=",
    "cryptocurrency": "bitcoin",
    "status": "processing",
    "totalCoinAmount": 0.05,
    "side": "sell",
}

get_network_fee(currency, coin_amount)

This method calculates and returns the network fee for an amount coin_amount of the supplied currency.

Example:

wallet.py
from buycoins import Wallet

wallet = Wallet()

network_fee = wallet.get_network_fee(currency="bitcoin", coin_amount=0.01)

print(network_fee)

The response printed:

{
    "estimatedFee": 0.00044,
    "total": 0.01044,
}

create_address(currency)

This method creates a wallet address for the given currency.

Example:

wallet.py
from buycoins import Wallet

wallet = Wallet()

usd_coin_address = wallet.create_address(currency="usd_coin")

print(usd_coin_address)

The printed response:

{
    "cryptocurrency": "usd_coin", 
    "address": "0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a",
}

send_crypto(currency, coin_amount, address)

This method sends an amountcoin_amountof the specified currency to the supplied address.

Example

wallet.py
from buycoins import Wallet

wallet = Wallet()

send_usd_coin = wallet.send_crypto(currency="usd_coin", coin_amount=20, address="0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a")

print(send_usd_coin)

The printed response:

{
    "id": "QnV5Y29pbnNQ=",
    "address": "0x3856c5511ac5344eb85d439e338ae0f1b5dbe34a",
    "amount": 20,
    "cryptocurrency": "usd_coin",
    "fee": 1.25,
    "status": "processing",
    "transaction": {
        "txhash": "hybuojpkllmjvvcdersxkjijmkllbvdsabl",
        "id": "QnV5Y29pbnNQ=",
    }
}

Sending cryptocurrencies via the API is currently not supported. You need to contact BuyCoin's support to lift the restriction.

get_balances()

This gets all cryptocurrency balance available to the user.

Example:

from buycoins import Wallet

wallet = Wallet()

balances = wallet.get_balances()

print(balances)

The printed response:

[
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'usd_tether',
    'confirmedBalance': '10.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'naira_token',
    'confirmedBalance': '5357872.49'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'bitcoin',
    'confirmedBalance': '10.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'ethereum',
    'confirmedBalance': '20.0033'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'litecoin',
    'confirmedBalance': '640.0'
  },
  {
    'id': 'QWNjb3VudC0=',
    'cryptocurrency': 'usd_coin',
    'confirmedBalance': '309.75'
  }
]

Errors

Appropriate error responses are sent in the event of an unsuccessful request or insufficient data to complete or execute requests.

Last updated