Skip to main content

Python client of Blocktrades Public API

Project description

## Getting started

[Blocktrades Restler API Explorer](https://blocktrades.us/api/v2/explorer/#)

Install the package:

```python
pip install blocktrades
pip install blocktrades -U
```

## How to use blocktrades

All packages can be imported as follows.

```python
>>> from blocktrades_base.http_client import HttpClient
>>> from blocktrades_base.utils import get_active_wallets_by_type
>>> from blocktrades.convert import *
>>> from blocktrades.convert import __all__
>>> from blocktrades.blocktrades import (Session, Coin, Balance,
Citizenship, Bank, Wallet, Convert, User)
>>> from blocktrades.operation import Op
```

#### HttpClient class
We can use this class to get parameters and send request from *Blocktrades API services*.

```python
>>> from blocktrades_base.http_client import HttpClient
>>> client = HttpClient(**kwargs)
>>> client.get(api_address:str)
# get request
>>> client.post(api_address:str, data:dict | default None)
# post request
>>> client.put(api_address:str, data:dict | default None)
# put request
>>> client.delete_requets(api_address:str)
# delete request

```

#### get_active_wallets_by_type
Using this function we can see the active wallet types.
```python
>>> from blocktrades_base.utils import get_active_wallets_by_type
>>> for wallet_type in get_active_wallets_by_type():
>>> print(wallet_type)
# btc
# bch
# bts
# dash
# doge
# eth
# ltc
# xmr
# omni
# steem
# sbd
# delegated_steem_power_90_days

```

#### Convert class;

If you want to see all convert functions, you should write like this to see all functions, there are **132 functions**,
you can use all

```python
>>> from blocktrades.convert import __all__
>>> from blocktrades.convert import *
>>> for func in __all__:
>>> print(func)
```

For example;
```python
>>> steem_to_sp(10)
>>> ltc_to_steem(1)
>>> btc_to_ltc(1)
>>> doge_to_sbd(10000)
# run all convert function
>>> for i in __all__:
>>> exec(f"print({i}(1))")
```


#### Session Class

I've written how to use each function in all functions,
so you can learn how to use it by writing a code like the one below.

```python
>>> from blocktrades.blocktrades import Session
>>> session = Session(session_token:str)
>>> session.session
>>> Session.session.__doc__
# >>> session = Session(session_token:str)
# >>> session.session
#
# Implementation Notes;
# "Get information about the specified session"
#
# Model Schema;
# {
# "token": "",
# "user": {
# "email": "",
# "userId": "",
# "timeZone": "",
# "activated": false,
# "creationTime": "",
# "lastModifiedTime": "",
# "lastLoginTime": ""
# },
# "expirationTime": ""
# }
>>> session = Session(session_token:str)
>>> session.invalid_method
>>> Session.invalid_method.__doc__
# >>> session = Session(session_token:str)
# >>> session.invalid_method
#
# Implementation Notes;
# "Test invalid method"
>>> session = Session(session_token:str)
>>> session.user_details
>>> Session.user_details.__doc__
# >>> session = Session(session_token:str)
# >>> session.user_details
#
# Implementation Notes;
# "Get user details"
>>> session = Session(email:str, password:str)
>>> session.create
>>> Session.create.__doc__
# >>> session = Session(email:str, password:str)
# >>> session.create
#
# Implementation Notes;
# "To login as an existing user, specify a username and password.
# To create a new unregistered session, leave the username, and password null."
>>> session = Session(session_token:str, first_name:str, last_name:str, date_of_birth:str, place_of_birth:str,
national_id_number:str, national_id_type:str)
>>> session.create_user_details
>>> session = Session(session_token:str, old_password:str, new_password:str, email:str)
>>> session.update_user_credentials
>>> session = Session(session_token:str, first_name:str, last_name:str, date_of_birth:str, place_of_birth:str,
national_id_number:str, national_id_type:str)
>>> session.update_user_details
>>> session = Session(session_token:str)
>>> session.delete

```

#### Coin Class

```python
>>> from blocktrades.blocktrades import Coin
>>> coin = Coin()
>>> coin.coins
>>> Coin.coins.__doc__
# >>> coin = Coin()
# >>> coin.coins
# Implementation Notes;
# "Returns detailed info about each of the cryptocoin types supported by *BlockTrades*"
>>> coin = Coin(coin_type:str)
>>> coin.coin
>>> Coin.coin.__doc__
# >>> coin = Coin(coin_type:str)
# >>> coin.coin
# Implementation Notes;
# "Returns detailed info about a specific coin type including users' declarations"
```

#### Balance class

```python
>>> from blocktrades.blocktrades import Balance
>>> balance = Balance(session_token:str)
>>> balance.balances
# Returns all user's affiliate balances
>>> balance = Balance(coin_type:str, session_token:str)
>>> balance.balance
# Returns detailed info about a selected user's affiliate balance
>>> balance = Balance(coin_type:str, rate_fee:str, session_token:str)
>>> balance.set_rate_fee
# Set the affiliate rate fee on a given coin type
>>> balance = Balance(
coin_type:str, amount_to_withdraw:str, receive_address:str,
receive_memo:str, output_coin_type:str, session_token:str
)
>>> balance.withdraw
# Allow an affiliate to withdraw some or all of their balance in a coin type
```

#### Citizenship class

```python
>>> from blocktrades.blocktrades import Citizenship
>>> citizenship = Citizenship(session_token:str)
>>> citizenship.citizenship
# Returns info of user's citizenships
>>> citizenship = Citizenship()
>>> citizenship.countries
# Returns list of all countries
>>> citizenship = Citizenship(country_id:str, session_token:str)
>>> citizenship.country
# Returns info about a specific user's citizenship
>>> citizenship = Citizenship(country_id:str, is_primary:str, session_token:str)
>>> citizenship.create
# Create New User's citizenship
>>> citizenship = Citizenship(country_id:str, new_country_id:str, is_primary:str, session_token:str)
>>> citizenship.update
# Update Existing User's Ctizenship
>>> citizenship = Citizenship(country_id:str, session_token:str)
>>> citizenship.delete
# Delete Given User's Citizenship
```

#### Bank class

```python
>>> from blocktrades.blocktrades import Bank
>>> bank = Bank(full:bool | default True, session_token:str)
>>> bank.banks
# Returns list of all user's bank accounts
>>> bank = Bank()
>>> bank.currencies
# Returns list of all currencies
>>> bank = Bank(country_id:str, cy_id:str)
>>> bank.rule
# Returns best matching rule for showing/hiding fields of
# Bank Account for given country and currency
>>> bank = Bank()
>>> bank.rules
# Returns rules for showing/hiding fields of Bank Account depending
# on country and currency
>>> bank = Bank(create:bool | default True)
>>> bank.validations
# Returns validation information for fields of Bank Account
>>> bank = Bank(bank_account_id:str, session_token:str)
>>> bank.bank
# Returns validation information for fields of Bank Account
>>> bank = Bank(nick_name:str, currency_id:str, account_holder:str, account_number:str,
iban:str, bank_name:str, sort_code:str, routing_number:str, swift_bic:str, ifsc_code:str, routing_code:str,
user_address_id:str, country_id:str, zip:str, city:str, administrative_area:str, dependent_locality:str,
sorting_code:str, organization:str, address_line1:str, address_line2:str, session_token:str )
>>> bank.create
# Create New User's Bank Account.
>>> bank = Bank(nick_name:str, currency_id:str, account_holder:str, account_number:str,
iban:str, bank_name:str, sort_code:str, routing_number:str, swift_bic:str, ifsc_code:str, routing_code:str,
user_address_id:str, country_id:str, zip:str, city:str, administrative_area:str, dependent_locality:str,
sorting_code:str, organization:str, address_line1:str, address_line2:str, session_token:str)
>>> bank.update
# Update Exisiting User's Bank Account
>>> bank = Bank(account_id:str, session_token:str)
>>> bank.delete
# Delete Given User's Bank Account
```

#### Wallet class

```python
>>> from blocktrades.blocktrades import Wallet
>>> wallet = Wallet()
>>> wallet.active_wallets
# This returns a list of walletTypes
>>> wallet = Wallet()
>>> wallet.wallets
# Returns the list of wallets supported by *BlockTrades*
>>> wallet = Wallet(wallet_type='steem')
>>> wallet.wallet
# Returns information about a single specific wallet
>>> wallet = Wallet(wallet_type:str, address:str, request_balances:bool | default True)
>>> wallet.wallet_validator
# Validate whether an address is valid for a given wallet.
```

#### Convert class

```python
>>> from blocktrades.blocktrades import Convert
>>> convert = Convert(amount:float, input_type:str, output_type:str)
>>> convert.estimate_output_amount
>>> convert = Convert(amount:float, input_type:str, output_type:str)
>>> convert.estimate_input_amount
```

#### User class

```python
>>> from blocktrades.blocktrades import User
>>> user = User(session_token:str)
>>> user.get_user
# You can only get user details when logged in as that user.
# This call works for both registered and unregistered sessions.
>>> user = User(email:str, password:str, session_token:str)
>>> user.register_user
# This registers a new user with the given username and password. The newly-registered
# user is initally inactive. The user will be sent an email with a validation link to
# verify that they own the email address. Once they click on the validation link,
# they will be able to login.
>>> user = User(email:str)
>>> user.forgot_password
# When a new user forgot password, BlockTrades sends a restoring email with a link.
# The user clicks on to restore password.
>>> user = User(user_id:str, restoration_id:str)
>>> user.restore_password
# When a user clicks link from restoring email, then user has possibility of changing password.
>>> user = User(user_id:str, validation_id:str)
>>> user.validate_email
# When a new user is created, BlockTrades sends a validation email with a link.
# The user clicks on to verify that they own the email address.
```

```
# TODO Class Address
# TODO Class Announcement
# TODO Class Aeclaration
# TODO Class Delegation
# TODO Class InputAddress
# TODO Class TradingPairs
# TODO Class DepositLimit
# TODO Class Mapping
# TODO Class OutputAddress
# TODO Class Transaction
# TODO Class InitiateTrade
# TODO Class InitiateFixedPriceRrade
# TODO Class Transaction
# TODO Class Crowdfund
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for blocktrades, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size blocktrades-0.0.5.tar.gz (9.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page