From dc74c837b12d138ce006742ca330879b53477135 Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 20:09:12 +0500 Subject: [PATCH 1/4] added examples for sockets,readonly token --- .../examples/12.generate_readonly_token.ts | 28 ++++++++++++++++++ .../examples/13.readonly_initialisation.ts | 29 +++++++++++++++++++ public/src/examples/sockets/2.ordersocket.ts | 29 +++++++++++++++---- 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 public/src/examples/12.generate_readonly_token.ts create mode 100644 public/src/examples/13.readonly_initialisation.ts diff --git a/public/src/examples/12.generate_readonly_token.ts b/public/src/examples/12.generate_readonly_token.ts new file mode 100644 index 0000000..fc4e0ca --- /dev/null +++ b/public/src/examples/12.generate_readonly_token.ts @@ -0,0 +1,28 @@ +/** + * Client initialization code example + */ + +/* eslint-disable no-console */ +import { BluefinClient, Networks } from "@bluefin-exchange/bluefin-v2-client"; + +async function main() { + const dummyAccountKey = + "royal reopen journey royal enlist vote core cluster shield slush hill sample"; + + const client = new BluefinClient( + true, + Networks.TESTNET_SUI, // i.e. TESTNET_SUI or PRODUCTION_SUI + dummyAccountKey, + "ED25519" // valid values are ED25519 or Secp256k1 + ); //passing isTermAccepted = true for compliance and authorizarion + + // load/init contract addresses + await client.init(); + + //receive read-only token in response + const resp = await client.generateReadOnlyToken(); + + console.log(resp.data); +} + +main().then().catch(console.warn); diff --git a/public/src/examples/13.readonly_initialisation.ts b/public/src/examples/13.readonly_initialisation.ts new file mode 100644 index 0000000..bf177f2 --- /dev/null +++ b/public/src/examples/13.readonly_initialisation.ts @@ -0,0 +1,29 @@ +/** + * Client initialization code example + */ + +/* eslint-disable no-console */ +import { BluefinClient, Networks } from "@bluefin-exchange/bluefin-v2-client"; + +async function main() { + const dummyAccountKey = + "royal reopen journey royal enlist vote core cluster shield slush hill sample"; + + const client = new BluefinClient( + true, + Networks.TESTNET_SUI, // i.e. TESTNET_SUI or PRODUCTION_SUI + dummyAccountKey, + "ED25519" // valid values are ED25519 or Secp256k1 + ); //passing isTermAccepted = true for compliance and authorizarion + + // load/init contract addresses using read-only token + await client.init(false, null, "80a5d86820821aeae483f7cdda715e0215c1fdad612b982e7ce22c88de3ac9e2"); + + //receive user positions using readonly client + const response = await client.getUserPosition({ symbol: "ETH-PERP" }); + + + console.log(response.data); +} + +main().then().catch(console.warn); diff --git a/public/src/examples/sockets/2.ordersocket.ts b/public/src/examples/sockets/2.ordersocket.ts index 0497f7b..7ace07a 100644 --- a/public/src/examples/sockets/2.ordersocket.ts +++ b/public/src/examples/sockets/2.ordersocket.ts @@ -6,6 +6,7 @@ import { Networks, ORDER_SIDE, ORDER_TYPE, + PlaceOrderResponse, } from "@bluefin-exchange/bluefin-v2-client"; async function main() { @@ -15,21 +16,37 @@ async function main() { // using predefined network const client = new BluefinClient( true, - Networks.TESTNET_SUI, + Networks.PRODUCTION_SUI, dummyAccountKey, "ED25519" ); //passing isTermAccepted = true for compliance and authorizarion await client.init(); - client.sockets.open(); - client.sockets.subscribeGlobalUpdatesBySymbol("ETH-PERP"); - client.sockets.subscribeUserUpdateByToken(); - let callback = ({ orderbook }: any) => { console.log(orderbook); client.sockets.close(); }; - client.sockets.onOrderBookUpdate(callback); + const connection_callback = async () => { + // This callback will be invoked as soon as the socket connection is established + // start listening to local user events + client.sockets.subscribeGlobalUpdatesBySymbol("BTC-PERP"); + client.sockets.subscribeUserUpdateByToken(); + + // triggered when order updates are received + client.sockets.onOrderBookUpdate(callback); + }; + + const disconnection_callback = async () => { + console.log("Sockets disconnected, performing actions..."); + }; + + // must specify connection_callback before opening the sockets below + await client.sockets.listen("connect", connection_callback); + await client.sockets.listen("disconnect", disconnection_callback); + + console.log("Making socket connection to firefly exchange"); + client.sockets.open(); + // wait for 1 sec as room might not had been subscribed From 68366c6add986df9faa1d0b02786b0afdf4bac6a Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 20:10:25 +0500 Subject: [PATCH 2/4] bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00ad8ec..699fa34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bluefin-exchange/bluefin-v2-client", - "version": "2.3.1", + "version": "2.3.2", "description": "The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.", "main": "dist/index.js", "scripts": { From 769588c84d2196a651a2b9168d50245367fa008b Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 20:11:56 +0500 Subject: [PATCH 3/4] removed extra example --- examples/1.generate_readonly_token.ts | 28 --------------------------- 1 file changed, 28 deletions(-) delete mode 100644 examples/1.generate_readonly_token.ts diff --git a/examples/1.generate_readonly_token.ts b/examples/1.generate_readonly_token.ts deleted file mode 100644 index 2e89977..0000000 --- a/examples/1.generate_readonly_token.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Client initialization code example - */ - -/* eslint-disable no-console */ -import { BluefinClient, MARKET_SYMBOLS, Networks } from "../index"; - -async function main() { - const dummyAccountKey = - "royal reopen journey royal enlist vote core cluster shield slush hill sample"; - - const client = new BluefinClient( - true, - Networks.TESTNET_SUI, // i.e. TESTNET_SUI or PRODUCTION_SUI - dummyAccountKey, - "ED25519" // valid values are ED25519 or Secp256k1 - ); //passing isTermAccepted = true for compliance and authorizarion - - // load/init contract addresses - await client.init(); - - //receive read-only token in response - const resp = await client.generateReadOnlyToken(); - - console.log(resp.data); -} - -main().then().catch(console.warn); From 6110678f67beb92612948a27b7235249c2dc374d Mon Sep 17 00:00:00 2001 From: Nida Karim Ali Date: Fri, 15 Sep 2023 20:16:10 +0500 Subject: [PATCH 4/4] fix formatting --- public/src/examples/13.readonly_initialisation.ts | 7 +++++-- public/src/examples/sockets/2.ordersocket.ts | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/src/examples/13.readonly_initialisation.ts b/public/src/examples/13.readonly_initialisation.ts index bf177f2..3042c02 100644 --- a/public/src/examples/13.readonly_initialisation.ts +++ b/public/src/examples/13.readonly_initialisation.ts @@ -17,12 +17,15 @@ async function main() { ); //passing isTermAccepted = true for compliance and authorizarion // load/init contract addresses using read-only token - await client.init(false, null, "80a5d86820821aeae483f7cdda715e0215c1fdad612b982e7ce22c88de3ac9e2"); + await client.init( + false, + null, + "80a5d86820821aeae483f7cdda715e0215c1fdad612b982e7ce22c88de3ac9e2" + ); //receive user positions using readonly client const response = await client.getUserPosition({ symbol: "ETH-PERP" }); - console.log(response.data); } diff --git a/public/src/examples/sockets/2.ordersocket.ts b/public/src/examples/sockets/2.ordersocket.ts index 7ace07a..0e1ce83 100644 --- a/public/src/examples/sockets/2.ordersocket.ts +++ b/public/src/examples/sockets/2.ordersocket.ts @@ -6,7 +6,6 @@ import { Networks, ORDER_SIDE, ORDER_TYPE, - PlaceOrderResponse, } from "@bluefin-exchange/bluefin-v2-client"; async function main() { @@ -16,7 +15,7 @@ async function main() { // using predefined network const client = new BluefinClient( true, - Networks.PRODUCTION_SUI, + Networks.TESTNET_SUI, dummyAccountKey, "ED25519" ); //passing isTermAccepted = true for compliance and authorizarion @@ -47,7 +46,6 @@ async function main() { console.log("Making socket connection to firefly exchange"); client.sockets.open(); - // wait for 1 sec as room might not had been subscribed client.postOrder({