Skip to main content

Inofficial Python SDK for consuming Tangany Settlement API

Project description

Tangany Settlement API Python SDK

Unofficial Python SDK for consuming Tangany Settlement API.

Installation

To install the SDK, you can use pip:

pip install tangany_settlement_api_sdk

Usage

Initialization

First, import the SDK:

from tangany_settlement_api_sdk import SettlementClient
from tangany_settlement_api_sdk.auth import Credentials

Initialize the SDK by providing API credentials and create a Settlement API client:

credentials = Credentials(client_id="xxx", client_secret="yyy")
api = SettlementClient(credentials=credentials)

Examples

There is a jupyter notebook file with all examples, here is an excerpt of some examples to demonstrate how to use the SDK:

Accounts

Create accounts

api.accounts.create(id="00000001", label="Satoshi Nakamoto's account", type="internal")

Update account label

api.accounts.update(id="00000001", op="replace", path="/label", value="Satoshi Nakamoto's HODL account")                                   

List all account ids

account_ids = []
next_page_token = ""

while next_page_token != None:
    results = api.accounts.list(next_page_token) 
    next_page_token = results['nextPageToken'] 
    for result in results['items']:
        account_ids.append(result['id'])

Delete accounts

api.accounts.delete(id="00000001")

Assets

Get all asset ids

api = SettlementClient(credentials=credentials)
asset_ids = []
for asset in api.assets.list()['items']:
    asset_ids.append(asset['id'])

Get a specific asset

result = api.assets.get(id="BTC")

Ledgers

Create ledger

api.ledgers.create("Test", "My test ledger")

List ledgers

result = api.ledgers.list()

Get a specific ledger

result = api.ledgers.get(id="Test")

Transactions

Create a virtual transaction

api.transactions.create(
    ledger_id="Test",
    transaction_id="TX_SAMPLE",
    from_account_id="00000001",
    to_account_id="00000002",
    value_date="2023-11-11T15:00:00.000Z",
    asset_id="BTC",
    value="1.0",
    fiat_currency="EUR",
    fiat_value="30000.00",
    reference="BTC-REF",
    trade_info_fill_date="2023-11-10T15:00:00.000Z",
    trade_info_market_maker_tx_id="123456789"    
)

Get a single transaction

result = api.transactions.get(ledger_id="Test", transaction_id="TX_SAMPLE")

Get all transactions for a specific account id

transactions = []
next_page_token = ""

while next_page_token != None:
    results = api.transactions.list(ledger_id="Test", involving_account_id="00000001", next_page_token=next_page_token)
    next_page_token = results['nextPageToken'] 
    for result in results['items']:
        transactions.append(result)

Get all transactions after a specific booking date

transactions = []
next_page_token = ""

while next_page_token != None:
    results = api.transactions.list(ledger_id="Test", booking_date_after="2023-11-11", next_page_token=next_page_token)
    next_page_token = results['nextPageToken'] 
    for result in results['items']:
        transactions.append(result)

Delete a single transaction (mark as cancelled)

api.transactions.delete(ledger_id="Test", transaction_id="TX_SAMPLE")

Fundings

Sync on-chain deposit as virtual transaction (create deposit)

api.funding_deposits.create(
    ledger_id="Test",
    transaction_id=f"TX_GENESIS",
    to_account_id="00000001",
    value_date="2023-11-11T15:00:00.000Z",
    asset_id="BTC",
    value="1.0",
    fiat_currency="EUR",
    fiat_value="30000.00",
    reference="BTC-REF",
    txHash="0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
)

List fundings

transactions = []
next_page_token = ""

while next_page_token != None:
    results = api.fundings.list(ledger_id="Test", next_page_token=next_page_token)
    next_page_token = results['nextPageToken'] 
    for result in results['items']:
        transactions.append(result)

Balances

List all account balances

account_balances = []
next_page_token = ""

while next_page_token != None:
    results = api.account_balances.list(ledger_id="Test", valuta_date="2023-11-12", next_page_token=next_page_token)
    next_page_token = results['nextPageToken'] 
    for result in results['items']:
        account_balances.append(result)

Get single account balance

result = api.account_balances.get(ledger_id="Test", account_id="00000001")

Get ledger balance of all assets

result = api.asset_balances.get(ledger_id="Test")

Reports

Create immediate report

api.reports.create(id="report1", type="account_balances_v1", format="csv", ledger_id="Test", date="2023-11-13")

List all reports

result = api.reports.list()

Get a single report

result = api.reports.get(id="report1")

List report results

result = api.report_results.list("report1")

Download a report

result = api.report_results.get(report_id="report1", result_id="2023-11-17T12:07:00Z")

Delete report

result = api.reports.delete(id="report1")

Changelog

All notable changes to this project are documented in the changelog

Testing

For testing provide your credentials to examples.ipynb and run the notebook.

Deployment

To release a new version of this SDK please update the version contained in the pyproject.toml file. After testing just use poetry to build and publish a new version to pypi.org:

poetry build
poetry publish

API documentation

Full API documentation is available at https://docs.tangany.com

Tangany




Project details


Download files

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

Source Distribution

tangany_settlement_api_sdk-0.1.8.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tangany_settlement_api_sdk-0.1.8-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file tangany_settlement_api_sdk-0.1.8.tar.gz.

File metadata

  • Download URL: tangany_settlement_api_sdk-0.1.8.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.1 Windows/10

File hashes

Hashes for tangany_settlement_api_sdk-0.1.8.tar.gz
Algorithm Hash digest
SHA256 c65698bca00d3bd29cc17f6d5c1bc918135e2993dc93a7dd807240e47a223065
MD5 9c6022db9ff23ef6c0771916acd3522e
BLAKE2b-256 bf556378e36fd18d97ea3b72c6bab62fd44b2bfda8d29ca396bcc33a957afa13

See more details on using hashes here.

File details

Details for the file tangany_settlement_api_sdk-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for tangany_settlement_api_sdk-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 3afd394275768eb962261e1f9ef11c8cd3d5048dc9a302163ac675daa3703aaf
MD5 d64f8bfaa43cd341fdd8278d51b82d50
BLAKE2b-256 e5e031c702bbe038cf0243e566e26453382026f0308059f9ed95a7c1db84d348

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page