Test hummingbot gateway API with xsswap exchange
Setup enviroment according to instructions before test.
I created some trade pools on xsswap and testnet:
Token1 | Token2 | Price(Token1/Token2) |
---|---|---|
WBTC2 | USDC2 | 20000 |
YFI2 | USDC2 | 8000 |
MKR2 | USDC2 | 600 |
AAVE2 | USDC2 | 70 |
UNI2 | USDC2 | 5 |
Set allowances to maximum for each test token.
xinfin
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/approve" -d '{
"chain": "xdc",
"network": "xinfin",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"token": "WXDC"
}' | jq
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/approve" -d '{
"chain": "xdc",
"network": "xinfin",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"token": "XTT"
}' | jq
apothem
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/approve" -d '{
"chain": "xdc",
"network": "apothem",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"token": "USDC2"
}' | jq
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/approve" -d '{
"chain": "xdc",
"network": "apothem",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"token": "WBTC2"
}' | jq
xinfin
# set WXDC allowance for xsswap
https --print=h POST ${SERVER}/evm/approve chain=xdc network=xinfin address=${XDC_ADDRESS} spender=xsswap token=WXDC
# set XTT allowance for xsswap
https --print=h POST ${SERVER}/evm/approve chain=xdc network=xinfin address=${XDC_ADDRESS} spender=xsswap token=XTT
apothem
# set USDC2 allowance for xsswap
https --print=h POST ${SERVER}/evm/approve chain=xdc network=apothem address=${XDC_ADDRESS} spender=xsswap token=USDC2
# set WBTC2 allowance for xsswap
https --print=h POST ${SERVER}/evm/approve chain=xdc network=apothem address=${XDC_ADDRESS} spender=xsswap token=WBTC2
xinfin
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/allowances" -d '{
"chain": "xdc",
"network": "xinfin",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"tokenSymbols": ["WXDC", "XTT"]
}' | jq
apothem
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/evm/allowances" -d '{
"chain": "xdc",
"network": "apothem",
"address": "'"$XDC_ADDRESS"'",
"spender": "xsswap",
"tokenSymbols": ["WBTC2", "USDC2"]
}' | jq
xinfin
# query allowances of WXDC and XTT
https --print=b POST ${SERVER}/evm/allowances chain=xdc network=xinfin address=${XDC_ADDRESS} spender=xsswap tokenSymbols:='["WXDC", "XTT"]'
apothem
# query allowances of WBTC2 and USDC2
https --print=b POST ${SERVER}/evm/allowances chain=xdc network=apothem address=${XDC_ADDRESS} spender=xsswap tokenSymbols:='["WBTC2", "USDC2"]'
xinfin
# buy XTT, quote with WXDC
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/price" -d '{
"connector": "xsswap",
"chain": "xdc",
"network": "xinfin",
"base": "XTT",
"quote": "WXDC",
"amount": "1",
"side": "BUY"
}' | jq
# sell XTT, quote with WXDC
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/price" -d '{
"connector": "xsswap",
"chain": "xdc",
"network": "xinfin",
"base": "XTT",
"quote": "WXDC",
"amount": "1",
"side": "SELL"
}' | jq
apothem
# buy WBTC2, quote with USDC2
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/price" -d '{
"connector": "xsswap",
"chain": "xdc",
"network": "apothem",
"base": "WBTC2",
"quote": "USDC2",
"amount": "1",
"side": "BUY"
}' | jq
# sell WBTC2, quote with USDC2
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/price" -d '{
"connector": "xsswap",
"chain": "xdc",
"network": "apothem",
"base": "WBTC2",
"quote": "USDC2",
"amount": "1",
"side": "SELL"
}' | jq
xinfin
# buy XTT, quote with WXDC
https --print=b POST ${SERVER}/amm/price connector=xsswap chain=xdc network=xinfin quote=WXDC amount=1 base=XTT side=BUY
# sell XTT, quote with WXDC
https --print=b POST ${SERVER}/amm/price connector=xsswap chain=xdc network=xinfin quote=WXDC amount=1 base=XTT side=SELL
apothem
# buy WBTC2, quote with USDC2
https --print=b POST ${SERVER}/amm/price connector=xsswap chain=xdc network=apothem quote=USDC2 amount=1 base=WBTC2 side=BUY
# sell WBTC2, quote with USDC2
https --print=b POST ${SERVER}/amm/price connector=xsswap chain=xdc network=apothem quote=USDC2 amount=1 base=WBTC2 side=SELL
We will check balances of base and quote tokens before and after trade. Notice: wait 3-4 seconds to send next request.
xinfin
# buy XTT, quote with WXDC
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/trade" -d '{
"address": "'"$XDC_ADDRESS"'",
"base": "XTT",
"quote": "WXDC",
"amount": "1",
"side": "BUY",
"chain": "xdc",
"network": "xinfin",
"connector": "xsswap"
}' | jq
# sell XTT, quote with WXDC
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/trade" -d '{
"address": "'"$XDC_ADDRESS"'",
"base": "XTT",
"quote": "WXDC",
"amount": "1",
"side": "SELL",
"chain": "xdc",
"network": "xinfin",
"connector": "xsswap"
}' | jq
apothem
# buy WBTC2, quote with USDC2
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/trade" -d '{
"address": "'"$XDC_ADDRESS"'",
"base": "WBTC2",
"quote": "USDC2",
"amount": "1",
"side": "BUY",
"chain": "xdc",
"network": "apothem",
"connector": "xsswap"
}' | jq
# sell WBTC2, quote with USDC2
curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "${HEADER}" "${SERVER}/amm/trade" -d '{
"address": "'"$XDC_ADDRESS"'",
"base": "WBTC2",
"quote": "USDC2",
"amount": "1",
"side": "SELL",
"chain": "xdc",
"network": "apothem",
"connector": "xsswap"
}' | jq
xinfin
# query balances before buy
https --print=b POST ${SERVER}/network/balances chain=xdc network=xinfin address=${XDC_ADDRESS} tokenSymbols:='["WXDC", "XTT"]'
# buy XTT, quote with WXDC
https --print=h POST ${SERVER}/amm/trade connector=xsswap chain=xdc network=xinfin address=${XDC_ADDRESS} quote=WXDC amount=1 base=XTT side=BUY
# query balances after buy
https --print=b POST ${SERVER}/network/balances chain=xdc network=xinfin address=${XDC_ADDRESS} tokenSymbols:='["WXDC", "XTT"]'
# query WXDC and XTT balances before sell
https --print=b POST ${SERVER}/network/balances chain=xdc network=xinfin address=${XDC_ADDRESS} tokenSymbols:='["WXDC", "XTT"]'
# sell XTT, quote with WXDC
https --print=h POST ${SERVER}/amm/trade connector=xsswap chain=xdc network=xinfin address=${XDC_ADDRESS} quote=WXDC amount=1 base=XTT side=SELL
# query WXDC and XTT balances after sell
https --print=b POST ${SERVER}/network/balances chain=xdc network=xinfin address=${XDC_ADDRESS} tokenSymbols:='["WXDC", "XTT"]'
apothem
# query WBTC2 and USDC2 balances before buy
https --print=b POST ${SERVER}/network/balances chain=xdc network=apothem address=${XDC_ADDRESS} tokenSymbols:='["WBTC2", "USDC2"]'
# buy WBTC2, quote with USDC2
https --print=h POST ${SERVER}/amm/trade connector=xsswap chain=xdc network=apothem address=${XDC_ADDRESS} quote=USDC2 amount=1 base=WBTC2 side=BUY
# query WBTC2 and USDC2 balances after buy
https --print=b POST ${SERVER}/network/balances chain=xdc network=apothem address=${XDC_ADDRESS} tokenSymbols:='["WBTC2", "USDC2"]'
# query WBTC2 and USDC2 balances before sell
https --print=b POST ${SERVER}/network/balances chain=xdc network=apothem address=${XDC_ADDRESS} tokenSymbols:='["WBTC2", "USDC2"]'
# sell WBTC2, quote with USDC2
https --print=h POST ${SERVER}/amm/trade connector=xsswap chain=xdc network=apothem address=${XDC_ADDRESS} quote=USDC2 amount=1 base=WBTC2 side=SELL
# query WBTC2 and USDC2 balances after sell
https --print=b POST ${SERVER}/network/balances chain=xdc network=apothem address=${XDC_ADDRESS} tokenSymbols:='["WBTC2", "USDC2"]'