Cancel Order Signature

The method Create Order Cancellation Signature allows user to create cancellation signatures for the provided orders. Similar to creating orders, signatures are used to validate the authenticity of the request since the order must be cancelled off-chain on the orderbook before being cancelled on-chain.

Sub Accounts: If trading as a sub account, set the maker field to the address of the parent account. Read more about Sub Accounts here.

The method takes the following input parameters:

  • interface OrderCancelSignatureRequest {
      symbol: MarketSymbol; // symbol of market of orders to be cancelled
      hashes: string[]; // hash of the orders to be cancelled
      parentAddress?: string // (optional) specify parent account if trading as a sub account
    }
    
    class OrderCancelSignatureRequest(TypedDict):
      symbol: MARKET_SYMBOLS # symbol of market of orders to be cancelled
      hashes: list  # hash of the orders to be cancelled
      parentAddress: str # (optional) should only be provided by a sub account
    

The order hash parameter is returned as part of the post order response or can be obtained via the get order routes.

Examples

/* eslint-disable no-console */
import {
  Networks, 
  BluefinClient
  ORDER_STATUS,
  ORDER_SIDE,
  ORDER_TYPE,
  toBaseNumber,
  MinifiedCandleStick,
  Faucet,
  OrderSigner,
  parseSigPK,
  ADJUST_MARGIN,
} from "@bluefin-exchange/bluefin-v2-client";

async function main() {
  const dummyAccountKey =
    "trigger swim reunion gate hen black real deer light nature trial dust";

  const client = new BluefinClient(
    true,
    Networks.TESTNET_SUI,
    dummyAccountKey,
    "ED25519" //valid values are ED25519 or Secp256k1
  ); //passing isTermAccepted = true for compliance and authorizarion
  await client.init();

  let symbol = "ETH-PERP";
  // post a limit order
  const response = await client.postOrder({
    symbol: symbol,
    price: 50,
    quantity: 0.5,
    side: ORDER_SIDE.SELL,
    orderType: ORDER_TYPE.LIMIT,
    leverage: 3,
  });

  // create signature
  const cancelSignature = await client.createOrderCancellationSignature({
    symbol: symbol,
    hashes: [response.response.data.hash],
  });
  console.log("Cancellation Signatures:", cancelSignatures);
}

main().then().catch(console.warn);

from pprint import pprint
import asyncio
import time
import random
from config import TEST_ACCT_KEY
from bluefin_v2_client import (
    BluefinClient,
    Networks,
    MARKET_SYMBOLS,
    ORDER_SIDE,
    ORDER_TYPE,
    ORDER_STATUS,
    OrderSignatureRequest,
)


async def main():
    client = BluefinClient(True, Networks["SUI_STAGING"], TEST_ACCT_KEY)
    await client.init(True)

    leverage = 1
    await client.adjust_leverage(MARKET_SYMBOLS.ETH, leverage)
    order = OrderSignatureRequest(
        symbol=MARKET_SYMBOLS.ETH,  # market symbol
        price=2905,  # price at which you want to place order
        quantity=0.01,  # quantity
        side=ORDER_SIDE.BUY,
        orderType=ORDER_TYPE.LIMIT,
        leverage=leverage,
        salt=random.randint(0, 100000000),
        expiration=int(time.time() + (30 * 24 * 60 * 60)) * 1000,
    )
    signed_order = client.create_signed_order(order)
    post_resp = await client.post_signed_order(signed_order)
    pprint(post_resp)
    time.sleep(2)

    # cancel placed order
    cancellation_request = client.create_signed_cancel_orders(
        MARKET_SYMBOLS.ETH, order_hash=[post_resp["hash"]]
    )
    cancellation_request = client.create_signed_cancel_order(order)
    pprint(cancellation_request)
    cancel_resp = await client.post_cancel_order(cancellation_request)
    pprint(cancel_resp)

    # post order again
    await client.adjust_leverage(MARKET_SYMBOLS.ETH, leverage)
    order = OrderSignatureRequest(
        symbol=MARKET_SYMBOLS.ETH,  # market symbol
        price=2905,  # price at which you want to place order
        quantity=0.01,  # quantity
        side=ORDER_SIDE.BUY,
        orderType=ORDER_TYPE.LIMIT,
        leverage=leverage,
        salt=random.randint(0, 100000000),
        expiration=int(time.time() + (30 * 24 * 60 * 60)) * 1000,
    )
    signed_order = client.create_signed_order(order)
    post_resp = await client.post_signed_order(signed_order)
    pprint(post_resp)
    time.sleep(2)

    # this time cancel all open orders
    resp = await client.cancel_all_orders(
        MARKET_SYMBOLS.ETH, [ORDER_STATUS.OPEN, ORDER_STATUS.PARTIAL_FILLED]
    )
    if resp is False:
        print("No open order to cancel")
    else:
        pprint(resp)

    await client.close_connections()


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    loop.run_until_complete(main())
    loop.close()

  loop.close()

Order Cancellation Signatures in Other Languages

To use the API, you may choose any other language or library that allows you to make HTTP requests. While we don't support official libraries for other languages, you can find a list of order cancellation signature creation examples in various languages here.