The exchange.Sell()
function is used to place sell orders.
A successful order returns the order Id, a failed order returns a null value. The attribute Id
of the order {@struct/Order Order} structure of the FMZ platform consists of the exchange product code and the exchange original order ID, separated by English commas. For example, the attribute Id
format of the spot trading pair ETH_USDT
order of the OKX exchange is: ETH-USDT,1547130415509278720
. When calling the exchange.Sell()
function to place an order, the return value order Id
is consistent with the Id
attribute of the order {@struct/Order Order} structure.
string, null value
exchange.Sell(price, amount) exchange.Sell(price, amount, …args)
The price
parameter is used to set the order price.
price
true
number
The amount
parameter is used to set the order amount.
amount
true
number
Extended parameters that can output accompanying information to this order log, arg
parameters can be passed more than one.
arg
false
string, number, bool, object, array, null and any other type supported by the system
function main(){
var id = exchange.Sell(100, 1)
Log("id:", id)
}
def main():
id = exchange.Sell(100, 1)
Log("id:", id)
void main() {
auto id = exchange.Sell(100, 1);
Log("id:", id);
}
The order number returned by exchange.Sell()
can be used to query order information and cancel orders.
// The following is an error call
function main() {
exchange.SetContractType("quarter")
// Set the shorting direction
exchange.SetDirection("sell")
// If you place a buy order, an error will be reported, and shorting can only be sold
var id = exchange.Buy(50, 1)
// Set the long direction
exchange.SetDirection("buy")
// If you place a sell order, it will report an error, go long, only buy
var id2 = exchange.Sell(60, 1)
// Set direction to close long positions
exchange.SetDirection("closebuy")
// If you place a buy order, it will report an error, close long, only sell
var id3 = exchange.Buy(-1, 1)
// Set direction to close short positions
exchange.SetDirection("closesell")
// If you place a sell order, it will report an error, close short, only buy
var id4 = exchange.Sell(-1, 1)
}
# The following is an error call
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)
// The following is an error call
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);
}
When placing an order for a cryptocurrency futures contract, care must be taken to ensure that the trade direction is set correctly, as a mismatch between the trade direction and the trade function will result in an error:
direction 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 Sell
// For example, the trading pair: ETH_BTC, place a sell order at the market price
function main() {
// Note: place a market order to sell, sell 0.2 ETH
exchange.Sell(-1, 0.2)
}
def main():
exchange.Sell(-1, 0.2)
void main() {
exchange.Sell(-1, 0.2);
}
Spot market order.
When placing an order for a futures contract, you must pay attention to whether the trade direction is set correctly, as an error will be reported if the trade direction and the trade function do not match. The order amount for cryptocurrency futures contracts is the number of contracts if not specified.
The parameter price
is set to -1
for placing market orders, which requires the exchange’s order placement interface to support market orders. When placing market orders for cryptocurrency spot contracts, the amount parameter amount
is the amount in trading currency. When placing market orders for cryptocurrency futures contracts, the amount parameter amount
is the number of contracts. There are a few cryptocurrency exchanges that do not support market order interface during live trading.
If you are using an older version of the docker, the return value of the order Id
of the exchange.Sell()
function may be different from the return value of the order Id
described in the current document.
{@fun/Trade/exchange.Buy exchange.Buy}, {@fun/Futures/exchange.SetContractType exchange.SetContractType}, {@fun/Futures/exchange.SetDirection exchange.SetDirection}
exchange.Buy exchange.CreateOrder