@bluefin-exchange/pro-sdk 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/example.d.ts +1 -0
- package/dist/example.js +181 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/api.d.ts +4445 -0
- package/dist/src/api.js +2317 -0
- package/dist/src/base.d.ts +66 -0
- package/dist/src/base.js +65 -0
- package/dist/src/common.d.ts +65 -0
- package/dist/src/common.js +161 -0
- package/dist/src/configuration.d.ts +91 -0
- package/dist/src/configuration.js +43 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +22 -0
- package/dist/src/request-signer.d.ts +105 -0
- package/dist/src/request-signer.js +180 -0
- package/dist/src/sdk.d.ts +55 -0
- package/dist/src/sdk.js +293 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.js +9 -0
- package/dist/src/websocket.d.ts +38 -0
- package/dist/src/websocket.js +158 -0
- package/example.ts +249 -0
- package/index.ts +1 -0
- package/openapitools.json +26 -0
- package/package.json +39 -0
- package/src/.openapi-generator/FILES +7 -0
- package/src/.openapi-generator/VERSION +1 -0
- package/src/.openapi-generator-ignore +25 -0
- package/src/api.ts +5653 -0
- package/src/base.ts +86 -0
- package/src/common.ts +150 -0
- package/src/configuration.ts +110 -0
- package/src/git_push.sh +57 -0
- package/src/index.ts +6 -0
- package/src/request-signer.ts +273 -0
- package/src/sdk.ts +381 -0
- package/src/utils.ts +6 -0
- package/src/websocket.ts +165 -0
- package/tsconfig.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
## @bluefin/bluefin-pro-sdk
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Building
|
|
5
|
+
|
|
6
|
+
To build and compile the typescript sources to javascript use:
|
|
7
|
+
```
|
|
8
|
+
npm install
|
|
9
|
+
npm run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Publishing
|
|
13
|
+
|
|
14
|
+
First build the package then run `npm publish`
|
|
15
|
+
|
|
16
|
+
### Consuming
|
|
17
|
+
|
|
18
|
+
navigate to the folder of your consuming project and run one of the following commands.
|
|
19
|
+
|
|
20
|
+
_published:_
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
npm install @bluefin/api-client@1.0.0 --save
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
_unPublished (not recommended):_
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npm install PATH_TO_GENERATED_PACKAGE --save
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Generated via
|
|
35
|
+
```
|
|
36
|
+
openapi-generator generate -i ../resources/bluefin-api.yaml -c ./sdk/openapitools.json -g typescript-axios -o sdk/src --skip-validate-spec
|
|
37
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const index_1 = require("./index");
|
|
13
|
+
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
|
|
14
|
+
const index_2 = require("./index");
|
|
15
|
+
const index_3 = require("./index");
|
|
16
|
+
// Configure logging
|
|
17
|
+
const logger = {
|
|
18
|
+
info: (message) => console.log(new Date().toISOString(), "-", message),
|
|
19
|
+
error: (message) => console.error(new Date().toISOString(), "-", message),
|
|
20
|
+
};
|
|
21
|
+
// Handle market data stream events
|
|
22
|
+
function handleMarketDataEvent(msg) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (msg.event == index_1.MarketEventType.OraclePriceUpdate) {
|
|
25
|
+
logger.info(`OraclePriceUpdate: ${JSON.stringify(msg)}`);
|
|
26
|
+
}
|
|
27
|
+
if (msg.event == index_1.MarketEventType.MarkPriceUpdate) {
|
|
28
|
+
logger.info(`MarkPriceUpdate: ${JSON.stringify(msg)}`);
|
|
29
|
+
}
|
|
30
|
+
if (msg.event == index_1.MarketEventType.MarketPriceUpdate) {
|
|
31
|
+
logger.info(`MarketPriceUpdate: ${JSON.stringify(msg)}`);
|
|
32
|
+
}
|
|
33
|
+
if (msg.event == index_1.MarketEventType.CandlestickUpdate) {
|
|
34
|
+
logger.info(`CandlestickUpdate: ${JSON.stringify(msg)}`);
|
|
35
|
+
}
|
|
36
|
+
if (msg.event == index_1.MarketEventType.OrderbookDiffDepthUpdate) {
|
|
37
|
+
logger.info(`OrderbookDiffDepthUpdate: ${JSON.stringify(msg)}`);
|
|
38
|
+
}
|
|
39
|
+
if (msg.event == index_1.MarketEventType.OrderbookPartialDepthUpdate) {
|
|
40
|
+
logger.info(`OrderbookPartialDepthUpdate: ${JSON.stringify(msg)}`);
|
|
41
|
+
}
|
|
42
|
+
if (msg.event == index_1.MarketEventType.RecentTradesUpdates) {
|
|
43
|
+
logger.info(`RecentTradesUpdates: ${JSON.stringify(msg)}`);
|
|
44
|
+
}
|
|
45
|
+
if (msg.event == index_1.MarketEventType.TickerAllUpdate) {
|
|
46
|
+
logger.info(`TickerAllUpdate: ${JSON.stringify(msg)}`);
|
|
47
|
+
}
|
|
48
|
+
if (msg.event == index_1.MarketEventType.TickerUpdate) {
|
|
49
|
+
logger.info(`TickerUpdate: ${JSON.stringify(msg)}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Handle account data stream events
|
|
54
|
+
function handleAccountDataEvent(msg) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (msg.event == index_1.AccountEventType.AccountUpdate) {
|
|
57
|
+
logger.info(`AccountUpdate: ${JSON.stringify(msg)}`);
|
|
58
|
+
}
|
|
59
|
+
if (msg.event == index_1.AccountEventType.AccountTradeUpdate) {
|
|
60
|
+
logger.info(`AccountTradeUpdate: ${JSON.stringify(msg)}`);
|
|
61
|
+
}
|
|
62
|
+
if (msg.event == index_1.AccountEventType.AccountPositionUpdate) {
|
|
63
|
+
logger.info(`AccountPositionUpdate: ${JSON.stringify(msg)}`);
|
|
64
|
+
}
|
|
65
|
+
if (msg.event == index_1.AccountEventType.AccountOrderUpdate) {
|
|
66
|
+
// if (msg.actual_instance instanceof ActiveOrderUpdate) {
|
|
67
|
+
// logger.info(`ActiveOrderUpdate: ${JSON.stringify(msg.actual_instance)}`);
|
|
68
|
+
// }
|
|
69
|
+
// if (msg.actual_instance instanceof OrderCancellationUpdate) {
|
|
70
|
+
// logger.info(
|
|
71
|
+
// `OrderCancellationUpdate: ${JSON.stringify(msg.actual_instance)}`
|
|
72
|
+
// );
|
|
73
|
+
// }
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function main() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
// Create wallet from mnemonic
|
|
80
|
+
const suiWallet = ed25519_1.Ed25519Keypair.deriveKeypair(
|
|
81
|
+
// "dilemma salmon lake ceiling moral glide cute that ginger float area aunt vague remind cage mother concert inch dizzy present proud program time urge",
|
|
82
|
+
"know puzzle puzzle table miss member token image loop velvet skin legend clarify affair wisdom alert lucky unveil mean two question nice spatial grape");
|
|
83
|
+
logger.info(`Sui Address: ${suiWallet.getPublicKey().toSuiAddress()}`);
|
|
84
|
+
const bfSigner = new index_3.BluefinRequestSigner((0, index_3.makeAddressableKeyPair)(suiWallet));
|
|
85
|
+
const client = new index_2.BluefinProSdk(bfSigner, "devnet", undefined);
|
|
86
|
+
yield client.initialize();
|
|
87
|
+
try {
|
|
88
|
+
// Get Market Data from Exchange Data API
|
|
89
|
+
const exchangeInfo = (yield client.exchangeDataApi.getExchangeInfo()).data;
|
|
90
|
+
logger.info(`Exchange Info: ${JSON.stringify(exchangeInfo)}`);
|
|
91
|
+
// Get any arbitrary market from the exchange info
|
|
92
|
+
const arbitraryMarket = exchangeInfo.markets[0];
|
|
93
|
+
logger.info(`Selected market: ${JSON.stringify(arbitraryMarket)}`);
|
|
94
|
+
const symbol = arbitraryMarket.symbol;
|
|
95
|
+
// Get market data
|
|
96
|
+
const candleStick = (yield client.exchangeDataApi.getCandlestickData(symbol, index_1.KlineInterval._1m, index_1.CandlePriceType.Oracle)).data;
|
|
97
|
+
logger.info(`Candle stick: ${JSON.stringify(candleStick)}`);
|
|
98
|
+
const depth = (yield client.exchangeDataApi.getOrderbookDepth(symbol)).data;
|
|
99
|
+
logger.info(`Depth: ${JSON.stringify(depth)}`);
|
|
100
|
+
const ticker = (yield client.exchangeDataApi.getMarketTicker(symbol)).data;
|
|
101
|
+
logger.info(`Exchange Market ticker: ${JSON.stringify(ticker)}`);
|
|
102
|
+
const recentTrades = (yield client.exchangeDataApi.getRecentTrades(symbol))
|
|
103
|
+
.data;
|
|
104
|
+
logger.info(`Recent Trades: ${JSON.stringify(recentTrades)}`);
|
|
105
|
+
const fundingRateHistory = (yield client.exchangeDataApi.getFundingRateHistory(symbol)).data;
|
|
106
|
+
logger.info(`Funding Rate History: ${JSON.stringify(fundingRateHistory)}`);
|
|
107
|
+
// Account Data API calls
|
|
108
|
+
const accountTrades = (yield client.accountDataApi.getAccountTrades(symbol, Date.now() - 10000000, Date.now(), 1000, index_1.TradeTypeEnum.Order, 1)).data;
|
|
109
|
+
logger.info(`Trades History ${JSON.stringify(accountTrades)}`);
|
|
110
|
+
const depositHistory = (yield client.accountDataApi.getAccountTransactionHistory([index_1.TransactionTypeEnum.Deposit, index_1.TransactionTypeEnum.Withdraw], symbol, Date.now() - 10000000, Date.now(), 1000, 1)).data;
|
|
111
|
+
logger.info(`Deposits history: ${JSON.stringify(depositHistory)}`);
|
|
112
|
+
const accountDetails = (yield client.accountDataApi.getAccountDetails())
|
|
113
|
+
.data;
|
|
114
|
+
logger.info(`Account Details: ${JSON.stringify(accountDetails)}`);
|
|
115
|
+
const accountPreferences = (yield client.accountDataApi.getAccountPreferences()).data;
|
|
116
|
+
logger.info(`Account Preferences: ${JSON.stringify(accountPreferences)}`);
|
|
117
|
+
// Set up WebSocket listeners
|
|
118
|
+
const accountDataListener = yield client.createAccountDataStreamListener(handleAccountDataEvent);
|
|
119
|
+
const marketDataListener = yield client.createMarketDataStreamListener(handleMarketDataEvent);
|
|
120
|
+
yield accountDataListener.send(JSON.stringify({
|
|
121
|
+
method: "Subscribe",
|
|
122
|
+
dataStreams: [
|
|
123
|
+
index_1.AccountDataStream.AccountOrderUpdate,
|
|
124
|
+
index_1.AccountDataStream.AccountPositionUpdate,
|
|
125
|
+
index_1.AccountDataStream.AccountTradeUpdate,
|
|
126
|
+
index_1.AccountDataStream.AccountTransactionUpdate,
|
|
127
|
+
index_1.AccountDataStream.AccountUpdate,
|
|
128
|
+
],
|
|
129
|
+
}));
|
|
130
|
+
yield marketDataListener.send(JSON.stringify({
|
|
131
|
+
method: "Subscribe",
|
|
132
|
+
dataStreams: [
|
|
133
|
+
{
|
|
134
|
+
symbol: symbol,
|
|
135
|
+
streams: [
|
|
136
|
+
index_1.MarketDataStreamName.MarkPrice,
|
|
137
|
+
index_1.MarketDataStreamName.RecentTrade,
|
|
138
|
+
index_1.MarketDataStreamName.OraclePrice,
|
|
139
|
+
index_1.MarketDataStreamName.Ticker,
|
|
140
|
+
index_1.MarketDataStreamName.TickerAll,
|
|
141
|
+
index_1.MarketDataStreamName.DiffDepth500Ms,
|
|
142
|
+
index_1.MarketDataStreamName.PartialDepth5,
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
}));
|
|
147
|
+
// Place order
|
|
148
|
+
const orderParams = {
|
|
149
|
+
clientOrderId: "123456",
|
|
150
|
+
type: index_1.OrderType.Limit,
|
|
151
|
+
symbol: symbol,
|
|
152
|
+
priceE9: "10000000",
|
|
153
|
+
quantityE9: "100000000000",
|
|
154
|
+
side: index_1.OrderSide.Long,
|
|
155
|
+
leverageE9: "1000000000",
|
|
156
|
+
isIsolated: false,
|
|
157
|
+
expiresAtUtcMillis: Date.now() + 60000,
|
|
158
|
+
postOnly: false,
|
|
159
|
+
reduceOnly: false,
|
|
160
|
+
timeInForce: index_1.OrderTimeInForce.Gtt,
|
|
161
|
+
};
|
|
162
|
+
const orderCreationResult = (yield client.createOrder(orderParams)).data;
|
|
163
|
+
logger.info(`Order Creation Result: ${JSON.stringify(orderCreationResult)}`);
|
|
164
|
+
logger.info("Update Leverage to 2");
|
|
165
|
+
yield client.updateLeverage(symbol, "2000000000");
|
|
166
|
+
// Withdraw 10 USD
|
|
167
|
+
yield client.withdraw("USDC", "10000000000");
|
|
168
|
+
logger.info("Withdraw request success");
|
|
169
|
+
// Keep connection alive
|
|
170
|
+
yield new Promise((resolve) => setTimeout(resolve, 50000));
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
yield client.dispose();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// Run the main function
|
|
178
|
+
main().catch((error) => {
|
|
179
|
+
console.error("Error in main:", error);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/index"), exports);
|