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

Owner
Musa Rasheed
Software Engineer at @textkernel
Musa Rasheed
🌶️ Give real chat boosting to your discord server.

Chat-Booster Give real chat boosting to your discord server. ✅ Setup: - Add token to scrape messages on server that you whant. - Put the token in

&! Ѵιchy.#0110 36 Nov 04, 2022
Source code of BobuxAdmin bot from Bobux Bot Development server.

BobuxAdmin Source code of BobuxAdmin bot from Bobux Bot Development server. The bot is written with usage of disnake and SQLite database. Functionalit

Bobux Bot Developers 3 Dec 29, 2022
Os-Remoter with Python (Telegram Bot)

Remote-Os Os-Remoter with Python (Telegram Bot) [1] First install "python -m pip install --upgrade pip" [2] Second install the modules inside file ins

Alisa Alikhani 2 Nov 09, 2022
A Python script that wraps the gitleaks tool to enable scanning of multiple repositories in parallel

mpgitleaks A Python script that wraps the gitleaks tool to enable scanning of multiple repositories in parallel. The motivation behind writing this sc

Emilio Reyes 7 Dec 29, 2022
LoL API is a Python application made to serve League of Legends data.

LoL API is a Python application made to serve League of Legends data.

Caique Cunha Pereira 1 Nov 06, 2021
A tool for extracting plain text from Wikipedia dumps

WikiExtractor WikiExtractor.py is a Python script that extracts and cleans text from a Wikipedia database dump. The tool is written in Python and requ

Giuseppe Attardi 3.2k Dec 31, 2022
MSE5050/7050 Materials Informatics course at the University of Utah

MaterialsInformatics MSE5050/7050 Materials Informatics course at the University of Utah This github repo contains coursework content such as class sl

41 Dec 30, 2022
PokemonGo-Bot - The Pokemon Go Bot, baking with community.

PokemonGo-Bot PokemonGo-Bot is a project created by the PokemonGoF team. Since no public API available for now, a patch to use HASH-Server was applied

3.8k Jan 08, 2023
checks anilist for available usernames (200rq/s)

Anilist checker Running the program Set a path to the extracted files Install the packages with pip install -r req.txt Run the script by typing python

gxzs 1 Oct 13, 2021
VALORANT rank yoinker lets you retrieve the ranks and basic informations of everyone in the lobby, regardless of gamemode.

vRY VALORANT rank yoinker Retrieve the rank and basic information of everyone in the lobby, regardless of gamemode. Table of Contents Terms of Use Abo

Isaac Kenyon 270 Dec 30, 2022
This repository contains Python code examples using the MoneyMoov API

Python Examples This repository contains Python code examples using the MoneyMoov API. The examples are written to operate in the NoFrixion sandbox en

nofrixion 1 Feb 08, 2022
A stable telegram bot to get restricted messages with custom thumbnail support

Save restricted content Bot A stable telegram bot to get restricted messages with custom thumbnail support

DEVANSH 3 Feb 09, 2022
Polar devices Python API and CLI.

loophole - Polar devices API About Python API for Polar devices. Command line interface included. Tested with: A360 Loop M400 Installation pip install

[roscoe] 145 Sep 14, 2022
Telegram Auto Filter Bot

Pro Auto Filter Bot V2.o Hey Mo Tech, I'm an Autofilter bot v2.O and you can not Add Me to your Group. I was made for this one group. So don't waste y

14 Oct 20, 2021
Linky bot, A open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

LinkyBot Linky bot, An open-source discord bot that allows you to add links to ur website, youtube url, etc for the people all around discord to see!

AlexyDaCoder 1 Sep 20, 2022
📈 A Discord bot for displaying the download stats of a repository made with Python, the Hikari API and PostgreSQL.

📈 axyl-stats axyl-stats is a Discord bot made with Python (with the Hikari API wrapper) and PostgreSQL, used as a download counter for a GitHub repo.

Angelo-F 2 May 14, 2022
Music bot because Octave is down and I can : )

Chords On a mission to build the best Discord Music Bot View Demo · Report Bug · Request Feature Table of Contents About The Project Built With Gettin

Aman Prakash Jha 53 Jan 07, 2023
⚡ A really fast and powerful Discord Token Checker

discord-token-checker ⚡ A really fast and powerful Discord Token Checker How To Use? Do pip install -r requirements.txt in your command prompt Make to

vida 25 Feb 26, 2022
Apps related to Odoo it's calendar features

calendar Apps related to Odoo it's calendar/appointments features: online_appointment_locations: allow setting an online URL per employee online_appoi

Yenthe Van Ginneken 3 Oct 27, 2022
Python linting made easy. Also a casual yet honorific way to address individuals who have entered an organization prior to you.

pysen What is pysen? pysen aims to provide a unified platform to configure and run day-to-day development tools. We envision the following scenarios i

Preferred Networks, Inc. 452 Jan 05, 2023