diff --git a/package.json b/package.json index ba022a4..8337079 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bluefin-exchange/bluefin-v2-client", - "version": "2.4.0", + "version": "2.5.0", "description": "The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.", "main": "dist/index.js", "scripts": { @@ -56,7 +56,7 @@ "webpack-node-externals": "^3.0.0" }, "dependencies": { - "@firefly-exchange/library-sui": "^0.1.47", + "@firefly-exchange/library-sui": "^0.1.54", "@mysten/sui.js": "^0.35.0", "@noble/hashes": "^1.2.0", "@noble/secp256k1": "^1.7.1", diff --git a/public/package.json b/public/package.json index b095803..3b549a6 100644 --- a/public/package.json +++ b/public/package.json @@ -6,7 +6,7 @@ "build": "tsc" }, "dependencies": { - "@bluefin-exchange/bluefin-v2-client": "^2.0.0" + "@bluefin-exchange/bluefin-v2-client": "^2.5.0" }, "devDependencies": { "typescript": "^5.2.2" diff --git a/src/exchange/WebSocket.ts b/src/exchange/WebSocket.ts index 81f2e1c..3bd9c1f 100644 --- a/src/exchange/WebSocket.ts +++ b/src/exchange/WebSocket.ts @@ -14,6 +14,8 @@ import { GetAccountDataResponse, MarketData, TickerData, + OrderSentForSettlementUpdateResponse, + OrderRequeueUpdateResponse, } from "../interfaces/routes"; // @ts-ignore @@ -168,6 +170,18 @@ export class WebSockets { callbackListeners[SOCKET_EVENTS.MarketDataUpdateKey] = cb; }; + onUserOrderSentForSettlementUpdate = ( + cb: (update: OrderSentForSettlementUpdateResponse) => void + ) => { + callbackListeners[SOCKET_EVENTS.OrderSentForSettlementUpdate] = cb; + }; + + onUserOrderRequeueUpdate = ( + cb: (update: OrderRequeueUpdateResponse) => void + ) => { + callbackListeners[SOCKET_EVENTS.OrderRequeueUpdate] = cb; + }; + onMarketHealthChange = ( cb: ({ status, symbol }: { status: MARKET_STATUS; symbol: string }) => void ) => { diff --git a/src/exchange/sockets.ts b/src/exchange/sockets.ts index 5ee653e..b4f01d3 100644 --- a/src/exchange/sockets.ts +++ b/src/exchange/sockets.ts @@ -17,6 +17,8 @@ import { UserSubscriptionAck, TickerData, Callbacks, + OrderSentForSettlementUpdateResponse, + OrderRequeueUpdateResponse, } from "../interfaces/routes"; export class Sockets { @@ -156,6 +158,18 @@ export class Sockets { this.socketInstance.on(SOCKET_EVENTS.MarketHealthKey, cb); }; + onUserOrderSentForSettlementUpdate = ( + cb: (update: OrderSentForSettlementUpdateResponse) => void + ) => { + this.socketInstance.on(SOCKET_EVENTS.OrderSentForSettlementUpdate, cb); + }; + + onUserOrderRequeueUpdate = ( + cb: (update: OrderRequeueUpdateResponse) => void + ) => { + this.socketInstance.on(SOCKET_EVENTS.OrderRequeueUpdate, cb); + }; + onCandleStickUpdate = ( symbol: string, interval: string, diff --git a/src/interfaces/routes.ts b/src/interfaces/routes.ts index d8a7c15..07a1766 100644 --- a/src/interfaces/routes.ts +++ b/src/interfaces/routes.ts @@ -742,6 +742,23 @@ export interface LinkReferredUserResponse { message?: string; } +export interface OrderSentForSettlementUpdateResponse { + orderHash: string; + userAddress: string; + symbol: string; + message: string; + quantitySentForSettlement: string; + orderQuantity: string; +} + +export interface OrderRequeueUpdateResponse { + orderHash: string; + userAddress: string; + symbol: string; + message: string; + quantitySentForRequeue: string; +} + export interface Callbacks { [event: string]: Function; } diff --git a/tests/bluefinClient.test.ts b/tests/bluefinClient.test.ts index a4deb6b..b99cf4b 100644 --- a/tests/bluefinClient.test.ts +++ b/tests/bluefinClient.test.ts @@ -25,6 +25,7 @@ import { GetUserTradesResponse, GetAccountDataResponse, TickerData, + OrderSentForSettlementUpdateResponse, } from "../index"; import { generateRandomNumber } from "../utils/utils"; @@ -1162,6 +1163,26 @@ describe("BluefinClient", () => { }); }); }); + it("should receive an sent for settlement event when trade is performed", (done) => { + const callback = (update: OrderSentForSettlementUpdateResponse) => { + expect(update.symbol).to.be.equal(symbol); + done(); + }; + + client.sockets.onUserOrderSentForSettlementUpdate(callback); + + // wait for 1 sec as room might not had been subscribed + setTimeout(1000).then(async () => { + client.postOrder({ + symbol, + price: 0, + quantity: 0.001, + side: ORDER_SIDE.SELL, + leverage: defaultLeverage, + orderType: ORDER_TYPE.MARKET, + }); + }); + }); }); describe("WebSockets", () => { @@ -1331,6 +1352,26 @@ describe("BluefinClient", () => { }); }); }); + it("WebSocket Client: should receive an sent for settlement event when trade is performed", (done) => { + const callback = (update: OrderSentForSettlementUpdateResponse) => { + expect(update.symbol).to.be.equal(symbol); + done(); + }; + + client.webSockets?.onUserOrderSentForSettlementUpdate(callback); + + // wait for 1 sec as room might not had been subscribed + setTimeout(1000).then(async () => { + client.postOrder({ + symbol, + price: 0, + quantity: 0.001, + side: ORDER_SIDE.SELL, + leverage: defaultLeverage, + orderType: ORDER_TYPE.MARKET, + }); + }); + }); }); describe("Cancel On Disconnect - DMS", () => { diff --git a/yarn.lock b/yarn.lock index 5c2e041..fe3b640 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1079,10 +1079,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af" integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw== -"@firefly-exchange/library-sui@^0.1.47": - version "0.1.47" - resolved "https://registry.yarnpkg.com/@firefly-exchange/library-sui/-/library-sui-0.1.47.tgz#b7947a44736a4928ed12b5234691c877ebde993d" - integrity sha512-Q9oBl4+5ii6cx5lRF0J23otJrdlB4j9i10v3gFmr2zRNd/EykuLymylMGZwhnjouLgq3vSxozTCQ06kDHzcHCw== +"@firefly-exchange/library-sui@^0.1.54": + version "0.1.54" + resolved "https://registry.yarnpkg.com/@firefly-exchange/library-sui/-/library-sui-0.1.54.tgz#d49aa04be2d044ee25415f171032c2d2ac6615bc" + integrity sha512-k6vkZzjpLNeZfrtQZqLBkkyvb8S0PiIjexFtz/azd6mt966agn6G7jMVwr/OFd0lKi7W7DPG0o7eBtGEZ68jxQ== dependencies: "@mysten/sui.js" "^0.35.0" "@noble/hashes" "^1.2.0"