Package: ticton
TicTon Python SDKThis 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.InstallationInstall the SDK using pip:pipinstallticton(Optional) Setting the Environment VariablesThe SDK requires several environment variables for its operation.You can set the environment variables using theexportcommand 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.exportTICTON_WALLET_MNEMONICS="word1 word2 word3 ... wordN"exportTICTON_WALLET_VERSION="v4r2"exportTICTON_ORACLE_ADDRESS="your_oracle_address"exportTICTON_TONCENTER_API_KEY="your_api_key"exportTICTON_THRESHOLD_PRICE=0.7InitializationIf you have already set the environment variables by using theexportcommand, you can easily initialize the ticton client using the following code:fromtictonimportTicTonAsyncClientclient=awaitTicTonAsyncClient.init()Alternatively, if you prefer not to set global environment variables, you can pass these directly to the initialization function:fromtictonimportTicTonAsyncClientclient=awaitTicTonAsyncClient.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 ExampleGetting Alarm Informationalarm_address="ABCDEFGHIJKLMNOPQRSTUVWXYZ"result=awaitclient.get_alarm_info(alarm_address)resultis a json object containing the following information:watchmaker_addressbase_asset_scalequote_asset_scaleremain_scalebase_asset_pricebase_asset_amountquote_asset_amountcreated_atGetting the Amount of Alarmsamount=awaitclient.get_alarms_amount()Checking the State of Alarmsalarm_id_list=[1,2]alarm_dict=awaitclient.check_alarms(alarm_id_list)Example output:alarm_dict={1:{"state":"active","address":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"},2:{"state":"unintialized","address":"BCDEFGHIJKLMNOPQRSTUVWXYZA"},}Ticktick will open a alarm with the given price and timeout, the total amount
of baseAsset and quoteAsset will be calculated automatically.Parametersprice: floatThe price of the alarm quoteAsset/baseAssettimeout: int (optional, default=1000)The timeout of the alarm in secondsextra_ton: float (optional, default=0.1)The extra ton to be sent to the oracleExampleAssume the token pair is TON/USDT, the price is 2.5 USDT per TONprice=2.5result=awaitclient.tick(price)Ringring will close the alarm with the given alarm_idParametersalarm_id: intThe alarm_id of the alarm to be closedExamplealarm_id=1result=awaitclient.ring(alarm_id)Windwind will arbitrage the alarm with the given alarm_id, buy_num and new_priceParametersalarm_id: intThe alarm_id of the alarm to be arbitragebuy_num: intThe number of tokens to be bought, at least 1.new_price: floatThe new price of the alarm quoteAsset/baseAssetExampleAssume 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=123buy_num=1new_price=5result=awaitclient.wind(alarm_id,buy_num,new_price)Subscribesubscribe will subscribe the oracle's transactions, handle the transactions and call the
given callbacks.Parameterson_tick_success: functionThe callback function to be called when the tick transaction is successful, with the following parameters:watchmaker: strbase_asset_price: floatnew_alarm_id: intcreated_at: inton_ring_success: functionThe callback function to be called when the ring transaction is successful, with the following parameters:alarm_id: intcreated_at: intorigin: strreceiver: stramount: inton_wind_success: functionThe callback function to be called when the wind transaction is successful, with the following parameters:timekeeper: stralarm_id: intnew_base_asset_price: floatremain_scale: intnew_alarm_id: intcreated_at: intstart_lt: int, "oldest", "latest" (optional, default="oldest")From when to yield transaction, default to replay the transaction from the oldest transactionExamplesasyncdefon_tick_success(params:OnTickSuccessParams):print(f"Tick success",params.model_dump())asyncdefon_ring_success(params:OnRingSuccessParams):print(f"Tick success",params.model_dump())asyncdefon_wind_success(params:OnWindSuccessParams):print(f"Tick success",params.model_dump())awaitclient.subscribe(on_tick_success,on_ring_success,on_wind_success)Development GuideInstallMake surepoetryinstalled on your machine.you may need to set thePATHenvironment variable to include the Poetry binary directory, e.g.export PATH="$HOME/.local/bin:$PATH"curl-sSLhttps://install.python-poetry.org|python3-Install plugin for poetrypoetryselfaddpoetry-bumpversion
poetryselfaddpoetry-plugin-exportInstall dependenciesmakeinstallStart your virtual environmentpoetryshellRun testspoetryrunpytest