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

[EXC-1683] add examples for above features in ts client #13

Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

/* eslint-disable no-console */
import { BluefinClient, MARKET_SYMBOLS, Networks } from "../index";
import { BluefinClient, Networks } from "@bluefin-exchange/bluefin-v2-client";

async function main() {
const dummyAccountKey =
Expand Down
32 changes: 32 additions & 0 deletions public/src/examples/13.readonly_initialisation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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);
25 changes: 20 additions & 5 deletions public/src/examples/sockets/2.ordersocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,31 @@ async function main() {
"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

Expand Down
Loading