Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

The exchange.IO("api", ...) function is used to call smart contract methods.

exchange.IO(k, address, method)
exchange.IO(k, address, method, ...args)
exchange.IO(k, address, method, value, ...args)

Examples

  • The decimals method is a constant method of ERC20 that does not consume gas and can query the precision data of a token.

    The decimals method requires no parameters. Return value: the precision data of the token.

    javascript
    function main(){ var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 代币的合约地址,例子中的代币为1INCH Log(exchange.IO("api", tokenAddress, "decimals")) // 查询,打印1INCH代币的精度指数为18 }
  • The allowance method is a constant method of ERC20 that does not consume gas and can query the authorized amount of a token for a specific contract address.

    The allowance method requires 2 parameters: the first parameter is the wallet address, and the second parameter is the authorized address. Return value: the authorized amount of the token.

    owner: wallet address, represented by the string "owner" in the example, actual use requires filling in the specific address.

    spender: the authorized contract address, represented by the string "spender" in the example, actual use requires filling in the specific address, for example, it can be the Uniswap V3 router v1 address.

    javascript
    function main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 例如查询得出1000000000000000000,除以该token的精度单位1e18,得出当前交易所对象绑定的钱包给spender地址授权了1个1INCH数量 Log(exchange.IO("api", tokenAddress, "allowance", "owner", "spender")) }
  • The approve method is a non-constant method of ERC20 that consumes gas and is used to authorize a contract address with an operational amount of tokens.

    The approve method requires 2 parameters: the first parameter is the authorized address, and the second parameter is the authorized amount. Return value: txid.

    spender: the authorized contract address, represented by the string "spender" in the example, actual use requires filling in the specific address, for example, it can be the Uniswap V3 router v1 address.

    0xde0b6b3a7640000: the authorized amount, represented here as a hexadecimal string, corresponding to the decimal value of 1e18, divided by the token precision unit in the example (i.e., 1e18), resulting in authorization of 1 token.

    The third parameter of the exchange.IO() function passes the method name approve, which can also be written in methodId form, for example: "0x571ac8b0". It can also be written as the complete standard method name, for example: "approve(address,uint256)".

    javascript
    function main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 授权量的十六进制字符串: 0xde0b6b3a7640000 , 对应的十进制字符串: 1e18 , 1e18除以该token的精度单位,即1个代币数量 , 所以这里指授权一个代币 Log(exchange.IO("api", tokenAddress, "approve", "spender", "0xde0b6b3a7640000")) }
  • The multicall method is a non-constant method of Uniswap V3 that consumes gas and is used for multi-path token swaps.

    The multicall method may have multiple parameter passing methods. You can query the ABI containing this method for details. The ABI needs to be registered before calling this method. Return value: txid.

    For specific multicall method call examples, you can refer to the platform's public "Uniswap V3 Trading Library" template

    Here we use pseudocode to describe some details:

    javascript
    exchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data)

    ContractV3SwapRouterV2: The router v2 address of Uniswap V3.

    value: The amount of ETH to transfer. If the tokenIn token for the swap operation is not ETH, set it to 0.

    deadline: deadline is a parameter of the multicall method, which can be set to (new Date().getTime() / 1000) + 3600, indicating validity within one hour.

    data: data is a parameter of the multicall method, the packed operation data to be executed. Similar to exchange.IO("api", "eth", "send", "toAddress", toAmount), when calling the multicall method, you can also specify the gasLimit/gasPrice/nonce settings for the method call, also described using pseudocode:

    javascript
    exchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data, {gasPrice: 123456, gasLimit: 21000})

    You can set the {gasPrice: 11, gasLimit: 111, nonce: 111} parameters according to specific requirements. This parameter is set as the last parameter of the exchange.IO() function.

    You can omit nonce to use the system default value, or not set gasLimit/gasPrice/nonce to use all system default values.

    javascript
    function main() { var ContractV3SwapRouterV2 = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45" var tokenInName = "ETH" var amountIn = 0.01 var options = {gasPrice: 5000000000, gasLimit: 21000, nonce: 100} // 此处为举例,具体要根据实际场景设置 var data = "" // 编码后的数据,此处为空字符串,具体要根据实际场景设置 var tx = exchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", (tokenInName == 'ETH' ? amountIn : 0), (new Date().getTime() / 1000) + 3600, data, options || {}) }

Returns

TypeDescription

string / number / bool / object / array / any (any type supported by the platform)

The exchange.IO("api", ...) function returns the return value of the called smart contract method.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). Setting it to "api" indicates that this function is used for extended API call requests.

address

string

Yes

The address parameter is used to specify the smart contract address.

method

string

Yes

The method parameter is used to specify the smart contract method to be called.

value

number / string

No

The value parameter is used to set the amount of ETH to send. When the stateMutability attribute of the smart contract method to be executed is payable, the value parameter needs to be passed. The "stateMutability":"payable" attribute can be viewed from the ABI. The exchange.IO() function will determine the required parameters based on the stateMutability attribute in the registered ABI. If the stateMutability attribute is nonpayable, there is no need to pass the value parameter.

arg

string / number / bool / any (any type supported by the platform)

No

The arg parameter is used to specify the parameters of the smart contract method to be called.

There may be multiple arg parameters. The type and number of arg parameters depend on the smart contract method to be called.