RESTful API
You are referring to the Legacy
version of KyberSwap docs.
For the most updated information, please refer to:
INTRODUCTION
The RESTful API provide a way for users to be able to programmatically interact with the KyberNetwork contract without in depth understanding of blockchain and smart contracts. Please note that some of these endpoints have certain limitations as follows:
The
/buy_rate
and/sell_rate
endpoints are restricted to ETH <-> token queries only while thetrade_data
endpoint allows token <-> token trades.The fields
active
,custom_proxy
andoriginal_token
will only appear if certain conditions are met. Otherwise, they will not show up in the API response.The
only_official_reserve
parameter has been deprecated.
INDEX
<AUTOGENERATED_TABLE_OF_CONTENTS>
REFERENCE
Endpoints
/buy_rate
/buy_rate
(GET) Returns the latest BUY conversion rate in ETH. For example, if you want to know how much ETH is needed to buy 1 DAI, you can use this function.
Arguments:
id
string
Yes
The id
represents the token you want to buy using ETH.
qty
float
Yes
A floating point number which will be rounded off to the decimals of the asset specified. The quantity is the amount of units of the asset you want to buy.
only_official_reserve
bool
No
Deprecated
Response:
src_id
string
The id
represents the source token. It should be ETH for this endpoint.
dst_id
string
The id
represents the destination token of the pair you want to get rates for. id
should match one of the request input parameters specified in id
.
src_qty
float[]
Array of floating point numbers which will be rounded off to the decimals of ETH.
dst_qty
float[]
Array of floating point numbers which will be rounded off to the decimals of the id
represents the destination token. They should match the request input parameter specified in qty
.
Example
Get buy rates for 300 KNC and 10.1 OMG.
/change24h
/change24h
(GET) Returns token to ETH and USD rates and percentage changes against the past day
Arguments:
only_official_reserve
bool
No
Deprecated
Response:
timestamp
int
Server timestamp in UTC
token_name
string
Name of the asset
token_symbol
string
Symbol of the asset
token_decimal
int
Decimals that will be used to round-off the srcQty or dstQty of the asset in other requests
token_address
string
The asset contract address
rate_eth_now
float
Current asset price against ETH
change_eth_24h
float
Percentage change in ETH against the past 24 hours
change_usd_24h
float
Percentage change in USD against the past 24 hours
rate_usd_now
float
Current asset price in USD
custom_proxy
bool
Returns true if the address is a proxy address. Note that this field only appears if the token is a proxy token.
original_token
string
The address of the original token contract. Note that this field only appears if the token is a proxy token.
Example
/currencies
/currencies
(GET) Returns a list of all possible tokens available for trade.
Arguments:
include_delisted
bool
No
Accepts true
or false
as arguments. If no value is specified, it will default to false. If true, the API will also return tokens that have been delisted.
page
int
No
The page index of the response data, starts from 0
. If no value is specified, it will default to 0. Each page includes maximum 1000 records.
only_official_reserve
bool
No
Deprecated
Response:
symbol
string
The symbol of the asset in its native chain.
name
string
Name of the asset in its native chain.
decimals
int
Decimals that will be used to round-off the srcQty or dstQty of the asset in other requests.
address
string
The address of the asset in its native chain.
id
string
A unique ID used by Kyber Network to identify between different symbols.
active
bool
A boolean value to represent if the token is still active on Kyber. Note that this field only appears when you specify a value for the include_delisted
parameter.
reserves_src
string[]
Reserve contract addresses supporting Token to Ether trades
reserves_dest
string[]
Reserve contract addresses supporting Ether to Token trades
custom_proxy
bool
Returns true if the address is a proxy address. Note that this field only appears if the token is a proxy token.
original_token
string
The address of the original token contract. Note that this field only appears if the token is a proxy token.
Note: Ether and tokens that have been deployed permissionlessly do not have the reserves_src
and reserves_dest
fields.
Example
/expectedRate
/expectedRate
(GET) Return the expected rate for a token pair, with behavior similar to getExpectedRate from the proxy contract.
Arguments:
source
string
Yes
The source token contract address.
dest
string
Yes
The destination token contract address.
sourceAmount
number
Yes
The amount of source tokens in source token decimals.
platformFee
number
No
The platform fee in BPS.
Response:
expectedRate
string
The conversion rate of the token pair in 10^18. See example for reference.
slippageRate
string
Deprecated, will return expectedRate
timestamp
int
Server timestamp in UTC.
error
bool
Returns true
if the operation encountered an error, otherwise false
.
Example
Get rates for 100 DAI to OMG, with a 0.25% platform fee.
This means that 1 DAI can be exchanged for 634908750000000033 / 1e18
= 0.63490875 OMG.
/gas_limit
/gas_limit
(GET) Return the estimated Gas Limit used for a transaction based on source token amount.
Arguments:
source
string
Yes
The source token contract address.
dest
string
Yes
The destination token contract address.
amount
number
The amount of source tokens.
Response:
data
string
The estimated gas limit to be used for a transaction based on the parameters.
error
bool
Returns true
if the operation encountered an error, otherwise false
.
Example
Get the gas limit for exchanging 10000 DAI to OMG.
/gasLimitConfig
/gasLimitConfig
(GET) Returns the gas limit for approving token and swapping between ETH <-> ERC20 token. To calculate the gas limit for swapping between token A <-> token B, take the sum of the gas limit for swapping from token A -> ETH and for swapping from ETH -> Token B. Note that some tokens may require higher gas limits than others e.g. DAI, TUSD, MKR, DGX.
Response:
symbol
string
Symbol of the asset
address
string
Contract address of the asset
swapGasLimit
int
Gas limit when swapping between ETH <-> asset
approveGasLimit
int
Gas limit when approving KNP to trade the asset on behalf of the user
custom_proxy
bool
Returns true if the address is a proxy address. Note that this field only appears if the token is a proxy token.
original_token
string
The address of the original token contract. Note that this field only appears if the token is a proxy token.
Example
/hint
/hint
(GET) Returns the encoded hint based on the input parameters.
Arguments:
type
string
Yes
Must be e2t
, t2e
, or t2t
token_src
string
Dependent on route
source token address
token_dest
string
Dependent on route
destination token address
trade_type
string
Yes
Must be bestofall
, maskin
, maskout
, or split
reserve_id
string
Dependent on route
ID(s) of the reserve, comma-separated
split_value
string
Dependent on route
Respective split for the reserveId, comma-separated
Response:
data
string
The encoded hint
Example
Build a KNC to ETH split trade among 2 reserves:
Reserve
0xff00004b79626572000000000000000000000000000000000000000000000000
: 70%Reserve
0xff53706561726f53000000000000000000000000000000000000000000000000
: 30%
/market
/market
(GET) Retrieve in-depth information about price and other information about assets.
Response:
timestamp
int
Server timestamp in UTC.
quote_symbol
string
Symbol of the asset used for quoting i.e. ETH.
quote_name
string
Name of the asset in its native chain. i.e. Ethereum.
quote_decimals
int
Decimals that will be used to round-off the srcQty or dstQty of the asset in other requests.
quote_address
string
Contract address of the asset used for quoting.
base_symbol
string
Symbol of the asset to be quoted in terms of the quote_symbol
.
base_name
string
Name of the asset to be quoted in terms of the quote_name
.
base_decimals
int
Decimals of the asset to be quoted.
base_address
string
Contract address of the asset to be quoted.
past_24h_high
float
Highest ASK price for the last 24 hours of the pair.
past_24h_low
float
Highest BID price for the last 24 hours of the pair.
usd_24h_volume
float
Volume for the last 24 hours in USD.
eth_24h_volume
float
Volume for the last 24 hours in ETH.
token_24h_volume
float
Volume for the last 24 hours in tokens.
current_bid
float
Current (considering some X minute delay) BID price.
current_ask
float
Current (considering some X minute delay) ASK price.
last_traded
float
Last traded price in the exchange.
pair
string
Pair name consisting of the quote and base asset symbols.
custom_proxy
bool
Returns true if the address is a proxy address. Note that this field only appears if the token is a proxy token.
original_token
string
The address of the original token contract. Note that this field only appears if the token is a proxy token.
Example
/quote_amount
/quote_amount
(GET) Returns the amount of quote
token needed to buy / received when selling qty
amount of base
token. This endpoint will only work for official reserves.
Arguments:
base
string
Yes
The base token contract address.
quote
string
Yes
The quote token contract address.
base_amount
number
The amount of base tokens you would like to buy / sell.
type
string
Yes
Accepts buy
or sell
as arguments. Whether you want to buy / sell base_amount
worth of base
token.
Response:
error
bool
Returns true
if the operation encountered an error, otherwise false
.
data
string
The amount of quote
token needed to buy / received when selling base_amount
worth of base
tokens.
Examples
Get WETH amount receivable for selling 10 KNC, with 0.08% platform fee. (10 KNC -> ? WETH)
Get WETH amount needed to purchase 10 KNC, with 0.1% platform fee. (? WETH -> 10 KNC)
/all_reserves
/all_reserves
(GET) Returns a list of all reserves added to the network.
Response:
address
string
The address of the asset in its native chain.
type
integer
Reserve Type. Elaborated in description.
rebate_wallet
string
Reserve rebate wallet address
description
string
Reserve type description
Reserve Types
Refer to this section for more information on reserve types.
1
= Fed Price Reserve (FPR)2
= Automated Price Reserve (APR)3
= Bridge Reserve (BRIDGE)4
= Utility Reserve (UTILITY)5
= Custom Reserve (CUSTOM)6
= Orderbook Reserve (ORDERBOOK)
Example
/reserves
/reserves
(GET) Returns a list of reserves that supports a token pair.
Arguments:
token
string
Yes
Address of the asset.
type
string
Yes
Accepts buy
or sell
as arguments. buy
will return a list of reserves which support the eth -> token pair, otherwise sell
returns reserves which support the token -> eth pair.
Response:
address
string
The address of the asset in its native chain.
type
integer
Reserve Type. Elaborated in description.
rebate_wallet
string
Reserve rebate wallet address
description
string
Reserve type description
Reserve Types
Refer to this section for more information on reserve types.
1
= Fed Price Reserve (FPR)2
= Automated Price Reserve (APR)3
= Bridge Reserve (BRIDGE)4
= Utility Reserve (UTILITY)5
= Custom Reserve (CUSTOM)6
= Orderbook Reserve (ORDERBOOK)
Example
Get list of reserves that support ETH -> KNC trades.
/sell_rate
/sell_rate
(GET) Returns the latest SELL conversion rate in ETH. For example, if you want to know how much ETH you will get by selling 1 DAI, you can use this function.
Arguments:
id
string
Yes
The id
represents the token you want to sell using ETH.
qty
float
Yes
A floating point number which will be rounded off to the decimals of the asset specified. The quantity is the amount of units of the asset you want to sell.
only_official_reserve
bool
No
Deprecated
Response:
Example
Get sell rates for 300 and 150 KNC, and 10.1, 20 and 30 OMG.
/trade_data
/trade_data
(GET) Returns the transaction payload for the user to sign and broadcast in order to trade or convert an asset pair from token A to token B.
Arguments:
user_address
string
Yes
The ETH address that will be executing the swap.
src_id
string
Yes
The id
represents the source token of the pair you want to trade.
dst_id
string
Yes
The id
represents the destination token of the pair you want to trade.
src_qty
float
Yes
A floating point number representing the source amount in the conversion which will be rounded off to the decimals of the source token id
.
min_dst_qty
float
Yes
A floating point number representing the source amount in the conversion which will be rounded off to the decimals of the destination token id
. It is the minimum destination asset amount that is acceptable to the user. A guideline would be to set it at 3% less the destination quantity in getPair
, which indicates a 3% slippage.
gas_price
string
Yes
One of the following 3: low
, medium
, high
. Priority will be set according to the level defined.
wallet_id
string
No
Wallet address that to get fees from the trade. Read more about platform fees here.
hint
string
No
The trade hint, specifying the trade type, reserve IDs and splits. Read more about building and parsing hints here.
nonce
integer
No
Users can specify a nonce to override the default account nonce.
only_official_reserve
bool
No
Deprecated.
Response:
from
string
The ETH address that executed the swap. Must match the user_address
request input parameter.
to
string
The contract address of the KyberNetwork smart contract. Verify that it should always be the address resolved from kybernetwork.eth
ENS.
data
string
Transaction data. This data needs to be signed and broadcasted to the blockchain.
value
string
This will be equal to 0 in hex (0x0) if the user tries to trade from token to ETH (assuming src_id
is the source token address).
gasPrice
string
Calculated ETHGasStation price according to the user's request. If you need to specify a price value, change this wei hex value.
nonce
string
The nonce of the account. If multiple conversions are requested at the same time, each request will have the same nonce as the API will return the nonce of the account's last mined transaction.
gasLimit
string
The gas limit required for the transaction. This value should not be altered unless for specific reasons.
Example
User 0x8fa07f46353a2b17e92645592a94a0fc1ceb783f
to swap 0.05 ETH to KNC (minimally receive 5.5 KNC) at medium gas price, with a nonce of 200. 0.025% of the trade will be allocated to 0x0859A7958E254234FdC1d200b941fFdfCAb02fC1
.
/transfer_data
/transfer_data
(GET) Returns the transaction payload for the user to sign and broadcast in order to transfer an asset to a recipient.
Arguments:
from
string
Yes
The Ethereum address of the sender. | | to
| string | Yes | The Ethereum address of the receiver.
token
string
No
The contract address of token. If no argument is provided, it will default to ETH.
value
float
Yes
The number of token / ETH you want to send. For example, if you want to send 1.35 ZIL (12 decimals), it would be 1.35.
gas_price
string
Yes
One of the following 3: low
, medium
, high
. Priority will be set according to the level defined.
gas_limit
integer
No
The limit of gas required for your transaction.
nonce
integer
No
Users can specify a nonce to override the default account nonce.
Response:
from
string
The Ethereum address that executed the transfer. Must match the from
input parameter.
to
string
The contract address of the token or the recipient Ethereum address (if transferring ETH).
data
string
Transaction data. This data needs to be signed and broadcasted to the blockchain. If sending ETH, the value for this parameter should be '0x0'.
value
string
If sending token, the value for this parameter should be '0x0'. Else, it should match the value
input parameter.
gasPrice
string
Calculated ETHGasStation price according to the user's request. If you want to specify a price value, change this wei hex value.
nonce
string
The nonce of the account. If multiple conversions are requested at the same time, each request will have the same nonce as the API will return the nonce of the account's last mined transaction.
gasLimit
string
The gas limit required for the transaction. This value should not be altered unless for specific reasons.
Example
Wallet 0x3Cf628d49Ae46b49b210F0521Fbd9F82B461A9E1
to transfer 20.5 KNC to 0x723f12209b9C71f17A7b27FCDF16CA5883b7BBB0
with medium gas price and tx nonce of 123.
/users/:user_address/currencies
/users/:user_address/currencies
(GET) Returns a list of token enabled statuses of an Ethereum wallet. It indicates if the wallet can sell a token or not. If not, how many transactions he has to do in order to enable it.
Arguments:
user_address
string
Yes
The ETH address to get information from.
page
int
No
The page index of the response data, starts from 0
. If no value is specified, it will default to 0. Each page includes maximum 1000 records.
only_official_reserve
bool
No
Deprecated
Response:
id
string
A unique ID used by Kyber Network to identify between different symbols
enabled
bool
Whether the user address has approved Kyber Network to spend the asset on their behalf. Applicable only to ERC20 tokens. See ‘allowance’ on the ERC20 standard.
txs_required
int
Number of transactions required until the ID is enabled for trading. When enabled
is True, txs_required
is 0. When enabled
is False, majority of the time tx_required
is 1.
Example
Find what tokens the wallet 0x8fA07F46353A2B17E92645592a94a0Fc1CEb783F
has approved for trading.
/users/:user_address/currencies/:currency_id/enable_data
/users/:user_address/currencies/:currency_id/enable_data
(GET) Returns all needed information for a user to sign and do a transaction, and to enable a token to be able to be sold.
Arguments:
user_address
string
Yes
The ETH address of the user that will enable the asset.
currency_id
string
Yes
The unique ID of the destination asset.
gas_price
string
Yes
One of the following 3: low
, medium
, high
. Priority will be set according to the level defined.
nonce
int
No
You can manually specify a nonce to override the default account nonce.
only_official_reserve
bool
No
Deprecated
Response:
from
string
The ETH address of the user. Must match the user_address
request parameter.
to
string
The contract address of the token you want to enable trading in Kyber Network. Always verify this for security reasons.
data
string
Transaction data. This data needs to be signed and broadcasted to the blockchain.
value
string
Should always be equal to 0 for this operation. Always verify that the value is 0 for security reasons.
gasPrice
string
Calculated ETHGasStation price according to the user's request. If you need to specify a price value, change this wei hex value.
nonce
string
The nonce of the account. If multiple conversions are requested at the same time, each request will have the same nonce as the API will return the nonce of the account's last mined transaction.
gasLimit
string
The gas limit required for the transaction. This value should not be altered unless for specific reasons.
Example
Get transaction input parameters for user 0xfD65739DA3280dC976DDAf1937D37dA6Db98cb65
to approve KNC for trades at high gas price.
Last updated