Contract API

All trades and token transfers are executed in the contract.

You can trade tokens from deposits in the market contract or from token ledgers.

Market contracts represent a pair of tokens, named X and Y, or base and quote. All token amounts and prices are scaled by corresponding scaling factors unless otherwise stated. Also see Contract-to-human scaling transformation.

depositTokens

Move funds to the market contract to trade them.

Parameters

Parameter
Type
Description

token_x_amount

uint128

the amount of token X to deposit

token_y_amount

uint128

the amount of token Y to deposit

withdrawTokens

Move funds from market contracts to token ledgers.

Parameters

Parameter
Type
Description

withdraw_all

bool

if set to True, withdraws all the trader's tokens; otherwise, uses the specified amounts.

token_x_amount

uint128

the amount of token X to withdraw (ignored if withdraw_all is true)

token_y_amount

uint128

the amount of token Y to withdraw (ignored if withdraw_all is true)

placeOrder

Create an order in the market contract. The function supports receiving the native token instead of the corresponding wrapped token.

Parameters

Parameter
Type
Description

isAsk

bool

true if the order is a sell order, false if it is a buy order

quantity

uint128

the amount of the base token in the order

price

uint56

the price per token in the order, no more than 6 significant digits

max_commission

uint128

the maximum commission, which may include passive and/or aggressive fees

market_only

bool

indicates if the order should be executed only against existing orders in the market

post_only

bool

indicates if the order should be posted only and not executed immediately

transfer_executed_tokens

bool

flag for transferring executed tokens (true) or crediting them to the balance (false)

expires

uint256

the time at which the order will expire

placeOrder

Overloaded version. Create an order in the market contract with the permitted approval.

Parameters

Parameter
Type
Description

isAsk

bool

true if the order is a sell order, false if it is a buy order

quantity

uint128

the amount of the base token in the order

price

uint56

the price per token in the order, no more than 6 significant digits

max_commission

uint128

the maximum commission, which may include passive and/or aggressive fees

amount_to_approve

uint128

the amount of the token permitted by the signature

market_only

bool

indicates if the order should be executed only against existing orders in the market

post_only

bool

indicates if the order should be posted only and not executed immediately

transfer_executed_tokens

bool

flag for transferring executed tokens (true) or crediting them to the balance (false)

expires

uint256

the time at which the order will expire

v

uint8

the component V of the signature

r

bytes32

the component R of the signature

s

bytes32

the component S of the signature

placeMarketOrderWithTargetValue

Create a market order by specifying the exact value of token Y. The function supports receiving the native token instead of the corresponding wrapped token.

Parameters

Parameter
Type
Description

isAsk

bool

true if the order is a sell order, false if it is a buy order

target_token_y_value

uint128

the amount of the quote token to be spent by the order

price

uint56

the price per token in the order, no more than 6 significant digits

max_commission

uint128

the maximum commission

transfer_executed_tokens

bool

flag for transferring executed tokens (true) or crediting them to the balance (false)

expires

uint256

the time at which the order will expire

placeMarketOrderWithTargetValue

Overloaded version. Create a market order by specifying the exact value of token Y with the permitted approval.

Parameters

Parameter
Type
Description

isAsk

bool

true if the order is a sell order, false if it is a buy order

target_token_y_value

uint128

the amount of the quote token to be spent by the order

price

uint56

the price per token in the order, no more than 6 significant digits

max_commission

uint128

the maximum commission

amount_to_approve

uint128

the amount of the token permitted by the signature

transfer_executed_tokens

bool

flag for transferring executed tokens (true) or crediting them to the balance (false)

expires

uint256

the time at which the order will expire

v

uint8

the component V of the signature

r

bytes32

the component R of the signature

s

bytes32

the component S of the signature

changeOrder

Claiming/canceling an existing order and creating a new one in the same (bid/ask) direction.

Parameters

Parameter
Type
Description

old_order_id

uint64

the identifier of the order to modify, a new order id will be assigned to the order

new_quantity

uint128

the amount of tokens for the new order

new_price

uint56

the price per token in the order, no more than 6 significant digits

max_commission

uint128

the maximum commission, which may include passive and/or aggressive fees

post_only

bool

indicates if the order should be posted only and not executed immediately

transfer_tokens

bool

if true, tokens will be transferred to the order owner

expires

uint256

the time at which the order will expire

claimOrder

Allows a trader to claim or cancel the order.

Parameters

Parameter
Type
Description

order_id

uint64

the identifier of the order to claim

transfer_tokens

bool

if true, transfers the tokens to the trader's address

expires

uint256

the time at which the order will expire

Last updated