Python SDK for the Buycoins API.

Overview

Buycoins Python Library

Build Status Circle CI PyPI version Python 3.6+

This library provides easy access to the Buycoins API using the Python programming language. It provides all the feature of the API so that you don't need to interact with the API directly. This library can be used with Python 3.6+

Table of Contents

Links

Installation

You can install this package using pip:

pip install --upgrade buycoins

Introduction

Primer

  • The library is structured around the concept of a type, so everything is a type.
  • All date quantities are specified as timestamps. So you would have to reconstruct the ISO dates yourself if you ever need to.
  • All cryptocurrency (and monetary) values are specified as decimals.
  • Supports all cryptocurrencies supported by Buycoins

Initialization

Firstly, request API access by sending an email to [email protected] with the email address you used in creating a Buycoins account. When you've been granted access, you should be able to generate a public and secret key from the 'API settings' section of your account.

You have to initialize the library once in your app. You can do this when initializing databases, logging, etc. As a security practice, it is best not to hardcode your API keys. You should store them in environmental variables or a remote Secrets Manager.

import buycoins

buycoins.initialize('', '')

Accounts

Accounts provide a way to programmatically create virtual naira accounts.

Types

VirtualDepositAccountType:
    account_number: str
    account_name: str
    account_type: str
    bank_name: str
    account_reference: str

Create Naira deposit account

import buycoins as bc

acc = bc.accounts.create_deposit('john doe')  # VirtualDepositAccountType

print(acc.account_name)  # john doe
print(acc.bank_name)  # bank name
print(acc.account_number)  # account number
print(acc.account_reference) # account reference
print(acc.account_type) # account type

Orders

Orders provide a way to buy from and sell directly to Buycoins. When buying or selling, price ID should be the ID gotten from calling either .get_price() or .get_prices(). Make sure to use price that hasn't expired yet, so call .get_price(cryptocurrency) to get the latest price for the cryptocurrency just before buying or selling.

Types

CoinPriceType:
    id: str
    cryptocurrency: str
    buy_price_per_coin: Decimal
    min_buy: Decimal
    max_buy: Decimal
    expires_at: int

class OrderType(NamedTuple):
    id: str
    cryptocurrency: str
    status: str
    side: str
    created_at: int
    total_coin_amount: str
    static_price: Decimal
    price_type: str
    dynamic_exchange_rate: str
    coin_amount: Decimal

Get cryptocurrency prices

import buycoins as bc

# Get prices of all cryptocurrencies
prices = bc.orders.get_prices()  # CoinPriceType[]

print(prices[0].id)  # ID of first price entry
print(prices[0].cryptocurrency)  # cryptocurrency
print(prices[0].expires_at)  # when this price entry will expire
print(prices[0].buy_price_per_coin)  # coin price
print(prices[0].min_buy)  # minimum amount you can buy
print(prices[0].max_buy)  # max amount you can buy

Get single cryptocurrency price

import buycoins as bc

price = bc.orders.get_price('bitcoin')  # CoinPriceType

print(price.id)  # ID of price entry
print(price.cryptocurrency)  # cryptocurrency
print(price.expires_at)  # when this price entry will expire
print(price.buy_price_per_coin)  # coin price
print(price.min_buy)  # minimum amount you can buy
print(price.max_buy)  # max amount you can buy

Buy a cryptocurrency

import buycoins as bc


order = bc.orders.buy(
    price_id='price-id',
    coin_amount=1.52,
    cryptocurrency='litecoin'
)  # OrderType

print(order.id)  # Order ID
print(order.status)  # either active or inactive
print(order.side)  # buy
print(order.cryptocurrency)  # litecoin
print(order.total_coin_amount)  # Total coin amount
print(order.price_type)  # Price type

Sell a cryptocurrency

import buycoins as bc


order = bc.orders.sell(
    price_id='price-id',
    coin_amount=0.0043,
    cryptocurrency='ethereum'
)  # OrderType

print(order.id)  # Order ID
print(order.status)  # either active or inactive
print(order.side)  # sell
print(order.cryptocurrency)  # litecoin
print(order.total_coin_amount)  # Total coin amount
print(order.price_type)  # Price type

P2P Trading

P2P Trading lets you trade cryptocurrencies with other users. If you are not familiar with p2p trading on the Buycoins platform, read about it here

Types

class OrderType(NamedTuple):
    id: str
    cryptocurrency: str
    status: str
    side: str
    created_at: int
    total_coin_amount: str
    static_price: Decimal
    price_type: str
    dynamic_exchange_rate: str
    coin_amount: Decimal

Place limit orders

