Get & Adjust Leverage

Bluefin Exchange currently supports Isolated Margining with up to 20x leverage. As such user's have isolated control over each market's leverage.

All orders for a given market must be placed at the same leverage as the user set market leverage.

Get Leverage

The method Get User Default Leverage returns a user's set leverage for a given market. The method takes in the following parameter:

  • Market Symbol: Symbol of the market in format "{ASSET_SYMBOL}-PERP" eg: "BTC-PERP", "ETH-PERP"

Adjust Leverage

The Adjust Leverage method allows users to update the market leverage.

Note that you should cancel all open orders before updating leverage. This method will force cancel any remaining open orders at the previous market leverage.

Sub Accounts: If trading as a sub account, specify the parentAddress field. Read more about Sub Accounts here.

The method expects the following parameters:

  • Symbol: Symbol of the market in format "{ASSET_SYMBOL}-PERP" eg: "BTC-PERP", "ETH-PERP"
  • Leverage: New leverage
  • Parent Address (optional): Specify parent account if trading as a sub account

Examples

import { Networks, BluefinClient } from "@bluefin-exchange/bluefin-v2-client";

async function main() {

  // ensure account has funds to pay gas
  const dummyAccountKey =
    "trigger swim reunion gate hen black real deer light nature trial dust";

  // using TESTNET network, getUSDCBalance does not work on MAINNET
  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();
  
  // returns the user default leverage
  console.log("Initial leverage: ", await client.getUserDefaultLeverage(MARKET_SYMBOLS.BTC));

  // set BTC market to 10x leverage  
  await client.adjustLeverage({
    symbol:MARKET_SYMBOLS.BTC,
    leverage: 10,
  })
}

main().then().catch(console.warn);
from bluefin_v2_client import BluefinClient, Networks, MARKET_SYMBOLS
import asyncio

async def main():
    ed25519_wallet_seed_phrase =
    "person essence firm tail chapter forest return pulse dismiss unlock zebra amateur";

  	client = BluefinClient(
      True, # agree to terms and conditions
      Networks["SUI_STAGING"], # network to connect i.e. SUI_STAGING or SUI_PROD
      ed25519_wallet_seed_phrase, # seed phrase of the wallet
  	)

    await client.init(True)

    print("Leverage on BTC market:", await client.get_user_leverage(MARKET_SYMBOLS.BTC))
    # we have a position on BTC so this will perform on-chain leverage update
    # must have native chain tokens to pay for gas fee
    await client.adjust_leverage(MARKET_SYMBOLS.BTC, 2)

    print("Leverage on BTC market:", await client.get_user_leverage(MARKET_SYMBOLS.BTC))

    print("Leverage on ETH market:", await client.get_user_leverage(MARKET_SYMBOLS.ETH))
    # since we don't have a position on-chain, it will perform off-chain leverage adjustment
    await client.adjust_leverage(MARKET_SYMBOLS.ETH, 8)

    print("Leverage on ETH market:", await client.get_user_leverage(MARKET_SYMBOLS.ETH))

    await client.close_connections()


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