Skip to content

Latest commit

 

History

History
262 lines (195 loc) · 7.38 KB

Trader.md

File metadata and controls

262 lines (195 loc) · 7.38 KB

Trader

Function price

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.

Function orderbook

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.

Function status

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.

Function pending

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.

Function events

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.

Function order

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_units (e.g. ICPs) of token1 can be exchanged for 1 base_units (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)

Function buyWall

func buyWall(_pair : Principal, _buywall : [{ price : Float; quantity : Nat }]) : async [{ price : Float; quantity : Nat; result : ?ICDex.TradingResult }]

Create buy-wall

Function addLiquidity

func addLiquidity(_maker : Principal, _value0 : Nat, _value1 : Nat) : async Maker.Shares

Add liquidity to OAMM

Function removeLiquidity

func removeLiquidity(_maker : Principal, _shares : ?Nat) : async (value0 : Nat, value1 : Nat)

Remove liquidity from OAMM

Function cancel

func cancel(_pair : Principal, _txid : ICDex.Txid) : async ()

cancel order

Function fallbackFromPair

func fallbackFromPair(_pair : Principal) : async (value0 : Nat, value1 : Nat)

fallback blocked funds from Pair

Function fallbackFromMaker

func fallbackFromMaker(_maker : Principal) : async (value0 : Nat, value1 : Nat)

fallback blocked funds from Maker

Function depositToPair

func depositToPair(_pair : Principal, _value0 : ?Nat, _value1 : ?Nat) : async ()

Deposit funds from Trader to Pair

Function withdrawFromPair

func withdrawFromPair(_pair : Principal) : async ()

Withdraw funds from Pair to Trader.
This method will be deprecated and withdrawFundsFromPair() can be used.
Note: This only withdraws the available funds, if you want to withdraw all the funds, execute the cancelAll() method first.

Function withdrawFundsFromPair

func withdrawFundsFromPair(_pair : Principal, _value0 : ?Nat, _value1 : ?Nat) : async ()

Withdraw specified amount 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.

Function version

func version() : async Text

Function getOwner

func getOwner() : async Principal

Returns owner

Function changeOwner

func changeOwner(_owner : Principal) : async ()

Change owner

Function pause

func pause(_pause : Bool) : async ()

Pause or enable this Canister.

Function isPaused

func isPaused() : async Bool

Returns whether to pause or not.

Function init

func init() : async ()

Re-acquire trading pair information.
The initialization can be repeated.

Function setWhitelist

func setWhitelist(_pair : Principal) : async Bool

Add a whitelist trading pair (only these pairs are allowed to be traded)

Function removeWhitelist

func removeWhitelist(_pair : Principal) : async Bool

Remove a whitelist trading pair

Function getWhitelist

func getWhitelist() : async [Principal]

Return whitelist trading pairs

Function setOperator

func setOperator(_operator : Principal) : async Bool

Add an operator (he can only submit trade orders, not withdraw funds).

Function removeOperator

func removeOperator(_operator : Principal) : async Bool

Remove an operator

Function getOperators

func getOperators() : async [Principal]

Return operators

Function getBalances

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.

Function cancelAll

func cancelAll(_pair : Principal) : async ()

cancel all orders

Function withdraw

func withdraw(_token : Principal, _to : ICRC1.Account, _value : Nat) : async ()

Withdraw Note: To withdraw the funds being traded, you need to first call withdrawFromPair().

Function drc207

func drc207() : async DRC207.DRC207Support

DRC207 support

Function canister_status

func canister_status() : async DRC207.canister_status

Return canister_status (Need to add this CanisterId as its own controller)

Function wallet_receive

func wallet_receive() : async ()

Receive cycles