exchange.Sell
The exchange.Sell() function is used to place a sell order.
exchange.Sell(price, amount)
exchange.Sell(price, amount, ...args)Examples
-
The order number returned by
exchange.Sell()can be used to query order information and cancel orders.javascriptfunction main(){ var id = exchange.Sell(100, 1) Log("id:", id) }pythondef main(): id = exchange.Sell(100, 1) Log("id:", id)rustfn main() { let id = exchange.Sell(100, 1).unwrap(); Log!("id:", id); }c++void main() { auto id = exchange.Sell(100, 1); Log("id:", id); } -
When placing orders for cryptocurrency futures contracts, you must pay attention to whether the trading direction is set correctly. If the trading direction does not match the trading function, an error will be reported:
logdirection is sell, invalid order type Buy direction is buy, invalid order type Sell direction is closebuy, invalid order type Buy direction is closesell, invalid order type Selljavascript// The following are incorrect calls function main() { exchange.SetContractType("quarter") // Set the short direction exchange.SetDirection("sell") // Placing a buy order will report an error; shorting can only sell var id = exchange.Buy(50, 1) // Set the long direction exchange.SetDirection("buy") // Placing a sell order will report an error; going long can only buy var id2 = exchange.Sell(60, 1) // Set the close-long direction exchange.SetDirection("closebuy") // Placing a buy order will report an error; closing a long can only sell var id3 = exchange.Buy(-1, 1) // Set the close-short direction exchange.SetDirection("closesell") // Placing a sell order will report an error; closing a short can only buy var id4 = exchange.Sell(-1, 1) }python# The following are incorrect calls def main(): exchange.SetContractType("quarter") exchange.SetDirection("sell") id = exchange.Buy(50, 1) exchange.SetDirection("buy") id2 = exchange.Sell(60, 1) exchange.SetDirection("closebuy") id3 = exchange.Buy(-1, 1) exchange.SetDirection("closesell") id4 = exchange.Sell(-1, 1)rust// The following are incorrect calls fn main() { let _ = exchange.SetContractType("quarter"); // Set the short direction let _ = exchange.SetDirection("sell"); // Placing a buy order will report an error; shorting can only sell let id = exchange.Buy(50, 1); // Set the long direction let _ = exchange.SetDirection("buy"); // Placing a sell order will report an error; going long can only buy let id2 = exchange.Sell(60, 1); // Set the close-long direction let _ = exchange.SetDirection("closebuy"); // Placing a buy order will report an error; closing a long can only sell let id3 = exchange.Buy(-1, 1); // Set the close-short direction let _ = exchange.SetDirection("closesell"); // Placing a sell order will report an error; closing a short can only buy let id4 = exchange.Sell(-1, 1); }c++// The following are incorrect calls void main() { exchange.SetContractType("quarter"); exchange.SetDirection("sell"); auto id = exchange.Buy(50, 1); exchange.SetDirection("buy"); auto id2 = exchange.Sell(60, 1); exchange.SetDirection("closebuy"); auto id3 = exchange.Buy(-1, 1); exchange.SetDirection("closesell"); auto id4 = exchange.Sell(-1, 1); } -
Spot market order.
javascript// For example, trading pair: ETH_BTC, sell with a market order function main() { // Note: place a market order to sell, selling 0.2 ETH exchange.Sell(-1, 0.2) }pythondef main(): exchange.Sell(-1, 0.2)rust// For example, trading pair: ETH_BTC, sell with a market order fn main() { // Note: place a market order to sell, selling 0.2 ETH let _ = exchange.Sell(-1, 0.2); }c++void main() { exchange.Sell(-1, 0.2); }
Returns
| Type | Description |
string / null value | Returns the order Id when the order is placed successfully, and returns a null value when the order fails. The |
Arguments
| Name | Type | Required | Description |
price | number | Yes | The |
amount | number | Yes | The |
arg | string / number / bool / object / array / any (any type supported by the platform) | No | An extension parameter used to output additional information attached to this order log. Multiple |
See Also
exchange.Buy exchange.SetContractType exchange.SetDirection exchange.IO (API rate limit control; the Sell function is affected by the CreateOrder rate limit setting)
Remarks
When placing orders for futures contracts, you must pay attention to whether the trading direction is set correctly. If the trading direction does not match the trading function, an error will be reported. For cryptocurrency futures contract exchanges, the order size is denominated in number of contracts unless otherwise specified.
When the price parameter is set to -1, it is used to place a market order, which requires the exchange's order interface to support market orders. When trading cryptocurrency spot with market orders, when placing a sell order, the order size parameter amount is denominated in the trading currency. When trading cryptocurrency futures contracts with market orders, the order size parameter amount is denominated in number of contracts. In live trading, a few cryptocurrency exchanges do not support the market order interface.
If you are using an older version of the docker, the order Id returned by the exchange.Sell() function may differ from the returned order Id described in the current documentation.