DEX Class
Last updated
Last updated
Instances of DEX
cannot be constructed manually. They are only accessible as a return value of SDK.init()
. Each instance of the DEX class represents a connection to a particular instance of the Portal DEX network for a particular user.
The DEX instance returned by SDK.init()
contains no assets. Before any trades are executed on that instance, assets must be transferred into it using DEX.xfer()
.
Returns the assets and their quantities currently available. The elements of the Array are Objects with format: { asset: String, qty: Number }
.
Transfers one or more assets into the receiver from the specified source. Instances of DEX initially contain no assets and this method must be called before any trades are executed.
Argument | Type and Semantics |
---|---|
DEX.xfer
()
returns an Array whose elements are Objects with format:
Performs a swap of the specified assets under the specified conditions. Returns an instance of the Trade class. Will throw an exception if there are any errors in the arguments - thus it is advisable to call this function in a try/catch block.
Close the connection to receiver. Returns true
if successful else false
.
Returns the instance of Trade with the specified order_id
or undefined
if no trade with that order_id
was executed on the receiver.
Argument | Type and semantics |
---|---|
source
Object. Specifies the source of the assets and the parameters necessary for transferring them. Format depends on the source.
assets
Array. Specifies quantities of assets to transfer. The elements of the Array are Objects with format: { asset: String, qty: Number }
order_id
String (case sensitive). A user-defined identifier of this trade. Stored in the instance and returned on every method call to that instance.
order_type
String (case insensitive). One of: "limit" or "market".
goals
Object.
sell_asset, buy_asset
String (case insensitive). One of: "BTC" or "ETH".
sell_qty, buy_qty
Number
sell_ctx, buy_ctx
Object. Format is dependent on the values of order_type
, sell_asset
, and buy_asset
.