⚙️Thales integration
Thales API
In order to ensure easy integration with external partners Thales API is created. API returns all main data available on Thales. Using Thales API endpoints someone can get data about:
Thales collaterals
Thales markets
Thales market
User Thales positions
User Thales transactions
Buy quote
Sell quote
More details about each API endpoint with request/response examples can be found under Postman documentation.
Contract integration
Once all data are fetched from API, the next step is integration with Thales contracts. Depending on whether someone wants to buy a position on Tokenized Positional Markets or Tokenized Ranged Markets integration should be done with ThalesAMM or RangedAMM contract.
The next sections describe integration with Thales API and Thales contracts together with JS code examples.
Buy a UP/DOWN position
Let's say someone wants to buy UP positional tokens on the BTC market with a strike price of 35000 on 7th November 2023 with a buy-in amount of 100 sUSD:

Integration with Thales API and Thales AMM contract should include the following steps:
Get a buy quote for the market from Thales API
Get a Thales AMM contract address for a specific network from Thales contracts
Get a Thales AMM contract ABI from Thales contract repository contract repository
Create Thales AMM contract instance
Call
buyFromAmmmethod on Thales AMM contract with input parameters fetched from Thales API in step #1
The JS code snippet below implements these steps:
Buy a IN/OUT position
Let's say someone wants to buy IN positional tokens on the BTC market with a range 34000-38000 on 7th November 2023 with a buy-in amount of 100 sUSD:

Integration with Thales API and Ranged AMM contract should include the following steps:
Get a buy quote for the market from Thales API
Get a Ranged AMM contract address for a specific network from Thales contracts
Get a Ranged AMM contract ABI from Thales contract repository contract repository
Create Ranged AMM contract instance
Call
buyFromAmmmethod on Ranged AMM contract with input parameters fetched from Thales API in step #1
The JS code snippet below implements these steps:
Last updated
Was this helpful?