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_iddoes not exist.
- The market is not allowing orders to be created.
- The market requires attributes in order to create ask orders and the selleris missing one or more.
- The assetsare not in theseller's account.
- The priceis in a denom not supported by the market.
- The seller_settlement_flat_feeis in a denom different from theprice, and is not in theseller's account.
- The seller_settlement_flat_feeis insufficient (as dictated by the market).
- The external_idvalue is not empty and is already in use in the market.
- The order_creation_feeis 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_iddoes not exist.
- The market is not allowing orders to be created.
- The market requires attributes in order to create bid orders and the buyeris missing one or more.
- The pricefunds are not in thebuyer's account.
- The priceis in a denom not supported by the market.
- The buyer_settlement_feesare not in thebuyer's account.
- The buyer_settlement_feesare insufficient (as dictated by the market).
- The external_idvalue is not empty and is already in use in the market.
- The order_creation_feeis 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 accountis missing one or more.
- The creation_feeis insufficient (as dictated by the market).
- The amountis 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 signeris not one of:- The order's owner (e.g. buyerorseller).
- An account with PERMISSION_CANCELin 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 selleris missing one or more.
- One or more bid_order_idsare not bid orders (or do not exist).
- One or more bid_order_idsare in a market other than the providedmarket_id.
- The total_assetsare not in theseller's account.
- The sum of bid order assetsdoes not equal the providedtotal_assets.
- The selleror one of thebuyers are sanctioned, or are not allowed to possess the funds they are to receive.
- The seller_settlement_flat_feeis insufficient.
- The seller_settlement_flat_feeis not in theseller's account (afterassetsandpricefunds have been transferred).
- The ask_order_creation_feeis insufficient.
- The ask_order_creation_feeis 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 buyeris missing one or more.
- One or more ask_order_idsare not ask orders (or do not exist).
- One or more ask_order_idsare in a market other than the providedmarket_id.
- The total_pricefunds are not in thebuyer's account.
- The sum of ask order prices does not equal the providedtotal_price.
- The buyeror one of thesellers are sanctioned, or are not allowed to possess the funds they are to receive.
- The buyer_settlement_feesare insufficient.
- The buyer_settlement_feesare not in thebuyer's account (afterassetsandpricefunds have been transferred).
- The bid_order_creation_feeis insufficient.
- The bid_order_creation_feeis 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 admindoes not havePERMISSION_SETTLEin the market, and is not theauthority.
- One or more ask_order_idsare not ask orders, or do not exist, or are in a market other than the providedmarket_id.
- One or more bid_order_idsare 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 assetsof all the provided orders.
- There is more than one denom in the priceof all the provided orders.
- The market requires a seller settlement ratio fee, but there is no ratio defined for the pricedenom.
- Two or more orders are being partially filled.
- One or more orders cannot be filled at all with the assetsorpricefunds available in the settlement.
- An order is being partially filled, but expect_partialisfalse.
- All orders are being filled in full, but expect_partialistrue.
- One or more of the buyers andsellers 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 admindoes not havePERMISSION_SETTLEin the market, and is not theauthority.
- The sum of the inputsdoes 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 admindoes not havePERMISSION_CANCELin 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 admindoes not havePERMISSION_SET_IDSin 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_idequals the order's currentexternal_id.
- The provided external_idis 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 admindoes not havePERMISSION_WITHDRAWin the market, and is not theauthority.
- The amountfunds are not in the market's account.
- The to_addressis 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 admindoes not havePERMISSION_UPDATEin 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 admindoes not havePERMISSION_UPDATEin the market, and is not theauthority.
- The provided accepting_ordersvalue 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 admindoes not havePERMISSION_UPDATEin the market, and is not theauthority.
- The provided allow_user_settlementvalue 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 admindoes not havePERMISSION_UPDATEin the market, and is not theauthority.
- The provided accepting_ordersvalue equals the market's current setting.
- The provided accepting_ordersistruebut no commitment-related fees are defined.
- The provided accepting_ordersistrueand 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 admindoes not havePERMISSION_UPDATEin the market, and is not theauthority.
- The provided intermediary_denomis 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 admindoes not havePERMISSION_PERMISSIONSin the market, and is not theauthority.
- One or more revoke_alladdresses do not currently have any permissions in the market.
- One or more to_revokeentries do not currently exist in the market.
- One or more to_grantentries already exist in the market (afterrevoke_allandto_revokeare 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 admindoes not havePERMISSION_ATTRIBUTESin 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 Payments 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 sourceis not a valid bech32 string.
- The targetisn't empty and is not a valid bech32 string.
- The source_amountfunds are not available in thesourceaccount.
- The external_idis longer than 100 characters.
- A payment already exists with the given sourceandexternal_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 Paymentinfo does not match the payment's current state.
- The targetaccount does not have thetarget_amountfunds 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 sourceandexternal_id.
- The existing payment has a targetdifferent 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 sourceaccounts are provided.
- One of the provided sourceaccounts does not have any payments for thetarget.
MsgRejectPaymentsRequest
MsgRejectPaymentsResponse
CancelPayments
A source can cancel their payments with one or more external_ids 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_ids are provided.
- The sourcedoes 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 sourceandexternal_id.
- The provided new_targetequals 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 authorityis not the governance module's account.
- The provided market_idis 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 nameis limited to 250 characters max.
- The descriptionis limited to 2000 characters max.
- The website_urlis limited to 200 characters max.
- The icon_uriis 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 authorityis 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 authorityis 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 authorityis not the governance module's account.
MsgGovUpdateParamsRequest
See also: Params.