When placing limit orders, if price_type is static, static_price must also be specified, and if price_type is dynamic, dynamic_exchange_rate must be provided.

import buycoins as bc


order = bc.p2p.place_limit_order(
    side='buy', # either 'buy' or 'sell'
    coin_amount=0.00043,
    cryptocurrency='ethereum',
    price_type='static',
    static_price=0.004,
    dynamic_exchange_rate=None  # float   
)  # OrderType

print(order.id)  # Order ID
print(order.status)  # status, either active or inactive
print(order.cryptocurrency)  # bitcoin, litecoin, etc
print(order.coin_amount)  # coin amount

Place market orders

import buycoins as bc


# Place market order
# `order` has all the properties as shown above
order = bc.p2p.place_market_order(
    side='buy',  # either buy or sell
    coin_amount=0.00023,
    cryptocurrency='litecoin'
)  # order is an OrderType

print(order.id)  # Order ID
print(order.status)  # status, either active or inactive
print(order.cryptocurrency)  # bitcoin, litecoin, etc
print(order.coin_amount)  # coin amount

Get list of orders

import buycoins as bc


orders, dynamic_price_expiry = bc.p2p.get_orders('active')  # (OrderType[], timestamp)

print(dynamic_price_expiry)  # timestamp of when dynamic price expires
print(orders[0].id)  # ID of first order
print(orders[1].status)  # status of the first order

Get Market book

import buycoins as bc


market_book, dynamic_price_expiry = bc.p2p.get_market_book()  # (OrderType[], timestamp)

print(dynamic_price_expiry)  # timestamp of when dynamic price expires
print(market_book[0].id)  # ID of first order
print(market_book[1].status)  # status of the first order

Transactions

Transactions enable you to send and receive cryptocurrencies.

Types

CoinBalanceType:
    id: str
    cryptocurrency: str
    confirmed_balance: Decimal

NetworkFeeType:
    estimated_fee: Decimal
    total: Decimal

TransactionType:
    hash: str
    id: str

SendReturnValueType:
    id: str
    address: str
    cryptocurrency: str
    amount: Decimal
    fee: Decimal
    status: str
    transaction: TransactionType

AddressType:
    cryptocurrency: str
    address: str

Get balances

import buycoins as bc

balances = bc.transactions.get_balances()  # CoinBalanceType[]

print(balances[0].cryptocurrency)  # bitcoin, litecoin, etc
print(balances[0].confirmed_balance)  # the confirmed balance

Get single balance

import buycoins as bc


balance = bc.transactions.get_balance('bitcoin')  # CoinBalanceType

print(balance.cryptocurrency)  # bitcoin
print(balance.confirmed_balance)  # the confirmed balance

Estimate network fee

import buycoins as bc


fee = bc.transactions.estimate_network_fee(
    'bitcoin',  # cryptocurrency
    0.32,  # txn amount
)  # NetworkFeeType

print(fee.estimated_fee)  # estimated fee for txn
print(fee.total)   # total

Send cryptocurrency to an address

import buycoins as bc


sent = bc.transactions.send(
    cryptocurrency='ethereum',
    amount=0.0023,
    address=''
)  # SendReturnValueType

print(sent.fee)  # fee charged for the 'send' txn
print(sent.status) # status of the txn
print(sent.transaction.id)  # ID of the txn
print(sent.transaction.hash)  # txn hash

Create wallet address

import buycoins as bc


addr = bc.transactions.create_address('bitcoin')  # AddressType

print(addr.address)  # Address string
print(addr.cryptocurrency)  # cryptocurrency

Webhooks

Webhooks provides a way for Buycoins to inform you of events that take place on your account. See the Buycoins documentation for an introduction and the available events.

Verify event payload

Ensure that the webhook event originated from Buycoins

import buycoins as bc


is_valid = bc.webhook.verify_payload(
    body='',
    webhook_token='',
    header_signature='X-Webhook-Signature header'
)

print(is_valid)  # True if the event is from Buycoins, False otherwise.

Testing

To run tests:

poetry run pytest

Contributing

See CONTRIBUTING.md

License

MIT License

You might also like...
Python SDK for accessing the Hanko Authentication API

Hanko Authentication SDK for Python This package is maintained by Hanko. Contents Introduction Documentation Installation Usage Prerequisites Create a

Balsam Python client API & SDK

balsam No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) This Python package is automatically

Python SDK for interacting with the Frame.io API.
Python SDK for interacting with the Frame.io API.

python-frameio-client Frame.io Frame.io is a cloud-based collaboration hub that allows video professionals to share files, comment on clips real-time,

DongTai API SDK For Python

