Exchange Messages
The exchange module has Msg
endpoints for users, markets, and governance proposals.
User Endpoints
There are several endpoints available for all users, but some markets might have restrictions on their use.
CreateAsk
An ask order indicates the desire to sell some assets
at a minimum price
.
They are created using the CreateAsk
endpoint.
Markets can define a set of attributes that an account must have in order to create ask orders in them.
So, this endpoint might not be available, depending on the seller
and the market_id
.
Markets can also disable order creation altogether, making this endpoint unavailable for that market_id
.
It is expected to fail if:
- The
market_id
does not exist. - The market is not allowing orders to be created.
- The market requires attributes in order to create ask orders and the
seller
is missing one or more. - The
assets
are not in theseller
's account. - The
price
is in a denom not supported by the market. - The
seller_settlement_flat_fee
is in a denom different from theprice
, and is not in theseller
's account. - The
seller_settlement_flat_fee
is insufficient (as dictated by the market). - The
external_id
value is not empty and is already in use in the market. - The
order_creation_fee
is not in theseller
's account.
MsgCreateAskRequest
AskOrder
MsgCreateAskResponse
CreateBid
A bid order indicates the desire to buy some assets
at a specific price
.
They are created using the CreateBid
endpoint.
Markets can define a set of attributes that an account must have in order to create bid orders in them.
So, this endpoint might not be available, depending on the buyer
and the market_id
.
Markets can also disable order creation altogether, making this endpoint unavailable for that market_id
.
It is expected to fail if:
- The
market_id
does not exist. - The market is not allowing orders to be created.
- The market requires attributes in order to create bid orders and the
buyer
is missing one or more. - The
price
funds are not in thebuyer
's account. - The
price
is in a denom not supported by the market. - The
buyer_settlement_fees
are not in thebuyer
's account. - The
buyer_settlement_fees
are insufficient (as dictated by the market). - The
external_id
value is not empty and is already in use in the market. - The
order_creation_fee
is not in thebuyer
's account.
MsgCreateBidRequest
BidOrder
MsgCreateBidResponse
CommitFunds
Funds can be committed to a market using the CommitFunds
endpoint.
If the account already has funds committed to the market, the provided funds are added to that commitment amount.
It is expected to fail if:
- The market does not exist.
- The market is not accepting commitments.
- The market requires attributes in order to create commitments and the
account
is missing one or more. - The
creation_fee
is insufficient (as dictated by the market). - The
amount
is not spendable in the account (after paying the creation fee).
MsgCommitFundsRequest
MsgCommitFundsResponse
CancelOrder
Orders can be cancelled using the CancelOrder
endpoint.
When an order is cancelled, the hold on its funds is released and the order is deleted.
Users can cancel their own orders at any time.
Market actors with the PERMISSION_CANCEL
permission can also cancel orders in that market at any time.
Order creation fees are not refunded when an order is cancelled.
It is expected to fail if:
- The order does not exist.
- The
signer
is not one of:- The order's owner (e.g.
buyer
orseller
). - An account with
PERMISSION_CANCEL
in the order's market. - The governance module account (
authority
).
- The order's owner (e.g.
MsgCancelOrderRequest
MsgCancelOrderResponse
FillBids
If a market allows user-settlement, users can use the FillBids
endpoint to settle one or more bids with their own assets
.
This is similar to an "Immediate or cancel" AskOrder
with the sum of the provided bids' assets and prices.
Fees are paid the same as if an AskOrder
were actually created and settled normally with the provided bids.
The seller
must be allowed to create an AskOrder
in the given market.
It is expected to fail if:
- The market does not exist.
- The market is not allowing orders to be created.
- The market does not allow user-settlement.
- The market requires attributes in order to create ask orders and the
seller
is missing one or more. - One or more
bid_order_ids
are not bid orders (or do not exist). - One or more
bid_order_ids
are in a market other than the providedmarket_id
. - The
total_assets
are not in theseller
's account. - The sum of bid order
assets
does not equal the providedtotal_assets
. - The
seller
or one of thebuyer
s are sanctioned, or are not allowed to possess the funds they are to receive. - The
seller_settlement_flat_fee
is insufficient. - The
seller_settlement_flat_fee
is not in theseller
's account (afterassets
andprice
funds have been transferred). - The
ask_order_creation_fee
is insufficient. - The
ask_order_creation_fee
is not in theseller
's account (after all other transfers have been made).
MsgFillBidsRequest
MsgFillBidsResponse
FillAsks
If a market allows user-settlement, users can use the FillAsks
endpoint to settle one or more asks with their own price funds.
This is similar to an "Immediate or cancel" BidOrder
with the sum of the provided asks' assets and prices.
Fees are paid the same as if a BidOrder
were actually created and settled normally with the provided asks.
The buyer
must be allowed to create a BidOrder
in the given market.
It is expected to fail if:
- The market does not exist.
- The market is not allowing orders to be created.
- The market does not allow user-settlement.
- The market requires attributes in order to create bid orders and the
buyer
is missing one or more. - One or more
ask_order_ids
are not ask orders (or do not exist). - One or more
ask_order_ids
are in a market other than the providedmarket_id
. - The
total_price
funds are not in thebuyer
's account. - The sum of ask order
price
s does not equal the providedtotal_price
. - The
buyer
or one of theseller
s are sanctioned, or are not allowed to possess the funds they are to receive. - The
buyer_settlement_fees
are insufficient. - The
buyer_settlement_fees
are not in thebuyer
's account (afterassets
andprice
funds have been transferred). - The
bid_order_creation_fee
is insufficient. - The
bid_order_creation_fee
is not in thebuyer
's account (after all other transfers have been made).
MsgFillAsksRequest
MsgFillAsksResponse
Market Endpoints
Several endpoints are only available to accounts designated by the market.
These are all also available for use in governance proposals using the governance module account (aka authority
) as the admin
.
MarketSettle
Orders are settled using the MarketSettle
endpoint.
The admin
must have the PERMISSION_SETTLE
permission in the market (or be the authority
).
The market is responsible for identifying order matches. Once identified, this endpoint is used to settle and clear the matched orders.
All orders in a settlement must have the same asset denom and the same price denom.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_SETTLE
in the market, and is not theauthority
. - One or more
ask_order_ids
are not ask orders, or do not exist, or are in a market other than the providedmarket_id
. - One or more
bid_order_ids
are not bid orders, or do not exist, or are in a market other than the providedmarket_id
. - There is more than one denom in the
assets
of all the provided orders. - There is more than one denom in the
price
of all the provided orders. - The market requires a seller settlement ratio fee, but there is no ratio defined for the
price
denom. - Two or more orders are being partially filled.
- One or more orders cannot be filled at all with the
assets
orprice
funds available in the settlement. - An order is being partially filled, but
expect_partial
isfalse
. - All orders are being filled in full, but
expect_partial
istrue
. - One or more of the
buyer
s andseller
s are sanctioned, or are not allowed to possess the funds they are to receive.
MsgMarketSettleRequest
MsgMarketSettleResponse
MarketCommitmentSettle
A market can move committed funds using the MarketCommitmentSettle
endpoint.
The admin
must have the PERMISSION_SETTLE
permission in the market (or be the authority
).
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_SETTLE
in the market, and is not theauthority
. - The sum of the
inputs
does not equal the sum of theoutputs
. - Not enough funds have been committed by one or more accounts to the market.
- A NAV is needed (for fee calculation) that does not exist and was not provided.
MsgMarketCommitmentSettleRequest
MsgMarketCommitmentSettleResponse
MarketReleaseCommitments
A market can release committed funds using the MarketReleaseCommitments
endpoint.
The admin
must have the PERMISSION_CANCEL
permission in the market (or be the authority
).
Providing an empty amount indicates that all funds currently committed in that account (to the market) should be released.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_CANCEL
in the market, and is not theauthority
. - One or more of the amounts is more than what is currently committed by the associated
account
.
MsgMarketReleaseCommitmentsRequest
MsgMarketReleaseCommitmentsResponse
MarketSetOrderExternalID
Some markets might want to attach their own identifiers to orders.
This is done using the MarketSetOrderExternalID
endpoint.
The admin
must have the PERMISSION_SET_IDS
permission in the market (or be the authority
).
Orders with external ids can be looked up using the GetOrderByExternalID query.
External ids must be unique in a market, but multiple markets can use the same external id.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_SET_IDS
in the market, and is not theauthority
. - The order does not exist, or is in a different market than the provided
market_id
. - The provided
external_id
equals the order's currentexternal_id
. - The provided
external_id
is already associated with another order in the same market.
MsgMarketSetOrderExternalIDRequest
MsgMarketSetOrderExternalIDResponse
MarketWithdraw
When fees are collected by a market, they are given to the market's account.
Those funds can then be withdrawn/transferred using the MarketWithdraw
endpoint.
The admin
must have the PERMISSION_WITHDRAW
permission in the market (or be the authority
).
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_WITHDRAW
in the market, and is not theauthority
. - The
amount
funds are not in the market's account. - The
to_address
is not allowed to possess the requested funds.
MsgMarketWithdrawRequest
MsgMarketWithdrawResponse
MarketUpdateDetails
A market's details can be updated using the MarketUpdateDetails
endpoint.
The admin
must have the PERMISSION_UPDATE
permission in the market (or be the authority
).
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_UPDATE
in the market, and is not theauthority
. - One or more of the MarketDetails fields is too large.
MsgMarketUpdateDetailsRequest
See also: MarketDetails.
MsgMarketUpdateDetailsResponse
MarketUpdateAcceptingOrders
A market can enable or disable order creation using the MarketUpdateAcceptingOrders
endpoint.
The admin
must have the PERMISSION_UPDATE
permission in the market (or be the authority
).
With accepting_orders
= false
, no one can create any new orders in the market, but existing orders can still be settled or cancelled.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_UPDATE
in the market, and is not theauthority
. - The provided
accepting_orders
value equals the market's current setting.
MsgMarketUpdateAcceptingOrdersRequest
MsgMarketUpdateAcceptingOrdersResponse
MarketUpdateUserSettle
Using the MarketUpdateUserSettle
endpoint, markets can control whether user-settlement is allowed.
The admin
must have the PERMISSION_UPDATE
permission in the market (or be the authority
).
The FillBids and FillAsks endpoints are only available for markets where allow_user_settlement
= true
.
The MarketSettle endpoint is usable regardless of this setting.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_UPDATE
in the market, and is not theauthority
. - The provided
allow_user_settlement
value equals the market's current setting.
MsgMarketUpdateUserSettleRequest
MsgMarketUpdateUserSettleResponse
MarketUpdateAcceptingCommitments
Using the MarketUpdateAcceptingCommitments
endpoint, a market can control whether it is accepting commitments.
The admin
must have the PERMISSION_UPDATE
permission in the market (or be the authority
).
The CommitFunds endpoint is only available for markets where accepting_orders
= true
.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_UPDATE
in the market, and is not theauthority
. - The provided
accepting_orders
value equals the market's current setting. - The provided
accepting_orders
istrue
but no commitment-related fees are defined. - The provided
accepting_orders
istrue
and bips are set, but either no intermediary denom is defined or there is no NAV associating the intermediary denom with the chain's fee denom.
MsgMarketUpdateAcceptingCommitmentsRequest
MsgMarketUpdateAcceptingCommitmentsResponse
MarketUpdateIntermediaryDenom
The MarketUpdateIntermediaryDenom
endpoint allows a market to change its intermediary denom (used for commitment settlement fee calculation).
The admin
must have the PERMISSION_UPDATE
permission in the market (or be the authority
).
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_UPDATE
in the market, and is not theauthority
. - The provided
intermediary_denom
is not a valid denom string.
MsgMarketUpdateIntermediaryDenomRequest
MsgMarketUpdateIntermediaryDenomResponse
MarketManagePermissions
Permissions in a market are managed using the MarketManagePermissions
endpoint.
The admin
must have the PERMISSION_PERMISSIONS
permission in the market (or be the authority
).
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_PERMISSIONS
in the market, and is not theauthority
. - One or more
revoke_all
addresses do not currently have any permissions in the market. - One or more
to_revoke
entries do not currently exist in the market. - One or more
to_grant
entries already exist in the market (afterrevoke_all
andto_revoke
are processed).
MsgMarketManagePermissionsRequest
See also: AccessGrant and Permission.
MsgMarketManagePermissionsResponse
MarketManageReqAttrs
The attributes required to create orders in a market can be managed using the MarketManageReqAttrs
endpoint.
The admin
must have the PERMISSION_ATTRIBUTES
permission in the market (or be the authority
).
See also: Required Attributes.
It is expected to fail if:
- The market does not exist.
- The
admin
does not havePERMISSION_ATTRIBUTES
in the market, and is not theauthority
. - One or more attributes to add are already required by the market (for the given order type).
- One or more attributes to remove are not currently required by the market (for the given order type).
MsgMarketManageReqAttrsRequest
MsgMarketManageReqAttrsResponse
Payment Endpoints
There are several endpoints for using Payment
s to facilitate transfers of funds between two accounts.
These are available to any account, and are not associated with any markets.
CreatePayment
A Payment
can be created using the CreatePayment
endpoint.
The source
is the account creating the payment. As part of payment creation, a hold is placed on the source_amount
funds in the source
account.
A payment is uniquely identified using a combination of its source
and external_id
.
The source
is responsible for choosing the external_id
of the payment, so it is up to them to choose one that they aren't currently using.
Once a payment is accepted, rejected, or cancelled, its external_id
can be re-used on a new payment.
A payment can be created without a target
, but one cannot be accepted until a target has been set for it.
A Tx
with a MsgCreatePaymentRequest
requires an additional amount in the fee if the source_amount
is not zero.
That amount is defined in the exchange module Params.
The OrderFeeCalc query can be used to identify how much extra fee to include.
It is expected to fail if:
- The
source
is not a valid bech32 string. - The
target
isn't empty and is not a valid bech32 string. - The
source_amount
funds are not available in thesource
account. - The
external_id
is longer than 100 characters. - A payment already exists with the given
source
andexternal_id
.
MsgCreatePaymentRequest
Payment
MsgCreatePaymentResponse
AcceptPayment
A target
can accept a previously created Payment
using the AcceptPayment
endpoint.
When a payment is accepted, the hold on the source_amount
funds is released, and they are sent to the target
; then the target_amount
funds are sent to the source
. Lastly, the Payment
record is deleted.
A Tx
with a MsgAcceptPaymentRequest
requires an additional amount in the fee if the target_amount
is not zero.
That amount is defined in the exchange module Params.
The OrderFeeCalc query can be used to identify how much extra fee to include.
It is expected to fail if:
- Any part of the provided
Payment
info does not match the payment's current state. - The
target
account does not have thetarget_amount
funds in it.
MsgAcceptPaymentRequest
See also: Payment.
MsgAcceptPaymentResponse
RejectPayment
A target
can reject a Payment
using the RejectPayment
endpoint.
When a payment is rejected, the hold on the source_amount
is released and the payment record is deleted.
It is expected to fail if:
- A payment does not exist with the provided
source
andexternal_id
. - The existing payment has a
target
different from the one provided (that signed the msg).
MsgRejectPaymentRequest
MsgRejectPaymentResponse
RejectPayments
A target
can reject all payments from one or more source
accounts using the RejectPayments
endpoint.
For each applicable payment, the hold on the source_amount
funds is released, and the payment record is deleted.
It is expected to fail if:
- No
source
accounts are provided. - One of the provided
source
accounts does not have any payments for thetarget
.
MsgRejectPaymentsRequest
MsgRejectPaymentsResponse
CancelPayments
A source
can cancel their payments with one or more external_id
s using the CancelPayments
endpoint.
For each applicable payment, the hold on the source_amount
funds is released, and the payment record is deleted.
It is expected to fail if:
- No
external_id
s are provided. - The
source
does not have a payment with one of the provided external ids.
MsgCancelPaymentsRequest
MsgCancelPaymentsResponse
ChangePaymentTarget
A source
can change the target
of a Payment
using the ChangePaymentTarget
endpoint.
This can be used to:
- Set a target on a payment that previously didn't have one.
- Change the target from one account to another.
- Unset the payment's target.
A payment's target can be changed multiple times (until it's accepted, rejected, or cancelled).
It is expected to fail if:
- No payment exists with the given
source
andexternal_id
. - The provided
new_target
equals the payment's currenttarget
.
MsgChangePaymentTargetRequest
MsgChangePaymentTargetResponse
Governance Proposals
There are several governance-proposal-only endpoints.
GovCreateMarket
Market creation must be done via governance proposal with a MsgGovCreateMarketRequest
.
If the provided market_id
is 0
(zero), the next available market id will be assigned to the new market.
If it is not zero, the provided market_id
will be used (unless it's already in use by another market).
If it's already in use, the proposal will fail.
It is recommended that the message be checked using the ValidateCreateMarket query first, to reduce the risk of failure or problems.
It is expected to fail if:
- The provided
authority
is not the governance module's account. - The provided
market_id
is not zero, and is already in use by another market. - One or more of the MarketDetails fields is too large.
- One or more required attributes are invalid.
MsgGovCreateMarketRequest
Market
MarketDetails
- The
name
is limited to 250 characters max. - The
description
is limited to 2000 characters max. - The
website_url
is limited to 200 characters max. - The
icon_uri
is limited to 2000 characters max.
FeeRatio
AccessGrant
Permission
MsgGovCreateMarketResponse
GovManageFees
A market's fees can only be altered via governance proposal with a MsgGovManageFeesRequest
.
It is recommended that the message be checked using the ValidateManageFees query first, to ensure the updated fees do not present any problems.
It is expected to fail if:
- The provided
authority
is not the governance module's account.
MsgGovManageFeesRequest
See also: FeeRatio.
MsgGovManageFeesResponse
GovCloseMarket
A market can be closed via governance proposal with a MsgGovCloseMarketRequest
.
When a market is closed, it stops accepting orders and commitments, all orders are cancelled, and all commitments are released.
It is expected to fail if:
- The provided
authority
is not the governance module's account.
MsgGovCloseMarketRequest
MsgGovCloseMarketResponse
GovUpdateParams
The exchange module params are updated via governance proposal with a MsgGovUpdateParamsRequest
.
It is expected to fail if:
- The provided
authority
is not the governance module's account.
MsgGovUpdateParamsRequest
See also: Params.