BuyCoins API library
Project description
BuyCoins API library
A Python module for interacting with buyCoins API. See official documentation
Getting started
Installation via Pip:
$ pip install python-buycoins
This module consists of a Query class and a Mutation class. The Query class contains all queries in the API while the Mutation class contains all mutations in the API.
The Query class has the following methods:
- get_bank_accounts()
- get_balances()
- get_estimated_network_fee()
- get_market_book()
- get_orders()
- get_payments()
- get_prices()
...and the Mutation class has the following:
- buy()
- cancel_withdrawal()
- create_address()
- create_deposit_account()
- create_withdrawal()
- post_limit_order()
- post_market_order()
- sell()
- send()
- send_off_chain()
Authentication
You should place PUBLIC_KEY
and PRIVATE_KEY
in your .env file as seen in .env.example
Usage
from buycoins import Executor, Query, Mutation
# Instantiate the classes:
que = Query()
mut = Mutation()
# Example queries
data = que.get_balances() # get balances
data = que.get_bank_accounts() # get account details
# Example mutations
data = mut.buy(0.03) # buy 0.03 worth of bitcoin
data = mut.create_address() # create a bitcoin address to receive
# Wanna execute your own queries? Use the Executor() class
# If PUBLIC_KEY and PRIVATE_KEY is already in .env, do this:
exe = Executor()
# Else:
exe = Executor(PUBLIC_KEY, PRIVATE_KEY)
data = exe.query(query_str, variables)
All methods have an optional query
argument. You need not worry about passing this argument because by the default value is sufficient and returns all fields. All query strings are defined in the constants.py
file.
Method Signature
Queries
get_balances(self, cryptocurrency=None, query=GET_BALANCES)
Retrieve supported cryptocurrencies account balance.
Valid cryptocurrency values are: usd_tether, naira_token, bitcoin, ethereum, litecoin, usd_coin.
get_bank_accounts(self, account_number=None, query=GET_BANK_ACCOUNTS)
Retrieve bank accounts.
get_estimated_network_fee(self, amount, cryptocurrency="bitcoin", query=GET_ESTIMATED_NETWORK_FEE)
Retrieve estimated network fee to send supported cryptocurrencies.
get_market_book(self, coin_amount=None, cryptocurrency="bitcoin", query=GET_MARKET_BOOK)
Retrieve a list of orders on the peer-to-peer (P2P) platform.
get_orders(self, status, side=None, cryptocurrency="bitcoin", query=GET_ORDERS)
Retrieve a list of orders.
side takes either buy or sell.
status takes either open or completed.
get_payments(self, query=GET_PAYMENTS)
Retrieve a list of payments.
get_prices(self, side=None, cryptocurrency=None, query=GET_PRICES)
Retrieve buy/sell price(s) for supported cryptocurrencies.
Mutations
buy(self, coin_amount, price=None, cryptocurrency="bitcoin", query=BUY)
Buy supported cryptocurrencies. If price is not specified, it fetches an active price internally.
cancel_withdrawal(self, payment, query=CANCEL_WITHDRAWAL)
Cancel initiated withdrawal. The ID of the payment to be cancelled should be passed in as the payment parameter.
create_address(self, cryptocurrency="bitcoin", query=CREATE_ADDRESS)
Create address to receive supported cryptocurrencies.
create_deposit_account(self, account_name, query=CREATE_DEPOSIT_ACCOUNT)
Generate deposit bank accounts to top up your NGNT account with Naira.
create_withdrawal(self, amount, account_id=None, account_number=None, query=CREATE_WITHDRAWAL)
Create a new withdrawal. This requires the ID of the bank to withdraw to. You can easily get that using get_bank_accounts(). Whatever ID obtained from calling get_bank_accounts() should be specified as account_id. However, this method allows you to specify an account number (specified as value to account_number) and the account ID will be fetched internally. If you specify both account_id and account_number, an exception is thrown.
post_limit_order(self, order_side, coin_amount, price_type, cryptocurrency="bitcoin", static_price=None, dynamic_exchange_rate=None, query=POST_LIMIT_ORDER)
Create a new limit order.
order_side should be either buy or sell
price_type should be either static or dynamic
static_price and dynamic_exchange_rate depends on the value of price_type. If price_type is static, then static_price is required. If price_type is dynamic, dynamic_exchange_rate is required.
post_market_order(self, order_side, coin_amount, cryptocurrency="bitcoin", query=POST_MARKET_ORDER)
Create a new market order.
sell(self, coin_amount, price=None, cryptocurrency="bitcoin", query=SELL)
Sell supported cryptocurrencies. If price is not specified, it fetches an active price internally.
send(self, amount, address, cryptocurrency="bitcoin", query=SEND)
Send supported cryptocurrencies to external address.
send_off_chain(self, amount, recipient, cryptocurrency="bitcoin", query=SEND_OFF_CHAIN)
Send supported cryptocurrencies to internal BuyCoins users.
Running tests
To run tests, do:
pytest -sv
License
(c) 2021 Immanuel Kolapo
This repository is licensed under the MIT license. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-buycoins-1.0.tar.gz
.
File metadata
- Download URL: python-buycoins-1.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afd986e91775a1d1e95c09531c09fcc5e76c4a1b55e6cdcf37e9f8e74f7c9d95 |
|
MD5 | 87cfaa3500b4d7cc550a9bde634d25b2 |
|
BLAKE2b-256 | d9c6a9d7900d72cfb0c650b41010fc0521b2a19cc43937642cd7df82da7a7cd6 |
File details
Details for the file python_buycoins-1.0-py3-none-any.whl
.
File metadata
- Download URL: python_buycoins-1.0-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3fdf68c2578a672a8795950f14dec337abf83b07bc409ea1734b8d337f6001 |
|
MD5 | 9baeaf010280a00019099717b1ab6df6 |
|
BLAKE2b-256 | d7143ae59206b71d600734b191fafe098ac95e1f23d7b37257e24cbcdcf4e9f8 |