put https://trade.api.{env}.bluefin.io/api/v1/trade/orders/cancel/standby
Cancel orders in standby for a market using order hashes.
- May be a single order hash or a list of order hashes.
- All orders must belong to the same account.
- If no order hashes are specified, then will cancel all orders for the given market
- All orders being cancelled by request will receive the same time priority.
Client Library
#!/usr/bin/env python
import asyncio
import logging
import time
from bluefin_pro_sdk import BluefinProSdk, Environment
from crypto_helpers.signature import SuiWallet
from openapi_client import CancelOrdersRequest
# Set up logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
def now():
"""Return the current time in milliseconds since the Epoch."""
return int(time.time() * 1000)
async def main():
"""
Example showing how to cancel orders using the Bluefin Pro API
using the PRODUCTION environment.
"""
# Create a wallet with your private key
sui_wallet = SuiWallet(
mnemonic="dilemma salmon lake ceiling moral glide cute that ginger float area aunt vague remind cage mother concert inch dizzy present proud program time urge"
)
log.info(f"Using wallet address: {sui_wallet.sui_address}")
# Initialize the Bluefin Pro SDK client with PRODUCTION environment and RPC
async with BluefinProSdk(
sui_wallet=sui_wallet,
env=Environment.PRODUCTION,
debug=False # Set to True for more verbose output
) as client:
try:
# Initialize the client, which will handle authentication
await client.init()
# Get Market Data from the Exchange Data API.
exchange_info = await client.exchange_data_api.get_exchange_info()
log.info(f"{exchange_info=}")
# We'll work with the ETH-PERP market for this example, but you could as
# well choose any other market available on the Bluefin Pro exchange.
market = next(
market for market in exchange_info.markets if market.symbol == "ETH-PERP"
)
log.info(f"{market=}")
# ========= Cancel an Order(s) ==========
log.info("Cancelling Orders for this market")
await client.cancel_standby_order(
CancelOrdersRequest(
symbol=market.symbol,
)
)
except Exception as e:
log.error(f"Error cancelling orders: {e}")
raise
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
log.info("Exiting due to keyboard interrupt")
use bluefin_api::apis::configuration::Configuration;
use bluefin_api::apis::trade_api::{cancel_standby_orders, post_create_order};
use bluefin_api::models::{
CancelOrdersRequest, CreateOrderRequest, CreateOrderRequestSignedFields, LoginRequest,
OrderSide, OrderType, SelfTradePreventionType,
};
use bluefin_pro::prelude::*;
use chrono::{TimeDelta, Utc};
use hex::FromHex;
use rand::random;
use std::ops::Add;
use sui_sdk_types::SignatureScheme;
type Error = Box<dyn std::error::Error>;
type Result<T> = std::result::Result<T, Error>;
/// Submits the specified request to Bluefin.
///
/// # Errors
///
/// Will return `Err` if the request fails, or cannot be submitted.
async fn send_request(request: CancelOrdersRequest, auth_token: &str) -> Result<()> {
println!("Sending request...");
// Send request and get back order hash
let mut config = Configuration::new();
config.bearer_access_token = Some(auth_token.into());
config.base_path = trade::testnet::URL.into();
cancel_standby_orders(&config, request).await?;
Ok(())
}
async fn send_create_order_request(
request: CreateOrderRequest,
auth_token: &str,
) -> Result<String> {
println!("Sending request...");
// Send request and get back order hash
let mut config = Configuration::new();
config.bearer_access_token = Some(auth_token.into());
config.base_path = trade::testnet::URL.into();
let order_hash = post_create_order(&config, request).await?.order_hash;
Ok(order_hash)
}
#[tokio::main]
async fn main() -> Result<()> {
let environment = Environment::Production;
// Then, we construct an authentication request.
let request = LoginRequest {
account_address: "INSERT_ACCOUNT_ADDRESS_HERE".to_string(),
audience: auth::production::AUDIENCE.into(),
signed_at_millis: Utc::now().timestamp_millis(),
};
// Next, we generate a signature for our request.
let signature = request.signature(
SignatureScheme::Ed25519,
PrivateKey::from_hex("INSERT_HEX_ENCODED_PRIVATE_KEY_HERE")?,
)?;
// Then, we submit our authentication request to the API for the desired environment.
let auth_token = request
.authenticate(&signature, environment)
.await?
.access_token;
// We get the exchange info to fetch the IDS_ID
let contracts_info = exchange::info::contracts_config(environment).await?;
// Let's open an order on the book
let request = CreateOrderRequest {
signed_fields: CreateOrderRequestSignedFields {
symbol: "ETH-PERP".to_string(),
account_address: environment.test_keys().unwrap().address.into(),
price_e9: ("0").to_string(),
quantity_e9: (1.e9()).to_string(),
side: OrderSide::Short,
leverage_e9: (10.e9()).to_string(),
is_isolated: false,
salt: random::<u64>().to_string(),
ids_id: contracts_info.ids_id,
expires_at_millis: Utc::now().add(TimeDelta::minutes(6)).timestamp_millis(),
signed_at_millis: Utc::now().timestamp_millis(),
},
signature: String::new(),
client_order_id: None,
r#type: OrderType::StopMarket,
reduce_only: true,
post_only: None,
time_in_force: None,
trigger_price_e9: Some((10_000.e9()).to_string()),
self_trade_prevention_type: Some(SelfTradePreventionType::Maker),
};
// Then, we sign our order.
let request = request.sign(
PrivateKey::from_hex(environment.test_keys().unwrap().private_key)?,
SignatureScheme::Ed25519,
)?;
let order_hash = send_create_order_request(request, &auth_token).await?;
// Next, we construct our cancellation request.
let request = CancelOrdersRequest {
symbol: "ETH-PERP".to_string(),
order_hashes: Some(vec![order_hash.clone()]),
};
// Now, we submit our cancellation request to Bluefin.
send_request(request, &auth_token).await?;
// Finally, we print a confirmation message.
println!("Orders Cancellation submitted successfully.");
Ok(())
}
HTTPs
Alternatively, call the PUT /trade/orders/cancel/standby endpoint using the integrated editor on the right or locally from any language supporting HTTPs network calls.