1- import { BluefinClient , ExtendedNetwork , ADJUST_MARGIN , ORDER_STATUS } from "@bluefin-exchange/bluefin-v2-client" ;
1+ import {
2+ BluefinClient ,
3+ ExtendedNetwork ,
4+ ADJUST_MARGIN ,
5+ ORDER_STATUS ,
6+ ORDER_SIDE ,
7+ ORDER_TYPE ,
8+ PlaceOrderResponse ,
9+ CancelOrderResponse ,
10+ AdjustLeverageResponse ,
11+ GetPositionResponse ,
12+ GetOrderResponse ,
13+ GetOrderBookResponse ,
14+ MarketData
15+ } from "@bluefin-exchange/bluefin-v2-client" ;
216import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" ;
317import Tools from "../../utils/tools" ;
418import { handleError } from "../../utils" ;
@@ -11,6 +25,15 @@ import {
1125 BluefinMarketDataParams ,
1226} from "./types" ;
1327
28+ interface FormattedResponse {
29+ reasoning : string ;
30+ response : string ;
31+ status : "success" ;
32+ query : string ;
33+ errors : string [ ] ;
34+ }
35+
36+
1437class BluefinTools {
1538 private static client : BluefinClient ;
1639
@@ -35,14 +58,14 @@ class BluefinTools {
3558 return this . client ;
3659 }
3760
38- private static formatResponse ( result : any , query : string ) : string {
61+ private static formatResponse ( result : unknown , query : string ) : string {
3962 return JSON . stringify ( [ {
4063 reasoning : "Operation completed successfully" ,
4164 response : JSON . stringify ( result ) ,
4265 status : "success" ,
4366 query,
4467 errors : [ ] ,
45- } ] ) ;
68+ } as FormattedResponse ] ) ;
4669 }
4770
4871 private static formatError ( error : unknown , context : { reasoning : string ; query : string } ) : string {
@@ -97,8 +120,8 @@ class BluefinTools {
97120 try {
98121 const result = await this . placeOrder ( {
99122 symbol : args [ 0 ] as string ,
100- side : args [ 1 ] as any ,
101- type : args [ 2 ] as any ,
123+ side : args [ 1 ] as ORDER_SIDE ,
124+ type : args [ 2 ] as ORDER_TYPE ,
102125 quantity : args [ 3 ] as number ,
103126 price : args [ 4 ] as number || undefined ,
104127 leverage : args [ 5 ] as number || undefined ,
@@ -349,7 +372,7 @@ class BluefinTools {
349372 ) ;
350373 }
351374
352- private static async placeOrder ( params : BluefinOrderParams ) : Promise < any > {
375+ private static async placeOrder ( params : BluefinOrderParams ) : Promise < PlaceOrderResponse > {
353376 const { symbol, side, type, price, quantity, timeInForce, leverage } = params ;
354377
355378 if ( leverage ) {
@@ -361,85 +384,94 @@ class BluefinTools {
361384
362385 const checkprice = price || 0 ;
363386
364- return this . client . postOrder ( {
387+ const response = await this . client . postOrder ( {
365388 symbol,
366389 side,
367390 orderType : type ,
368391 price : checkprice ,
369392 quantity,
370393 timeInForce,
371394 } ) ;
395+ return response . data ;
372396 }
373397
374- private static async cancelOrder ( params : BluefinCancelOrderParams ) : Promise < any > {
398+ private static async cancelOrder ( params : BluefinCancelOrderParams ) : Promise < CancelOrderResponse > {
375399 const { symbol, orderId, cancelAll } = params ;
376400
377401 if ( cancelAll ) {
378- return this . client . cancelAllOpenOrders ( symbol ) ;
402+ const response = await this . client . cancelAllOpenOrders ( symbol ) ;
403+ return response . data ;
379404 } else if ( orderId ) {
380- return this . client . postCancelOrder ( {
405+ const response = await this . client . postCancelOrder ( {
381406 symbol,
382407 hashes : [ orderId ] ,
383408 } ) ;
409+ return response . data ;
384410 } else {
385411 throw new Error ( "Either orderId or cancelAll must be specified" ) ;
386412 }
387413 }
388414
389- private static async adjustPosition ( params : BluefinPositionParams ) : Promise < any > {
415+ private static async adjustPosition ( params : BluefinPositionParams ) : Promise < AdjustLeverageResponse > {
390416 const { symbol, leverage } = params ;
391417
392418 if ( ! leverage ) {
393419 throw new Error ( "Leverage must be specified" ) ;
394420 }
395421
396- return this . client . adjustLeverage ( {
422+ const response = await this . client . adjustLeverage ( {
397423 symbol,
398424 leverage,
399425 } ) ;
426+ return response . data ;
400427 }
401428
402- private static async adjustMargin ( params : BluefinMarginParams ) : Promise < any > {
429+ private static async adjustMargin ( params : BluefinMarginParams ) : Promise < GetPositionResponse > {
403430 const { symbol, amount, isDeposit } = params ;
404431
405- return this . client . adjustMargin (
432+ const response = await this . client . adjustMargin (
406433 symbol ,
407434 isDeposit ? ADJUST_MARGIN . Add : ADJUST_MARGIN . Remove ,
408435 amount
409436 ) ;
437+ return response . data ;
410438 }
411439
412- private static async getUserOrders ( params : BluefinUserDataParams ) : Promise < any > {
440+ private static async getUserOrders ( params : BluefinUserDataParams ) : Promise < GetOrderResponse [ ] > {
413441 const { symbol, parentAddress } = params ;
414- return this . client . getUserOrders ( {
442+ const response = await this . client . getUserOrders ( {
415443 symbol,
416444 parentAddress,
417445 statuses : [ ORDER_STATUS . OPEN , ORDER_STATUS . PARTIAL_FILLED ] ,
418446 } ) ;
447+ return response . data ;
419448 }
420449
421- private static async getUserPositions ( params : BluefinUserDataParams ) : Promise < any > {
450+ private static async getUserPositions ( params : BluefinUserDataParams ) : Promise < GetPositionResponse [ ] > {
422451 const { symbol, parentAddress } = params ;
423- return this . client . getUserPosition ( {
452+ const response = await this . client . getUserPosition ( {
424453 symbol,
425454 parentAddress,
426455 } ) ;
456+ return response . data ;
427457 }
428458
429- private static async getOrderbook ( params : BluefinMarketDataParams ) : Promise < any > {
459+ private static async getOrderbook ( params : BluefinMarketDataParams ) : Promise < GetOrderBookResponse > {
430460 const { symbol } = params ;
431461 if ( ! symbol ) {
432462 throw new Error ( "Symbol must be specified for orderbook data" ) ;
433463 }
434- return this . client . getOrderbook ( {
464+ const response = await this . client . getOrderbook ( {
435465 symbol,
436466 limit : 50 ,
437467 } ) ;
468+ return response . data ;
438469 }
439470
440- private static async getMarketData ( params : BluefinMarketDataParams ) : Promise < any > {
471+ private static async getMarketData ( params : BluefinMarketDataParams ) : Promise < MarketData > {
441472 const { symbol } = params ;
442- return this . client . getMarketData ( symbol ) ;
473+ const response = await this . client . getMarketData ( symbol ) ;
474+ return response . data ;
443475 }
444476}
445477
0 commit comments