Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nida/exc 1687 add ordersentforsettlement sockets to ts client #15

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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion public/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions src/exchange/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
GetAccountDataResponse,
MarketData,
TickerData,
OrderSentForSettlementUpdateResponse,
OrderRequeueUpdateResponse,
} from "../interfaces/routes";

// @ts-ignore
Expand Down Expand Up @@ -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
) => {
Expand Down
14 changes: 14 additions & 0 deletions src/exchange/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
UserSubscriptionAck,
TickerData,
Callbacks,
OrderSentForSettlementUpdateResponse,
OrderRequeueUpdateResponse,
} from "../interfaces/routes";

export class Sockets {
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/interfaces/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
41 changes: 41 additions & 0 deletions tests/bluefinClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
GetUserTradesResponse,
GetAccountDataResponse,
TickerData,
OrderSentForSettlementUpdateResponse,
} from "../index";
import { generateRandomNumber } from "../utils/utils";

Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading