Swap
Swap tokens at the best pricing available.
post
https://api.totle.com
/swap
/swap
Swap Vs Swaps - Executing Multiple Swaps in One Call To execute multiple swaps, submit a request using the swaps array of objects, where each object within the array contains information about a single swap (i.e., to swap two token pairs, include two objects within the swaps array).
cURL
Node
Ruby
JavaScript
Python
1
curl -X POST \
2
https://api.totle.com/swap \
3
-H 'content-type: Application/JSON' \
4
-d '{
5
"swap":{
6
"sourceAsset":"ETH",
7
"destinationAsset":"DAI",
8
"sourceAmount":"1000000000000000000",
9
"maxMarketSlippagePercent":"10",
10
"maxExecutionSlippagePercent":"3"
11
}
12
}'
Copied!
1
var request = require("request")
2
3
var body = {
4
"swap":{
5
"sourceAsset":"ETH",
6
"destinationAsset":"DAI",
7
"sourceAmount":"1000000000000000000",
8
"maxMarketSlippagePercent":"10",
9
"maxExecutionSlippagePercent":"3"
10
}
11
}
12
13
var options = {
14
method: 'POST',
15
url: 'https://api.totle.com/swap',
16
headers: {'content-type': 'application/json'},
17
body: JSON.stringify(body)
18
}
19
20
request(options, function (error, response, body) {
21
if (error) throw new Error(error)
22
23
console.log(body)
24
})
Copied!
1
require 'uri'
2
require 'net/http'
3
4
url = URI("https://api.totle.com/swap")
5
6
http = Net::HTTP.new(url.host, url.port)
7
8
request = Net::HTTP::Post.new(url)
9
request["content-type"] = 'Application/JSON'
10
request.body = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"sourceAmount\":\"1000000000000000000\",\"maxMarketSlippagePercent\":\"10\",\"maxExecutionSlippagePercent\":\"3\"}}"
11
12
response = http.request(request)
13
puts response.read_body
Copied!
1
var data = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"sourceAmount\":\"1000000000000000000\",\"maxMarketSlippagePercent\":\"10\",\"maxExecutionSlippagePercent\":\"3\"}}";
2
3
var xhr = new XMLHttpRequest();
4
xhr.withCredentials = true;
5
6
xhr.addEventListener("readystatechange", function () {
7
if (this.readyState === 4) {
8
console.log(this.responseText);
9
}
10
});
11
12
xhr.open("POST", "https://api.totle.com/swap");
13
14
xhr.send(data);
Copied!
1
import requests
2
3
url = "https://api.totle.com/swap"
4
5
payload = "{\"swap\":{\"sourceAsset\":\"ETH\",\"destinationAsset\":\"DAI\",\"sourceAmount\":\"1000000000000000000\",\"maxMarketSlippagePercent\":\"10\",\"maxExecutionSlippagePercent\":\"3\"}}"
6
headers = {
7
'content-type': "Application/JSON"
8
}
9
10
response = requests.request("POST", url, data=payload, headers=headers)
11
12
print(response.text)
Copied!
Last modified 11mo ago
Copy link