Skip to main content

TicTon Python SDK

This is the Python SDK for Tic Ton Oracle on TON blockchain, which is a pure decentralized oracle protocol that can provide latest price with high precision guraranteed by incentive mechanism.

Installation

Install the SDK using pip:

pip install ticton

(Optional) Setting the Environment Variables

The SDK requires several environment variables for its operation.You can set the environment variables using the export command in your shell. Here are the variables you need to set:

  • TICTON_WALLET_MNEMONICS: A space-separated list of mnemonics used for wallet authentication and operations.
  • TICTON_WALLET_VERSION: Specifies the wallet version. Supported values are "v2r1", "v2r2", "v3r1", "v3r2", "v4r1", "v4r2", "hv2". The default is "v4r2".
  • TICTON_ORACLE_ADDRESS: The address of the oracle smart contract on the TON blockchain.
  • TICTON_TONCENTER_API_KEY: An API key for accessing TON blockchain data. You can apply for an API key at @tonapibot.
  • TICTON_THRESHOLD_PRICE: A float value that sets a threshold price, with a default of 0.7.
export TICTON_WALLET_MNEMONICS="word1 word2 word3 ... wordN"
export TICTON_WALLET_VERSION="v4r2"
export TICTON_ORACLE_ADDRESS="your_oracle_address"
export TICTON_TONCENTER_API_KEY="your_api_key"
export TICTON_THRESHOLD_PRICE=0.7

Initialization

If you have already set the environment variables by using the export command, you can easily initialize the ticton client using the following code:

from ticton import TicTonAsyncClient

client = await TicTonAsyncClient.init()

Alternatively, if you prefer not to set global environment variables, you can pass these directly to the initialization function:

from ticton import TicTonAsyncClient

client = await TicTonAsyncClient.init(
    wallet_mnemonics="word1 word2 word3 ... wordN",
    wallet_version="v4r2",
    oracle_address="your_oracle_address",
    toncenter_api_key="your_api_key",
    threshold_price=0.7
)

Usage Example

Use Case - Ticton Oracle Automation

Tick

tick will open a alarm with the given price and timeout, the total amount of baseAsset and quoteAsset will be calculated automatically.

Parameters

  • price : float
    • The price of the alarm quoteAsset/baseAsset
  • timeout : int (optional, default=1000)
    • The timeout of the alarm in seconds
  • extra_ton : float (optional, default=0.1)
    • The extra ton to be sent to the oracle

Example

Assume the token pair is TON/USDT, the price is 2.5 USDT per TON

price = 2.5

result = await client.tick(price)

Ring

ring will close the alarm with the given alarm_id

Parameters

  • alarm_id : int
    • The alarm_id of the alarm to be closed

Example

alarm_id = 1

result = await client.ring(alarm_id)

Wind

wind will arbitrage the alarm with the given alarm_id, buy_num and new_price

Parameters

  • alarm_id : int
    • The alarm_id of the alarm to be arbitrage
  • buy_num : int
    • The number of tokens to be bought, at least 1.
  • new_price : float
    • The new price of the alarm quoteAsset/baseAsset

Example

Assume the token pair is TON/USDT, the price is 2.5 USDT per TON. The alarm is opened with 1 TON and 2.5 USDT with index 123. The new price is 5 USDT per TON, the buy_num is 1.

alarm_id = 123
buy_num = 1
new_price = 5

result = await client.wind(alarm_id, buy_num, new_price)

Subscribe

subscribe will subscribe the oracle's transactions, handle the transactions and call the given callbacks.

Parameters

  • on_tick_success: function

    • The callback function to be called when the tick transaction is successful, with the following parameters:
      • watchmaker : str
      • base_asset_price : float
      • new_alarm_id : int
      • created_at : int
  • on_ring_success: function

    • The callback function to be called when the ring transaction is successful, with the following parameters:
      • alarm_id : int
      • created_at : int
      • origin : str
      • receiver : str
      • amount : int
  • on_wind_success: function

    • The callback function to be called when the wind transaction is successful, with the following parameters:
      • timekeeper : str
      • alarm_id : int
      • new_base_asset_price : float
      • remain_scale : int
      • new_alarm_id : int
      • created_at : int
  • start_lt: int, "oldest", "latest" (optional, default="oldest")

    • From when to yield transaction, default to replay the transaction from the oldest transaction

Examples

async def on_tick_success(params: OnTickSuccessParams):
    print(f"Tick success", params.model_dump())

async def on_ring_success(params: OnRingSuccessParams):
    print(f"Tick success", params.model_dump())

async def on_wind_success(params: OnWindSuccessParams):
    print(f"Tick success", params.model_dump())

await client.subscribe(on_tick_success, on_ring_success, on_wind_success)

Development Guide

Install

  1. Make sure poetry installed on your machine.

    you may need to set the PATH environment variable to include the Poetry binary directory, e.g. export PATH="$HOME/.local/bin:$PATH"

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Install plugin for poetry

    poetry self add poetry-bumpversion
    poetry self add poetry-plugin-export
    
  3. Install dependencies

    make install
    
  4. Start your virtual environment

    poetry shell
    
  5. Run tests

    poetry run pytest
    

Metadata

Release files for ticton 0.1.31

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ticton 0.1.31
File Size Uploaded Provenance Actions
ticton-0.1.31.tar.gz 16.6 kB Without provenance Details for ticton-0.1.31.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ticton 0.1.31
File Interpreter ABI Platform Actions
ticton-0.1.31-py3-none-any.whl Python 3 none any Details for ticton-0.1.31-py3-none-any.whl

Total release size: 33.3 kB

Release files / ticton-0.1.31.tar.gz

Download URL ticton-0.1.31.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cb65037cbfead435121e0df44983d335ccabfbde4c07d633b1c80d27bcf71abd
BLAKE2b-256 checksum
How to use checksums
b60f2916887437afffcb31a10070623c81d758d89e441959ef317f3e48ade97f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.0 Linux/6.5.0-1015-azure

Release files / ticton-0.1.31-py3-none-any.whl

Download URL ticton-0.1.31-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae1579651e5600ec738e888c66330455c7e0ecab038d0938f0859a37ac37c904
BLAKE2b-256 checksum
How to use checksums
f41833818333f41bf9b03c4fd28d81db570ff50750da5a38b791ffdc0107a244
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.0 Linux/6.5.0-1015-azure

Security for ticton 0.1.31

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page