Skip to main content

close_long (FUTURES)

This function can only be used in trade().

To put one close_long order. Each period can put at max 500# orders.

Input

exchange: string;
pair: string;
amount: number;
type: OrderType;
price: number;

Check OrderType

Example

To put one close_long order with market price for 1 amount. It is not necassery to set price with market price order.

exchange, pair, base, quote = CA.get_exchange_pair()
long_position = CA.get_position(exchange, pair, CA.PositionSide.LONG)
if long_position and long_position.available_size >= 1:
CA.close_long(exchange, pair, 1, CA.OrderType.MARKET)

To put one close_long order with limit price for 1 amount. The limit price is set as close_price.

exchange, pair, base, quote = CA.get_exchange_pair()
close_price = candles[exchange][pair][0]['close']
long_position = CA.get_position(exchange, pair, CA.PositionSide.LONG)
if long_position and long_position.available_size >= 1:
CA.close_long(exchange, pair, 1, CA.OrderType.LIMIT, close_price)