- Module : Trader.mo
- Author : ICLighthouse Team
- Stability : Experimental
- Github : https://github.com/iclighthouse/ICDex-Trader
func price(_pair : Principal) : async { price : Float; change24h : Float; vol24h : ICDex.Vol; totalVol : ICDex.Vol }
Query statistics of the pair.
Tip: This is a composite_query method that does not get results if the trading pair and Trader are not in the same subnet.
Solution: query through the stats() method of the trading pair.
func orderbook(_pair : Principal) : async (unitSize : Nat, orderBook : { ask : [(price : Float, quantity : Nat)]; bid : [(price : Float, quantity : Nat)] })
Query orderbook of the pair.
Tip: It is more efficient to query directly using the query method of the ICDex trading pair.
Tip: This is a composite_query method that does not get results if the trading pair and Trader are not in the same subnet.
Solution: query through the level100() method of the trading pair.
func status(_pair : Principal, _txid : ?ICDex.Txid) : async ICDex.OrderStatusResponse
Query the status of an order.
Tip: This is a composite_query method that does not get results if the trading pair and Trader are not in the same subnet.
Solution: query through the statusByTxid() method of the trading pair.
func pending(_pair : Principal, _page : ?Nat, _size : ?Nat) : async ICDex.TrieList<ICDex.Txid, ICDex.TradingOrder>
Orders in pending status. Note, _page start from 1.
Tip: This is a composite_query method that does not get results if the trading pair and Trader are not in the same subnet.
Solution: query through the pending() method of the trading pair.
func events(_pair : Principal) : async [DRC205.TxnRecord]
Latest 100 events.
Tip: This is a composite_query method that does not get results if the trading pair and Trader are not in the same subnet.
Solution: query through the drc205_events() method of the trading pair.
func order(_pair : Principal, _side : {#Buy; #Sell}, _price : Float, _quantity : Nat) : async ICDex.TradingResult
Place an order
Parameters:
- pair Canister-id of the pair.
- side Side of the order, its value is #Buy or #Sell.
- price Human-readable Price, e.g. SNS1/ICP = 45.00, expressed as how many
base_unit
s (e.g. ICPs) of token1 can be exchanged for 1base_unit
s (e.g. SNS1s) of token0. Price = _price * 10**token1_decimals / 10**token0_decimals * UNIT_SIZE - quantity Quantity (smallest unit) of token0 to be traded for the order. It MUST be an integer multiple of UNIT_SIZE. Note: An additional 2x token fee must be retained in the balance.
Example:
Purchase 2 SNS1s at 45.00 via SNS1/ICP pair.
order(Principal.fromText("xxxxx-xxxxx-xxxxx-cai"), #Buy, 45.00, 200000000)
func buyWall(_pair : Principal, _buywall : [{ price : Float; quantity : Nat }]) : async [{ price : Float; quantity : Nat; result : ?ICDex.TradingResult }]
Create buy-wall
func addLiquidity(_maker : Principal, _value0 : Nat, _value1 : Nat) : async Maker.Shares
Add liquidity to OAMM
func removeLiquidity(_maker : Principal, _shares : ?Nat) : async (value0 : Nat, value1 : Nat)
Remove liquidity from OAMM
func cancel(_pair : Principal, _txid : ICDex.Txid) : async ()
cancel order
func fallbackFromPair(_pair : Principal) : async (value0 : Nat, value1 : Nat)
fallback blocked funds from Pair
func fallbackFromMaker(_maker : Principal) : async (value0 : Nat, value1 : Nat)
fallback blocked funds from Maker
func depositToPair(_pair : Principal, _value0 : ?Nat, _value1 : ?Nat) : async ()
Deposit funds from Trader to Pair
func withdrawFromPair(_pair : Principal) : async ()
Withdraw funds from Pair to Trader.
Note: This only withdraws the available funds, if you want to withdraw all the funds, execute the cancelAll()
method first.
func version() : async Text
func getOwner() : async Principal
Returns owner
func changeOwner(_owner : Principal) : async ()
Change owner
func pause(_pause : Bool) : async ()
Pause or enable this Canister.
func isPaused() : async Bool
Returns whether to pause or not.
func init() : async ()
Re-acquire trading pair information.
The initialization can be repeated.
func setWhitelist(_pair : Principal) : async Bool
Add a whitelist trading pair (only these pairs are allowed to be traded)
func removeWhitelist(_pair : Principal) : async Bool
Remove a whitelist trading pair
func getWhitelist() : async [Principal]
Return whitelist trading pairs
func setOperator(_operator : Principal) : async Bool
Add an operator (he can only submit trade orders, not withdraw funds).
func removeOperator(_operator : Principal) : async Bool
Remove an operator
func getOperators() : async [Principal]
Return operators
func getBalances() : async [{ pair : Principal; tokens : (Text, Text); traderBalances : (Nat, Nat); keptInPairBalances : ICDex.KeepingBalance; OAMMPools : [{ maker : Principal; shares : Nat; shareDecimals : Nat8; NAV : Maker.UnitNetValue }] }]
Return trader's balances.
Tip: It is more efficient to query directly using the query method of the ICDex trading pair and Tokens.
func cancelAll(_pair : Principal) : async ()
cancel all orders
func withdraw(_token : Principal, _to : ICRC1.Account, _value : Nat) : async ()
Withdraw
Note: To withdraw the funds being traded, you need to first call withdrawFromPair()
.
func drc207() : async DRC207.DRC207Support
DRC207 support
func canister_status() : async DRC207.canister_status
Return canister_status (Need to add this CanisterId as its own controller)
func wallet_receive() : async ()
Receive cycles