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
© 2023 Tangany GmbH
Imprint • Legal & privacy • Newsletter • Twitter • Facebook • LinkedIn • YouTube • Github
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
Built Distribution
Hashes for tangany_settlement_api_sdk-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6521e1681d24457bc54e05aad4621f5d9358ac62d9817c42d05b809fe14894 |
|
MD5 | 4a9cb52c45f00b4124452dfadb06ea47 |
|
BLAKE2b-256 | 4287b46d53f4ab1dad1f96b5a9d5904bc65deba4d7487b2c20bd6f463ee8ae19 |
Hashes for tangany_settlement_api_sdk-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8ce01a063f2261f13dd1af3594a2fcd3768a5cdd7393bf0388f9b42c50c1a7a |
|
MD5 | 484d9ae0e09525d3f3747d32a010dc15 |
|
BLAKE2b-256 | e2e575d3a8080f5ff02c051b376fdfce07389598329a1423937bad5fd541765d |