DongTai-SDK-Python Quick start You need a config file config.json { "DongTai":{ "token":"your token", "url":"http://127.0.0.1:90"

Python 3 SDK/Wrapper for Huobi Crypto Exchange Api

This packages intents to be an idiomatic PythonApi wrapper for https://www.huobi.com/ Huobi Api Doc: https://huobiapi.github.io/docs Showcase TODO Con

A wrapper for aqquiring Choice Coin directly through a Python Terminal. Leverages the TinyMan Python-SDK.

CHOICE_TinyMan_Wrapper A wrapper that allows users to acquire Choice Coin directly through their Terminal using ALGO and various Algorand Standard Ass

AWS SDK for Python

Boto3 - The AWS SDK for Python Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to wri

Box SDK for Python

Box Python SDK Installing Getting Started Authorization Server-to-Server Auth with JWT Traditional 3-legged OAuth2 Other Auth Options Usage Documentat

Evernote SDK for Python

Evernote SDK for Python Evernote API version 1.28 This SDK is intended for use with Python 2.X For Evernote's beta Python 3 SDK see https://github.com

Comments
  • chore: update deprecated API queries

    chore: update deprecated API queries

    The following graphQL queries previously covered by the buycoins public api have had their functionality deprecated.

    1. cancelWithdrawal
    2. createWithdrawal
    3. createDepositAccount
    4. getBankAccounts

    Please update the README.md documentation reflecting these changes, remove the queries and the library's interface to them, or mark them deprecated. You can learn more about the changes to withdrawals and deposit accounts in the documentation.

    opened by hailelagi 0
  • ModuleNotFoundError: No module named 'gql.transport.exceptions'

    ModuleNotFoundError: No module named 'gql.transport.exceptions'

    This is what happens when I try to import the library:

    >>> import buycoins as bc
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.7/site-packages/buycoins/__init__.py", line 3, in <module>
        from .client import initialize
      File "/usr/local/lib/python3.7/site-packages/buycoins/client.py", line 6, in <module>
        from gql.transport.exceptions import TransportQueryError, TransportServerError
    ModuleNotFoundError: No module named 'gql.transport.exceptions'
    

    I've tried both python 3.6.5 & 3.7.0

    opened by timigod 4
Owner
Musa Rasheed
Software Engineer at @textkernel
Musa Rasheed
This package allows interactions with the BuyCoins API.

The BuyCoins Python library allows interactions with the BuyCoins API from applications written in Python.

Abdulazeez Abdulazeez Adeshina 45 May 23, 2022
Graviti-python-sdk - Graviti Data Platform Python SDK

Graviti Python SDK Graviti Python SDK is a python library to access Graviti Data

Graviti 13 Dec 15, 2022
Python SDK for Facebook's Graph API

Facebook Python SDK This client library is designed to support the Facebook Graph API and the official Facebook JavaScript SDK, which is the canonical

Mobolic 2.7k Jan 7, 2023
The Official Dropbox API V2 SDK for Python

The offical Dropbox SDK for Python. Documentation can be found on Read The Docs. Installation Create an app via the Developer Console. Install via pip

Dropbox 828 Jan 5, 2023
Unofficial Medium Python Flask API and SDK

PyMedium - Unofficial Medium API PyMedium is an unofficial Medium API written in python flask. It provides developers to access to user, post list and

Engine Bai 157 Nov 11, 2022
qualysclient - a python SDK for interacting with the Qualys API

qualysclient - a python SDK for interacting with the Qualys API

null 5 Oct 28, 2022
A Python 2.7/3.x module for Amcrest Cameras using the SDK HTTP API.

A Python 2.7/3.x module for Amcrest Cameras using the SDK HTTP API. Amcrest and Dahua devices share similar firmwares. Dahua Cameras and NVRs also work with this module.

Marcelo Moreira de Mello 176 Dec 21, 2022
An Python SDK for QQ based on mirai-api-http v2.

Argon 一个基于 graia-broadcast 和 mirai-api-http v2 的 Python SDK。 本项目适用于 mirai-api-http 2.0 以上版本。 目前仍处于开发阶段,内部接口可能会有较大的变化。 The Stasis / 停滞 为维持 GraiaProject

BlueGlassBlock 1 Oct 29, 2021
An elegant mirai-api-http v2 Python SDK.

Ariadne 一个适用于 mirai-api-http v2 的 Python SDK。 本项目适用于 mirai-api-http 2.0 以上版本。 目前仍处于开发阶段,内部接口可能会有较大的变化。 安装 poetry add graia-ariadne 或 pip install graia

Graia Project 259 Jan 2, 2023