Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Users can import predefined networks from [constants](https://github.com/firefly
from bluefin_v2_client import Networks
```

For testing purposes use `Networks[SUI_STAGING]` and for production use `Networks[SUI_PROD]`.
For testing purposes use `Networks["SUI_STAGING"]` and for production use `Networks["SUI_PROD"]`.

## Initialization example​

Expand Down
14 changes: 4 additions & 10 deletions examples/1.initialization.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import os
import sys

# sys.path.append(os.getcwd() + "/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK

from bluefin_v2_client import BluefinClient, Networks
from pprint import pprint
import asyncio

from bluefin_v2_client import BluefinClient, Networks


async def main():
# initialize client
Expand All @@ -23,13 +18,12 @@ async def main():

print("Account Address:", client.get_public_address())

# # gets user account data on-chain
# gets user account data on-chain
data = await client.get_user_account_data()
pprint(data)

await client.close_connections()

pprint(data)


if __name__ == "__main__":
loop = asyncio.new_event_loop()
Expand Down
6 changes: 0 additions & 6 deletions examples/10.1.socket_readonly.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import sys, os

# sys.path.append(os.getcwd() + "/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import BluefinClient, Networks, MARKET_SYMBOLS, SOCKET_EVENTS
import asyncio

TEST_NETWORK = "SUI_STAGING"

event_received = False


Expand Down
5 changes: 0 additions & 5 deletions examples/10.sockets.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import sys, os

# sys.path.append(os.getcwd() + "/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import BluefinClient, Networks, MARKET_SYMBOLS, SOCKET_EVENTS
import asyncio

TEST_NETWORK = "SUI_STAGING"
event_received = False


Expand Down
2 changes: 0 additions & 2 deletions examples/12.open_order_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
)
import asyncio

TEST_NETWORK = "SUI_STAGING"

event_received = False


Expand Down
3 changes: 1 addition & 2 deletions examples/13.orderbook_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sys.path.append(os.getcwd() + "/src/")
import time
from config import TEST_ACCT_KEY, TEST_NETWORK
import asyncio
from bluefin_v2_client import (
BluefinClient,
Networks,
Expand All @@ -16,9 +17,7 @@
ORDER_TYPE,
OrderSignatureRequest,
)
import asyncio

TEST_NETWORK = "SUI_STAGING"

event_received = False

Expand Down
17 changes: 4 additions & 13 deletions examples/2.user_info.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import sys, os

# sys.path.append(os.getcwd() + "/src/")
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import BluefinClient, Networks, MARKET_SYMBOLS
from pprint import pprint
import asyncio
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import BluefinClient, Networks, MARKET_SYMBOLS


async def main():
# create client instance
client = BluefinClient(
True, # agree to terms and conditions
Networks[TEST_NETWORK], # network to connect with
Expand All @@ -21,18 +17,13 @@ async def main():

# gets user account data on Bluefin exchange
data = await client.get_user_account_data()

pprint(data)

position = await client.get_user_position({"symbol": MARKET_SYMBOLS.ETH})

# returns {} when user has no position
pprint(position)
pprint(position) # returns {} when user has no position

position = await client.get_user_position({"symbol": MARKET_SYMBOLS.BTC})

# returns user position if exists
pprint(position)
pprint(position) # returns user position if exists

await client.close_connections()

Expand Down
36 changes: 15 additions & 21 deletions examples/3.balance.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import sys, os

# sys.path.append(os.getcwd() + "/src/")

from pprint import pprint
import asyncio
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import BluefinClient, Networks
import asyncio


async def main():
Expand All @@ -19,37 +16,34 @@ async def main():
# on boards user on Bluefin. Must be set to true for first time use
await client.init(True)

# checks chain native token balance.
# A user must have native tokens to perform contract calls

# checks SUI token balance
print("Chain token balance:", await client.get_native_chain_token_balance())

# check margin bank balance on-chain
# check usdc balance deposited to Bluefin Margin Bank
print("Margin bank balance:", await client.get_margin_bank_balance())

# check usdc balance user has on-chain
# check usdc balance deposited to USDC contract
print("USDC balance:", await client.get_usdc_balance())

# deposit usdc to margin bank
# must have native chain tokens to pay for gas fee
usdc_coins = client.get_usdc_coins()
## we expect that you have some coins in your usdc,
coin_obj_id = usdc_coins["data"][1]["coinObjectId"]
print("USDC deposited:", await client.deposit_margin_to_bank(5000, coin_obj_id))
usdc_coins = await client.get_usdc_coins()
pprint(usdc_coins)

# deposit 100 usdc to margin bank
print("USDC deposited:", await client.deposit_margin_to_bank(100))

# check margin bank balance
resp = await client.get_margin_bank_balance()
print("Margin bank balance:", resp)
print("Margin bank balance after deposit:", resp)

# withdraw margin bank balance
print("USDC Withdrawn:", await client.withdraw_margin_from_bank(10))
print("USDC Withdrawn:", await client.withdraw_margin_from_bank(100))

# check margin bank balance
print("Margin bank balance:", await client.get_margin_bank_balance())
print("Margin bank balance after withdraw:", await client.get_margin_bank_balance())

print("Withdraw all", await client.withdraw_all_margin_from_bank())
# print("Withdraw all", await client.withdraw_all_margin_from_bank())

print("Margin bank balance:", await client.get_margin_bank_balance())
# print("Margin bank balance:", await client.get_margin_bank_balance())
await client.close_connections()


Expand Down
59 changes: 20 additions & 39 deletions examples/4.placing_orders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, os

# sys.path.append(os.getcwd() + "/src/")
from pprint import pprint
import asyncio
import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_v2_client import (
BluefinClient,
Expand All @@ -10,65 +10,48 @@
ORDER_TYPE,
OrderSignatureRequest,
)
import asyncio


async def place_limit_order(client: BluefinClient):
async def place_orders(client: BluefinClient):
# default leverage of account is set to 3 on Bluefin
user_leverage = await client.get_user_leverage(MARKET_SYMBOLS.ETH)
print("User Leverage", user_leverage)
print("User Default Leverage", user_leverage)

# creates a LIMIT order to be signed
# Sign and place a limit order at 4x leverage. Order is signed using the account seed phrase set on the client
adjusted_leverage = 4
await client.adjust_leverage(MARKET_SYMBOLS.ETH, adjusted_leverage)
signature_request = OrderSignatureRequest(
symbol=MARKET_SYMBOLS.ETH, # market symbol
price=1636.8, # price at which you want to place order
quantity=0.01, # quantity
side=ORDER_SIDE.BUY,
orderType=ORDER_TYPE.LIMIT,
leverage=user_leverage,
leverage=adjusted_leverage,
expiration=int(
(time.time() + 864000) * 1000
), # expiry after 10 days, default expiry is a month
)

# create signed order
signed_order = client.create_signed_order(signature_request)

print("Placing a limit order")
# place signed order on orderbook
resp = await client.post_signed_order(signed_order)
pprint({"msg": "placing limit order", "resp": resp})

# returned order with PENDING state
print(resp)

return


async def place_market_order(client: BluefinClient):
# default leverage of account is set to 3 on Bluefin
user_leverage = await client.get_user_leverage(MARKET_SYMBOLS.ETH)

# sign and place a market order at 2x leverage
adjusted_leverage = 2
await client.adjust_leverage(MARKET_SYMBOLS.BTC, adjusted_leverage)
signature_request = OrderSignatureRequest(
symbol=MARKET_SYMBOLS.ETH,
symbol=MARKET_SYMBOLS.BTC,
price=0,
quantity=1,
leverage=user_leverage,
leverage=adjusted_leverage,
side=ORDER_SIDE.BUY,
reduceOnly=False,
postOnly=False,
orderbookOnly=True,
expiration=1700530261000,
salt=1668690862116,
orderType=ORDER_TYPE.MARKET,
)

# create signed order
signed_order = client.create_signed_order(signature_request)

print("Placing a market order")
# place signed order on orderbook
resp = await client.post_signed_order(signed_order)

# returned order with PENDING state
print(resp)

pprint({"msg": "placing market order", "resp": resp})
return


Expand All @@ -81,9 +64,7 @@ async def main():
)

await client.init(True)

await place_limit_order(client)
await place_market_order(client)
await place_orders(client)

await client.close_connections()

Expand Down
39 changes: 0 additions & 39 deletions examples/5.adjusting_leverage.py

This file was deleted.

Loading