Skip to content

Commit 09faca8

Browse files
authored
Integrate Bluefin v2 decentralized derivatives exchange (#30)
* bluefin protocol integrate * install bluefin v2 sdk * update the tools * fix ts bugs * fix ts bugs * remove redundancy * fix eslint * fix all the eslint errors
1 parent cf24f9e commit 09faca8

File tree

6 files changed

+3431
-87
lines changed

6 files changed

+3431
-87
lines changed

packages/sui-agent/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"license": "ISC",
2020
"description": "",
2121
"dependencies": {
22+
"@bluefin-exchange/bluefin-v2-client": "^6.1.29",
2223
"@cetusprotocol/cetus-sui-clmm-sdk": "^5.2.0",
2324
"@mysten/sui": "1.1.0",
2425
"aftermath-ts-sdk": "^1.2.49",
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Bluefin Protocol Integration
2+
3+
This module provides integration with the Bluefin decentralized derivatives exchange on Sui Network.
4+
5+
## Features
6+
7+
- Order Management
8+
- Place orders (market/limit)
9+
- Cancel orders
10+
- Get user orders
11+
- Position Management
12+
- Adjust leverage
13+
- Adjust margin
14+
- Get user positions
15+
- Market Data
16+
- Get orderbook
17+
- Get market data
18+
19+
## Tools
20+
21+
### Order Management
22+
23+
#### `place_bluefin_order`
24+
Place a new order on Bluefin.
25+
26+
Parameters:
27+
- `symbol` (string, required): Trading pair symbol
28+
- `side` (string, required): Order side (BUY/SELL)
29+
- `type` (string, required): Order type (LIMIT/MARKET)
30+
- `quantity` (number, required): Order quantity
31+
- `price` (number, optional): Order price (required for LIMIT orders)
32+
- `leverage` (number, optional): Position leverage
33+
34+
#### `cancel_bluefin_order`
35+
Cancel an existing order on Bluefin.
36+
37+
Parameters:
38+
- `symbol` (string, required): Trading pair symbol
39+
- `order_id` (string, optional): Order ID to cancel
40+
- `cancel_all` (boolean, optional): Cancel all open orders
41+
42+
### Position Management
43+
44+
#### `adjust_bluefin_position`
45+
Adjust position leverage on Bluefin.
46+
47+
Parameters:
48+
- `symbol` (string, required): Trading pair symbol
49+
- `leverage` (number, required): New leverage value
50+
51+
#### `adjust_bluefin_margin`
52+
Add or remove margin from a position.
53+
54+
Parameters:
55+
- `symbol` (string, required): Trading pair symbol
56+
- `amount` (number, required): Amount to add/remove
57+
- `is_deposit` (boolean, required): True for deposit, false for withdrawal
58+
59+
### Market Data
60+
61+
#### `get_bluefin_orderbook`
62+
Get the orderbook for a trading pair.
63+
64+
Parameters:
65+
- `symbol` (string, required): Trading pair symbol
66+
67+
#### `get_bluefin_market_data`
68+
Get market data for a trading pair.
69+
70+
Parameters:
71+
- `symbol` (string, optional): Trading pair symbol
72+
73+
### User Data
74+
75+
#### `get_bluefin_user_positions`
76+
Get user's open positions.
77+
78+
Parameters:
79+
- `symbol` (string, optional): Trading pair symbol
80+
- `parent_address` (string, optional): Parent address
81+
82+
#### `get_bluefin_user_orders`
83+
Get user's orders.
84+
85+
Parameters:
86+
- `symbol` (string, optional): Trading pair symbol
87+
- `parent_address` (string, optional): Parent address
88+
89+
## Usage Example
90+
91+
```typescript
92+
// Initialize the protocol
93+
const bluefinProtocol = new BluefinProtocol(provider, keypair, {
94+
network: "mainnet",
95+
isTermAccepted: true,
96+
});
97+
98+
// Place a market order
99+
await tools.execute("place_bluefin_order", [
100+
"BTC-PERP", // symbol
101+
"BUY", // side
102+
"MARKET", // type
103+
1.0, // quantity
104+
]);
105+
106+
// Get user positions
107+
await tools.execute("get_bluefin_user_positions", [
108+
"BTC-PERP", // symbol
109+
]);
110+
```
111+
112+
## Error Handling
113+
114+
All tools return responses in a standardized format:
115+
116+
```typescript
117+
{
118+
reasoning: string; // Description of what happened
119+
response: string; // The actual response data
120+
status: string; // "success" or "failure"
121+
query: string; // The original query
122+
errors: string[]; // Array of error messages if any
123+
}
124+
```
125+
126+
## Dependencies
127+
128+
- @bluefin-exchange/bluefin-v2-client: ^6.1.29
129+
- @mysten/sui: ^1.1.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./types";
2+
export { default as BluefinTools } from "./tools";

0 commit comments

Comments
 (0)