@decibeltrade/sdk 0.1.1

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.
Files changed (294) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-lint$colon$check.log +5 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/decibel_transactions.md +1049 -0
  5. package/dist/abi/abi-manager.d.ts +13 -0
  6. package/dist/abi/abi-manager.d.ts.map +1 -0
  7. package/dist/abi/abi-manager.js +21 -0
  8. package/dist/abi/abis.json +1322 -0
  9. package/dist/abi/bytecode-manager.d.ts +57 -0
  10. package/dist/abi/bytecode-manager.d.ts.map +1 -0
  11. package/dist/abi/bytecode-manager.js +62 -0
  12. package/dist/abi/bytecode.json +24 -0
  13. package/dist/abi/fetch-abis.d.ts +7 -0
  14. package/dist/abi/fetch-abis.d.ts.map +1 -0
  15. package/dist/abi/fetch-abis.js +132 -0
  16. package/dist/abi/fetch-bytecode.d.ts +24 -0
  17. package/dist/abi/fetch-bytecode.d.ts.map +1 -0
  18. package/dist/abi/fetch-bytecode.js +123 -0
  19. package/dist/abi/generate-abis.d.ts +6 -0
  20. package/dist/abi/generate-abis.d.ts.map +1 -0
  21. package/dist/abi/generate-abis.js +170 -0
  22. package/dist/abi/json/netna.json +1323 -0
  23. package/dist/abi/json/testnet.json +1315 -0
  24. package/dist/abi/types.d.ts +22 -0
  25. package/dist/abi/types.d.ts.map +1 -0
  26. package/dist/abi/types.js +2 -0
  27. package/dist/admin.d.ts +29 -0
  28. package/dist/admin.d.ts.map +1 -0
  29. package/dist/admin.js +203 -0
  30. package/dist/base.d.ts +42 -0
  31. package/dist/base.d.ts.map +1 -0
  32. package/dist/base.js +176 -0
  33. package/dist/constants.d.ts +41 -0
  34. package/dist/constants.d.ts.map +1 -0
  35. package/dist/constants.js +78 -0
  36. package/dist/fee-pay.d.ts +11 -0
  37. package/dist/fee-pay.d.ts.map +1 -0
  38. package/dist/fee-pay.js +30 -0
  39. package/dist/gas/gas-price-manager.d.ts +35 -0
  40. package/dist/gas/gas-price-manager.d.ts.map +1 -0
  41. package/dist/gas/gas-price-manager.js +93 -0
  42. package/dist/gas-price-manager.d.ts +31 -0
  43. package/dist/gas-price-manager.d.ts.map +1 -0
  44. package/dist/gas-price-manager.js +84 -0
  45. package/dist/index.d.ts +11 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +26 -0
  48. package/dist/order-event.types.d.ts +55 -0
  49. package/dist/order-event.types.d.ts.map +1 -0
  50. package/dist/order-event.types.js +3 -0
  51. package/dist/order-status.d.ts +43 -0
  52. package/dist/order-status.d.ts.map +1 -0
  53. package/dist/order-status.js +86 -0
  54. package/dist/read/account-overview/account-overview.reader.d.ts +37 -0
  55. package/dist/read/account-overview/account-overview.reader.d.ts.map +1 -0
  56. package/dist/read/account-overview/account-overview.reader.js +35 -0
  57. package/dist/read/account-overview/account-overview.types.d.ts +52 -0
  58. package/dist/read/account-overview/account-overview.types.d.ts.map +1 -0
  59. package/dist/read/account-overview/account-overview.types.js +36 -0
  60. package/dist/read/api-wallets/api-wallets.reader.d.ts +17 -0
  61. package/dist/read/api-wallets/api-wallets.reader.d.ts.map +1 -0
  62. package/dist/read/api-wallets/api-wallets.reader.js +27 -0
  63. package/dist/read/api-wallets/api-wallets.types.d.ts +17 -0
  64. package/dist/read/api-wallets/api-wallets.types.d.ts.map +1 -0
  65. package/dist/read/api-wallets/api-wallets.types.js +13 -0
  66. package/dist/read/base-reader.d.ts +22 -0
  67. package/dist/read/base-reader.d.ts.map +1 -0
  68. package/dist/read/base-reader.js +29 -0
  69. package/dist/read/candlesticks/candlesticks.reader.d.ts +31 -0
  70. package/dist/read/candlesticks/candlesticks.reader.d.ts.map +1 -0
  71. package/dist/read/candlesticks/candlesticks.reader.js +43 -0
  72. package/dist/read/candlesticks/candlesticks.types.d.ts +45 -0
  73. package/dist/read/candlesticks/candlesticks.types.d.ts.map +1 -0
  74. package/dist/read/candlesticks/candlesticks.types.js +36 -0
  75. package/dist/read/delegations/delegations.reader.d.ts +15 -0
  76. package/dist/read/delegations/delegations.reader.d.ts.map +1 -0
  77. package/dist/read/delegations/delegations.reader.js +23 -0
  78. package/dist/read/delegations/delegations.types.d.ts +17 -0
  79. package/dist/read/delegations/delegations.types.d.ts.map +1 -0
  80. package/dist/read/delegations/delegations.types.js +13 -0
  81. package/dist/read/index.d.ts +105 -0
  82. package/dist/read/index.d.ts.map +1 -0
  83. package/dist/read/index.js +244 -0
  84. package/dist/read/leaderboard/leaderboard.reader.d.ts +21 -0
  85. package/dist/read/leaderboard/leaderboard.reader.d.ts.map +1 -0
  86. package/dist/read/leaderboard/leaderboard.reader.js +22 -0
  87. package/dist/read/leaderboard/leaderboard.types.d.ts +27 -0
  88. package/dist/read/leaderboard/leaderboard.types.d.ts.map +1 -0
  89. package/dist/read/leaderboard/leaderboard.types.js +14 -0
  90. package/dist/read/market-contexts/market-contexts.reader.d.ts +22 -0
  91. package/dist/read/market-contexts/market-contexts.reader.d.ts.map +1 -0
  92. package/dist/read/market-contexts/market-contexts.reader.js +27 -0
  93. package/dist/read/market-contexts/market-contexts.types.d.ts +26 -0
  94. package/dist/read/market-contexts/market-contexts.types.d.ts.map +1 -0
  95. package/dist/read/market-contexts/market-contexts.types.js +19 -0
  96. package/dist/read/market-depth/market-depth.reader.d.ts +30 -0
  97. package/dist/read/market-depth/market-depth.reader.d.ts.map +1 -0
  98. package/dist/read/market-depth/market-depth.reader.js +46 -0
  99. package/dist/read/market-depth/market-depth.types.d.ts +20 -0
  100. package/dist/read/market-depth/market-depth.types.d.ts.map +1 -0
  101. package/dist/read/market-depth/market-depth.types.js +16 -0
  102. package/dist/read/market-prices/market-prices.reader.d.ts +44 -0
  103. package/dist/read/market-prices/market-prices.reader.d.ts.map +1 -0
  104. package/dist/read/market-prices/market-prices.reader.js +51 -0
  105. package/dist/read/market-prices/market-prices.types.d.ts +48 -0
  106. package/dist/read/market-prices/market-prices.types.d.ts.map +1 -0
  107. package/dist/read/market-prices/market-prices.types.js +26 -0
  108. package/dist/read/market-trades/market-trades.reader.d.ts +33 -0
  109. package/dist/read/market-trades/market-trades.reader.d.ts.map +1 -0
  110. package/dist/read/market-trades/market-trades.reader.js +39 -0
  111. package/dist/read/market-trades/market-trades.types.d.ts +52 -0
  112. package/dist/read/market-trades/market-trades.types.d.ts.map +1 -0
  113. package/dist/read/market-trades/market-trades.types.js +23 -0
  114. package/dist/read/markets/markets.reader.d.ts +38 -0
  115. package/dist/read/markets/markets.reader.d.ts.map +1 -0
  116. package/dist/read/markets/markets.reader.js +80 -0
  117. package/dist/read/markets/markets.types.d.ts +82 -0
  118. package/dist/read/markets/markets.types.d.ts.map +1 -0
  119. package/dist/read/markets/markets.types.js +46 -0
  120. package/dist/read/pagination.types.d.ts +14 -0
  121. package/dist/read/pagination.types.d.ts.map +1 -0
  122. package/dist/read/pagination.types.js +12 -0
  123. package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts +14 -0
  124. package/dist/read/portfolio-chart/portfolio-chart.reader.d.ts.map +1 -0
  125. package/dist/read/portfolio-chart/portfolio-chart.reader.js +21 -0
  126. package/dist/read/portfolio-chart/portfolio-chart.types.d.ts +14 -0
  127. package/dist/read/portfolio-chart/portfolio-chart.types.d.ts.map +1 -0
  128. package/dist/read/portfolio-chart/portfolio-chart.types.js +12 -0
  129. package/dist/read/public-vaults/public-vaults.reader.d.ts +38 -0
  130. package/dist/read/public-vaults/public-vaults.reader.d.ts.map +1 -0
  131. package/dist/read/public-vaults/public-vaults.reader.js +31 -0
  132. package/dist/read/public-vaults/public-vaults.types.d.ts +62 -0
  133. package/dist/read/public-vaults/public-vaults.types.d.ts.map +1 -0
  134. package/dist/read/public-vaults/public-vaults.types.js +33 -0
  135. package/dist/read/types.d.ts +178 -0
  136. package/dist/read/types.d.ts.map +1 -0
  137. package/dist/read/types.js +87 -0
  138. package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts +31 -0
  139. package/dist/read/user-active-twaps/user-active-twaps.reader.d.ts.map +1 -0
  140. package/dist/read/user-active-twaps/user-active-twaps.reader.js +31 -0
  141. package/dist/read/user-active-twaps/user-active-twaps.types.d.ts +49 -0
  142. package/dist/read/user-active-twaps/user-active-twaps.types.d.ts.map +1 -0
  143. package/dist/read/user-active-twaps/user-active-twaps.types.js +25 -0
  144. package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts +31 -0
  145. package/dist/read/user-bulk-orders/user-bulk-orders.reader.d.ts.map +1 -0
  146. package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +32 -0
  147. package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts +46 -0
  148. package/dist/read/user-bulk-orders/user-bulk-orders.types.d.ts.map +1 -0
  149. package/dist/read/user-bulk-orders/user-bulk-orders.types.js +24 -0
  150. package/dist/read/user-funding-history/user-funding-history.reader.d.ts +28 -0
  151. package/dist/read/user-funding-history/user-funding-history.reader.d.ts.map +1 -0
  152. package/dist/read/user-funding-history/user-funding-history.reader.js +32 -0
  153. package/dist/read/user-funding-history/user-funding-history.types.d.ts +37 -0
  154. package/dist/read/user-funding-history/user-funding-history.types.d.ts.map +1 -0
  155. package/dist/read/user-funding-history/user-funding-history.types.js +21 -0
  156. package/dist/read/user-notifications/user-notifications.reader.d.ts +13 -0
  157. package/dist/read/user-notifications/user-notifications.reader.d.ts.map +1 -0
  158. package/dist/read/user-notifications/user-notifications.reader.js +19 -0
  159. package/dist/read/user-notifications/user-notifications.types.d.ts +49 -0
  160. package/dist/read/user-notifications/user-notifications.types.d.ts.map +1 -0
  161. package/dist/read/user-notifications/user-notifications.types.js +18 -0
  162. package/dist/read/user-open-orders/user-open-orders.reader.d.ts +40 -0
  163. package/dist/read/user-open-orders/user-open-orders.reader.d.ts.map +1 -0
  164. package/dist/read/user-open-orders/user-open-orders.reader.js +31 -0
  165. package/dist/read/user-open-orders/user-open-orders.types.d.ts +76 -0
  166. package/dist/read/user-open-orders/user-open-orders.types.d.ts.map +1 -0
  167. package/dist/read/user-open-orders/user-open-orders.types.js +34 -0
  168. package/dist/read/user-order-history/user-order-history.reader.d.ts +40 -0
  169. package/dist/read/user-order-history/user-order-history.reader.d.ts.map +1 -0
  170. package/dist/read/user-order-history/user-order-history.reader.js +28 -0
  171. package/dist/read/user-order-history/user-order-history.types.d.ts +85 -0
  172. package/dist/read/user-order-history/user-order-history.types.d.ts.map +1 -0
  173. package/dist/read/user-order-history/user-order-history.types.js +37 -0
  174. package/dist/read/user-positions/user-positions.reader.d.ts +37 -0
  175. package/dist/read/user-positions/user-positions.reader.d.ts.map +1 -0
  176. package/dist/read/user-positions/user-positions.reader.js +41 -0
  177. package/dist/read/user-positions/user-positions.types.d.ts +2590 -0
  178. package/dist/read/user-positions/user-positions.types.d.ts.map +1 -0
  179. package/dist/read/user-positions/user-positions.types.js +31 -0
  180. package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts +18 -0
  181. package/dist/read/user-subaccounts/user-subaccounts.reader.d.ts.map +1 -0
  182. package/dist/read/user-subaccounts/user-subaccounts.reader.js +28 -0
  183. package/dist/read/user-subaccounts/user-subaccounts.types.d.ts +21 -0
  184. package/dist/read/user-subaccounts/user-subaccounts.types.d.ts.map +1 -0
  185. package/dist/read/user-subaccounts/user-subaccounts.types.js +15 -0
  186. package/dist/read/user-trade-history/user-trade-history.reader.d.ts +33 -0
  187. package/dist/read/user-trade-history/user-trade-history.reader.d.ts.map +1 -0
  188. package/dist/read/user-trade-history/user-trade-history.reader.js +32 -0
  189. package/dist/read/user-trade-history/user-trade-history.types.d.ts +52 -0
  190. package/dist/read/user-trade-history/user-trade-history.types.d.ts.map +1 -0
  191. package/dist/read/user-trade-history/user-trade-history.types.js +26 -0
  192. package/dist/read/user-vaults/user-vaults.reader.d.ts +26 -0
  193. package/dist/read/user-vaults/user-vaults.reader.d.ts.map +1 -0
  194. package/dist/read/user-vaults/user-vaults.reader.js +32 -0
  195. package/dist/read/user-vaults/user-vaults.types.d.ts +39 -0
  196. package/dist/read/user-vaults/user-vaults.types.d.ts.map +1 -0
  197. package/dist/read/user-vaults/user-vaults.types.js +21 -0
  198. package/dist/read/vault/vault.reader.d.ts +95 -0
  199. package/dist/read/vault/vault.reader.d.ts.map +1 -0
  200. package/dist/read/vault/vault.reader.js +168 -0
  201. package/dist/read/vault/vault.types.d.ts +49 -0
  202. package/dist/read/vault/vault.types.d.ts.map +1 -0
  203. package/dist/read/vault/vault.types.js +45 -0
  204. package/dist/read/vaults/vaults.reader.d.ts +72 -0
  205. package/dist/read/vaults/vaults.reader.d.ts.map +1 -0
  206. package/dist/read/vaults/vaults.reader.js +63 -0
  207. package/dist/read/vaults/vaults.types.d.ts +140 -0
  208. package/dist/read/vaults/vaults.types.d.ts.map +1 -0
  209. package/dist/read/vaults/vaults.types.js +71 -0
  210. package/dist/read/ws-subscription.d.ts +21 -0
  211. package/dist/read/ws-subscription.d.ts.map +1 -0
  212. package/dist/read/ws-subscription.js +170 -0
  213. package/dist/subaccount-types.d.ts +24 -0
  214. package/dist/subaccount-types.d.ts.map +1 -0
  215. package/dist/subaccount-types.js +11 -0
  216. package/dist/transaction-builder.d.ts +14 -0
  217. package/dist/transaction-builder.d.ts.map +1 -0
  218. package/dist/transaction-builder.js +40 -0
  219. package/dist/tsconfig.tsbuildinfo +1 -0
  220. package/dist/utils.d.ts +56 -0
  221. package/dist/utils.d.ts.map +1 -0
  222. package/dist/utils.js +164 -0
  223. package/dist/vault-types.d.ts +43 -0
  224. package/dist/vault-types.d.ts.map +1 -0
  225. package/dist/vault-types.js +11 -0
  226. package/dist/write.d.ts +271 -0
  227. package/dist/write.d.ts.map +1 -0
  228. package/dist/write.js +485 -0
  229. package/eslint.config.mjs +25 -0
  230. package/package.json +39 -0
  231. package/readme.md +257 -0
  232. package/sdk_reference.md +876 -0
  233. package/src/abi/generate-abis.ts +164 -0
  234. package/src/abi/json/netna.json +1323 -0
  235. package/src/abi/json/testnet.json +1315 -0
  236. package/src/abi/types.ts +23 -0
  237. package/src/admin.ts +284 -0
  238. package/src/base.ts +218 -0
  239. package/src/constants.ts +118 -0
  240. package/src/fee-pay.ts +39 -0
  241. package/src/gas/gas-price-manager.ts +115 -0
  242. package/src/index.ts +10 -0
  243. package/src/order-event.types.ts +65 -0
  244. package/src/order-status.ts +89 -0
  245. package/src/read/account-overview/account-overview.reader.ts +43 -0
  246. package/src/read/account-overview/account-overview.types.ts +45 -0
  247. package/src/read/base-reader.ts +41 -0
  248. package/src/read/candlesticks/candlesticks.reader.ts +61 -0
  249. package/src/read/candlesticks/candlesticks.types.ts +46 -0
  250. package/src/read/delegations/delegations.reader.ts +22 -0
  251. package/src/read/delegations/delegations.types.ts +19 -0
  252. package/src/read/index.ts +271 -0
  253. package/src/read/leaderboard/leaderboard.reader.ts +21 -0
  254. package/src/read/leaderboard/leaderboard.types.ts +26 -0
  255. package/src/read/market-contexts/market-contexts.reader.ts +26 -0
  256. package/src/read/market-contexts/market-contexts.types.ts +18 -0
  257. package/src/read/market-depth/market-depth.reader.ts +60 -0
  258. package/src/read/market-depth/market-depth.types.ts +24 -0
  259. package/src/read/market-prices/market-prices.reader.ts +61 -0
  260. package/src/read/market-prices/market-prices.types.ts +38 -0
  261. package/src/read/market-trades/market-trades.reader.ts +46 -0
  262. package/src/read/market-trades/market-trades.types.ts +34 -0
  263. package/src/read/markets/markets.reader.ts +82 -0
  264. package/src/read/markets/markets.types.ts +54 -0
  265. package/src/read/pagination.types.ts +18 -0
  266. package/src/read/portfolio-chart/portfolio-chart.reader.ts +20 -0
  267. package/src/read/portfolio-chart/portfolio-chart.types.ts +21 -0
  268. package/src/read/types.ts +129 -0
  269. package/src/read/user-active-twaps/user-active-twaps.reader.ts +36 -0
  270. package/src/read/user-active-twaps/user-active-twaps.types.ts +33 -0
  271. package/src/read/user-bulk-orders/user-bulk-orders.reader.ts +37 -0
  272. package/src/read/user-bulk-orders/user-bulk-orders.types.ts +32 -0
  273. package/src/read/user-funding-history/user-funding-history.reader.ts +38 -0
  274. package/src/read/user-funding-history/user-funding-history.types.ts +29 -0
  275. package/src/read/user-notifications/user-notifications.reader.ts +17 -0
  276. package/src/read/user-notifications/user-notifications.types.ts +61 -0
  277. package/src/read/user-open-orders/user-open-orders.reader.ts +36 -0
  278. package/src/read/user-open-orders/user-open-orders.types.ts +42 -0
  279. package/src/read/user-order-history/user-order-history.reader.ts +34 -0
  280. package/src/read/user-order-history/user-order-history.types.ts +44 -0
  281. package/src/read/user-positions/user-positions.reader.ts +55 -0
  282. package/src/read/user-positions/user-positions.types.ts +43 -0
  283. package/src/read/user-subaccounts/user-subaccounts.reader.ts +30 -0
  284. package/src/read/user-subaccounts/user-subaccounts.types.ts +21 -0
  285. package/src/read/user-trade-history/user-trade-history.reader.ts +38 -0
  286. package/src/read/user-trade-history/user-trade-history.types.ts +33 -0
  287. package/src/read/vaults/vaults.reader.ts +79 -0
  288. package/src/read/vaults/vaults.types.ts +106 -0
  289. package/src/read/ws-subscription.ts +200 -0
  290. package/src/subaccount-types.ts +31 -0
  291. package/src/transaction-builder.ts +75 -0
  292. package/src/utils.ts +255 -0
  293. package/src/write.ts +965 -0
  294. package/tsconfig.json +8 -0
@@ -0,0 +1,876 @@
1
+ # Decibel TypeScript SDK Reference
2
+
3
+ ## Overview
4
+
5
+ The Decibel TypeScript SDK provides an interface for interacting with Decibel Smart Conracts on Aptos. The SDK is split into two main components:
6
+
7
+ - **Read operations** (`DecibelReadDex`) - For querying market data, positions, orders, and account information
8
+ - **Write operations** (`DecibelWriteDex`) - For executing trades, managing orders, and account operations
9
+
10
+ ## Installation
11
+
12
+ ```typescript
13
+ import { DecibelReadDex, DecibelWriteDex, NETNA_CONFIG } from "@decibeltrade/sdk";
14
+ ```
15
+
16
+ ## Quick Start
17
+
18
+ ### Read Operations
19
+
20
+ ```typescript
21
+ import { DecibelReadDex, NETNA_CONFIG } from "@decibeltrade/sdk";
22
+
23
+ // Initialize the read client
24
+ const readDex = new DecibelReadDex(NETNA_CONFIG, {
25
+ nodeApiKey: "your-api-key", // optional
26
+ onWsError: (error) => console.error("WebSocket error:", error), // optional
27
+ });
28
+
29
+ // Get all available markets
30
+ const markets = await readDex.markets.getAll();
31
+
32
+ // Get account overview
33
+ const accountOverview = await readDex.accountOverview.getByAddr("0x123...");
34
+ ```
35
+
36
+ ### Write Operations
37
+
38
+ ```typescript
39
+ import { DecibelWriteDex, NETNA_CONFIG, Account } from "@decibeltrade/sdk";
40
+
41
+ // Initialize with your account
42
+ const account = Account.fromPrivateKey({ privateKey: "your-private-key" });
43
+ const writeDex = new DecibelWriteDex(NETNA_CONFIG, account);
44
+
45
+ // Place an order
46
+ const result = await writeDex.placeOrder({
47
+ marketName: "BTC-USD",
48
+ price: 45000,
49
+ size: 1.5,
50
+ isBuy: true,
51
+ timeInForce: TimeInForce.GoodTillCanceled,
52
+ isReduceOnly: false,
53
+ });
54
+ ```
55
+
56
+ ## Configuration
57
+
58
+ ### Predefined Configurations
59
+
60
+ The SDK provides several predefined network configurations:
61
+
62
+ ```typescript
63
+ import { NETNA_CONFIG, LOCAL_CONFIG, DOCKER_CONFIG } from "@decibeltrade/sdk";
64
+
65
+ // Netna (Staging)
66
+ const readDex = new DecibelReadDex(NETNA_CONFIG);
67
+
68
+ // Local development
69
+ const localReadDex = new DecibelReadDex(LOCAL_CONFIG);
70
+
71
+ // Docker environment
72
+ const dockerReadDex = new DecibelReadDex(DOCKER_CONFIG);
73
+ ```
74
+
75
+ ### Example Configuration File
76
+
77
+ Here's an example of how to set up your configuration constants:
78
+
79
+ ```typescript path=null start=null
80
+ // constants.ts
81
+ import { AccountAddress, createObjectAddress, Network } from "@aptos-labs/ts-sdk";
82
+
83
+ export interface DecibelConfig {
84
+ network: Network;
85
+ fullnodeUrl: string;
86
+ tradingHttpUrl: string;
87
+ tradingWsUrl: string;
88
+ gasStationUrl: string;
89
+ deployment: Deployment;
90
+ }
91
+
92
+ export interface Deployment {
93
+ package: string;
94
+ usdc: string;
95
+ testc: string;
96
+ perpEngineGlobal: string;
97
+ }
98
+
99
+ // Utility functions to generate addresses
100
+ export function getUsdcAddress(publisherAddr: string) {
101
+ return createObjectAddress(
102
+ AccountAddress.fromString(publisherAddr),
103
+ new TextEncoder().encode("USDC"),
104
+ );
105
+ }
106
+
107
+ export function getTestcAddress(publisherAddr: string) {
108
+ return createObjectAddress(
109
+ AccountAddress.fromString(publisherAddr),
110
+ new TextEncoder().encode("TESTC"),
111
+ );
112
+ }
113
+
114
+ export function getPerpEngineGlobalAddress(publisherAddr: string) {
115
+ return createObjectAddress(
116
+ AccountAddress.fromString(publisherAddr),
117
+ new TextEncoder().encode("GlobalPerpEngine"),
118
+ );
119
+ }
120
+
121
+ // Network configurations
122
+ const NETNA_PACKAGE = "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95";
123
+
124
+ export const NETNA_DEPLOYMENT: Deployment = {
125
+ package: NETNA_PACKAGE,
126
+ usdc: getUsdcAddress(NETNA_PACKAGE).toString(),
127
+ testc: getTestcAddress(NETNA_PACKAGE).toString(),
128
+ perpEngineGlobal: getPerpEngineGlobalAddress(NETNA_PACKAGE).toString(),
129
+ };
130
+
131
+ export const NETNA_CONFIG: DecibelConfig = {
132
+ network: Network.CUSTOM,
133
+ fullnodeUrl: "https://api.netna.staging.aptoslabs.com/v1",
134
+ tradingHttpUrl: "https://api.netna.aptoslabs.com/decibel",
135
+ tradingWsUrl: "wss://api.netna.aptoslabs.com/decibel/ws",
136
+ gasStationUrl: "https://fee-payer-dev-netna-us-central1-410192433417.us-central1.run.app",
137
+ deployment: NETNA_DEPLOYMENT,
138
+ };
139
+
140
+ export const LOCAL_CONFIG: DecibelConfig = {
141
+ network: Network.CUSTOM,
142
+ fullnodeUrl: "http://localhost:8080/v1",
143
+ tradingHttpUrl: "http://localhost:8084",
144
+ tradingWsUrl: "ws://localhost:8083",
145
+ gasStationUrl: "http://localhost:8085",
146
+ deployment: NETNA_DEPLOYMENT,
147
+ };
148
+
149
+ export const DOCKER_CONFIG: DecibelConfig = {
150
+ network: Network.CUSTOM,
151
+ fullnodeUrl: "http://tradenet:8080/v1",
152
+ tradingHttpUrl: "http://trading-api-http:8080",
153
+ // nosemgrep: javascript.lang.security.detect-insecure-websocket.detect-insecure-websocket
154
+ tradingWsUrl: "ws://trading-api-ws:8080",
155
+ gasStationUrl: "http://fee-payer:8080",
156
+ deployment: NETNA_DEPLOYMENT,
157
+ };
158
+
159
+ export const NAMED_CONFIGS: Record<string, DecibelConfig | undefined> = {
160
+ netna: NETNA_CONFIG,
161
+ local: LOCAL_CONFIG,
162
+ docker: DOCKER_CONFIG,
163
+ };
164
+ ```
165
+
166
+ ### Custom Configuration
167
+
168
+ You can also create custom configurations for other environments:
169
+
170
+ ```typescript
171
+ import { DecibelConfig, Network } from "@decibeltrade/sdk";
172
+
173
+ const customConfig: DecibelConfig = {
174
+ network: Network.CUSTOM,
175
+ fullnodeUrl: "https://your-fullnode-url.com/v1",
176
+ tradingHttpUrl: "https://your-trading-api.com",
177
+ tradingWsUrl: "wss://your-trading-ws.com",
178
+ gasStationUrl: "https://your-fee-payer.com",
179
+ deployment: {
180
+ package: "0x...",
181
+ usdc: "0x...",
182
+ testc: "0x...",
183
+ perpEngineGlobal: "0x...",
184
+ },
185
+ };
186
+ ```
187
+
188
+ ## Read Operations API
189
+
190
+ ### DecibelReadDex
191
+
192
+ The main read client providing access to all market data and account information.
193
+
194
+ #### Constructor
195
+
196
+ ```typescript
197
+ new DecibelReadDex(config: DecibelConfig, opts?: {
198
+ nodeApiKey?: string;
199
+ onWsError?: (error: ErrorEvent) => void;
200
+ })
201
+ ```
202
+
203
+ #### Global Methods
204
+
205
+ ```typescript
206
+ // Get global perpetual engine state
207
+ await readDex.globalPerpEngineState();
208
+
209
+ // Get collateral balance decimals
210
+ await readDex.collateralBalanceDecimals();
211
+
212
+ // Get USDC decimals (cached)
213
+ await readDex.usdcDecimals();
214
+
215
+ // Get USDC balance for an address
216
+ await readDex.usdcBalance("0x123...");
217
+
218
+ // Get account balance
219
+ await readDex.accountBalance("0x123...");
220
+
221
+ // Get position size
222
+ await readDex.positionSize("0x123...", "metadata_address");
223
+
224
+ // Get crossed position
225
+ await readDex.getCrossedPosition("0x123...");
226
+ ```
227
+
228
+ ### Markets
229
+
230
+ Access market information and configuration.
231
+
232
+ ```typescript
233
+ // Get all available markets
234
+ const markets = await readDex.markets.getAll();
235
+
236
+ // Get specific market by name
237
+ const market = await readDex.markets.getByName("BTC-USD");
238
+
239
+ // List all market addresses
240
+ const addresses = await readDex.markets.listMarketAddresses();
241
+
242
+ // Get market name by address
243
+ const name = await readDex.markets.marketNameByAddress("0x123...");
244
+ ```
245
+
246
+ ### Account Overview
247
+
248
+ Get comprehensive account information including balances and positions.
249
+
250
+ ```typescript
251
+ // Get account overview
252
+ const overview = await readDex.accountOverview.getByAddr("subaccount_address", "30d"); // volume_window = "30d"
253
+
254
+ // Subscribe to real-time account updates
255
+ const unsubscribe = readDex.accountOverview.subscribeByAddr("subaccount_address", (data) =>
256
+ console.log("Account update:", data),
257
+ );
258
+
259
+ // Later, unsubscribe
260
+ unsubscribe();
261
+ ```
262
+
263
+ ### User Positions
264
+
265
+ Query user positions across markets.
266
+
267
+ ```typescript
268
+ // Get all positions for a user
269
+ const positions = await readDex.userPositions.getByAddr({
270
+ subAddr: "subaccount_address",
271
+ includeDeleted: false,
272
+ limit: 10,
273
+ });
274
+
275
+ // Get positions for specific market
276
+ const marketPositions = await readDex.userPositions.getByAddr({
277
+ subAddr: "subaccount_address",
278
+ marketAddr: "market_address",
279
+ limit: 10,
280
+ });
281
+
282
+ // Subscribe to position updates
283
+ const unsubscribe = readDex.userPositions.subscribeByAddr("subaccount_address", (data) =>
284
+ console.log("Position update:", data),
285
+ );
286
+ ```
287
+
288
+ ### User Orders
289
+
290
+ Query open orders and order history.
291
+
292
+ #### Open Orders
293
+
294
+ ```typescript
295
+ // Get open orders
296
+ const openOrders = await readDex.userOpenOrders.getByAddr("subaccount_address");
297
+
298
+ // Subscribe to open orders updates
299
+ const unsubscribe = readDex.userOpenOrders.subscribeByAddr("subaccount_address", (data) =>
300
+ console.log("Orders update:", data),
301
+ );
302
+ ```
303
+
304
+ #### Order History
305
+
306
+ ```typescript
307
+ // Get order history
308
+ const orderHistory = await readDex.userOrderHistory.getByAddr({
309
+ subAddr: "subaccount_address",
310
+ marketAddr: "market_address", // optional
311
+ limit: 50,
312
+ });
313
+
314
+ // Subscribe to order history updates
315
+ const unsubscribe = readDex.userOrderHistory.subscribeByAddr("subaccount_address", (data) =>
316
+ console.log("Order history update:", data),
317
+ );
318
+ ```
319
+
320
+ ### Market Data
321
+
322
+ #### Market Depth (Order Book)
323
+
324
+ ```typescript
325
+ // Get market depth
326
+ const depth = await readDex.marketDepth.getByName("BTC-USD", 100); // limit = 100
327
+
328
+ // Subscribe to depth updates
329
+ const unsubscribe = readDex.marketDepth.subscribeByName("BTC-USD", (data) =>
330
+ console.log("Depth update:", data),
331
+ );
332
+
333
+ // Reset subscription (clear cached data)
334
+ readDex.marketDepth.resetSubscriptionByName("BTC-USD");
335
+ ```
336
+
337
+ #### Market Prices
338
+
339
+ ```typescript
340
+ // Get current prices
341
+ const prices = await readDex.marketPrices.getByName("BTC-USD");
342
+
343
+ // Subscribe to price updates
344
+ const unsubscribe = readDex.marketPrices.subscribeByName("BTC-USD", (data) =>
345
+ console.log("Price update:", data),
346
+ );
347
+ ```
348
+
349
+ #### Market Trades
350
+
351
+ ```typescript
352
+ // Get recent trades
353
+ const trades = await readDex.marketTrades.getByName("BTC-USD", 50); // limit = 50
354
+
355
+ // Subscribe to trade updates
356
+ const unsubscribe = readDex.marketTrades.subscribeByName("BTC-USD", (data) =>
357
+ console.log("Trade update:", data),
358
+ );
359
+ ```
360
+
361
+ #### Candlesticks
362
+
363
+ ```typescript
364
+ import { CandlestickInterval } from "@decibeltrade/sdk";
365
+
366
+ // Get historical candlestick data
367
+ const candlesticks = await readDex.candlesticks.getByName(
368
+ "BTC-USD",
369
+ CandlestickInterval.MINUTE_1,
370
+ startTimestamp,
371
+ endTimestamp,
372
+ );
373
+
374
+ // Subscribe to candlestick updates
375
+ const unsubscribe = readDex.candlesticks.subscribeByName(
376
+ "BTC-USD",
377
+ CandlestickInterval.MINUTE_1,
378
+ (data) => console.log("Candlestick update:", data),
379
+ );
380
+ ```
381
+
382
+ ### Market Contexts
383
+
384
+ Get additional market metadata and context.
385
+
386
+ ```typescript
387
+ // Get market contexts
388
+ const contexts = await readDex.marketContexts.getAll();
389
+
390
+ // Subscribe to market context updates
391
+ const unsubscribe = readDex.marketContexts.subscribeAll((data) =>
392
+ console.log("Market contexts update:", data),
393
+ );
394
+ ```
395
+
396
+ ### User Trade History
397
+
398
+ Query historical trade data for a user.
399
+
400
+ ```typescript
401
+ // Get trade history
402
+ const trades = await readDex.userTradeHistory.getByAddr({
403
+ subAddr: "subaccount_address",
404
+ marketAddr: "market_address", // optional
405
+ limit: 100,
406
+ });
407
+
408
+ // Subscribe to trade history updates
409
+ const unsubscribe = readDex.userTradeHistory.subscribeByAddr("subaccount_address", (data) =>
410
+ console.log("Trade history update:", data),
411
+ );
412
+ ```
413
+
414
+ ### User Funding History
415
+
416
+ Query funding payment history.
417
+
418
+ ```typescript
419
+ // Get funding history
420
+ const funding = await readDex.userFundingHistory.getByAddr({
421
+ subAddr: "subaccount_address",
422
+ marketAddr: "market_address", // optional
423
+ limit: 50,
424
+ });
425
+
426
+ // Subscribe to funding history updates
427
+ const unsubscribe = readDex.userFundingHistory.subscribeByAddr("subaccount_address", (data) =>
428
+ console.log("Funding history update:", data),
429
+ );
430
+ ```
431
+
432
+ ## Write Operations API
433
+
434
+ ### DecibelWriteDex
435
+
436
+ The main write client for executing trades and managing account operations.
437
+
438
+ #### Constructor
439
+
440
+ ```typescript
441
+ import { Account } from "@aptos-labs/ts-sdk";
442
+
443
+ const account = Account.fromPrivateKey({ privateKey: "your-private-key" });
444
+ const writeDex = new DecibelWriteDex(config, account, opts?: {
445
+ nodeApiKey?: string;
446
+ sponsorAccount?: Account;
447
+ maxGasAmount?: number;
448
+ gasUnitPrice?: number;
449
+ });
450
+ ```
451
+
452
+ ### Account Management
453
+
454
+ #### Subaccount Operations
455
+
456
+ ```typescript
457
+ // Create a new subaccount
458
+ await writeDex.createSubaccount();
459
+
460
+ // Deposit collateral to primary subaccount
461
+ await writeDex.deposit(1000000); // amount in smallest unit
462
+
463
+ // Deposit to specific subaccount
464
+ await writeDex.deposit(1000000, "subaccount_address");
465
+
466
+ // Withdraw from subaccount
467
+ await writeDex.withdraw(500000, "subaccount_address");
468
+ ```
469
+
470
+ #### Trading Delegation
471
+
472
+ ```typescript
473
+ // Delegate trading permissions
474
+ await writeDex.delegateTradingTo({
475
+ subaccountAddr: "your_subaccount",
476
+ accountToDelegateTo: "delegate_account_address",
477
+ });
478
+
479
+ // Revoke delegation
480
+ await writeDex.revokeDelegation({
481
+ subaccountAddr: "your_subaccount",
482
+ accountToRevoke: "delegate_account_address",
483
+ });
484
+ ```
485
+
486
+ #### Market Configuration
487
+
488
+ ```typescript
489
+ // Configure user settings for a market
490
+ await writeDx.configureUserSettingsForMarket({
491
+ marketAddr: "market_address",
492
+ subaccountAddr: "subaccount_address",
493
+ isCross: true, // cross-margin mode
494
+ userLeverage: 1000, // 10x leverage (basis points)
495
+ });
496
+ ```
497
+
498
+ ### Order Management
499
+
500
+ #### Place Orders
501
+
502
+ ```typescript
503
+ import { TimeInForce } from "@decibeltrade/sdk";
504
+
505
+ // Place a limit order
506
+ const result = await writeDex.placeOrder({
507
+ marketName: "BTC-USD",
508
+ price: 45000,
509
+ size: 1.5,
510
+ isBuy: true,
511
+ timeInForce: TimeInForce.GoodTillCanceled,
512
+ isReduceOnly: false,
513
+ clientOrderId: "12345", // optional
514
+ subaccountAddr: "subaccount_address", // optional
515
+ });
516
+
517
+ // Place a post-only order
518
+ await writeDex.placeOrder({
519
+ marketName: "ETH-USD",
520
+ price: 3000,
521
+ size: 2.0,
522
+ isBuy: false,
523
+ timeInForce: TimeInForce.PostOnly,
524
+ isReduceOnly: false,
525
+ });
526
+
527
+ // Place an IOC (Immediate or Cancel) order
528
+ await writeDex.placeOrder({
529
+ marketName: "SOL-USD",
530
+ price: 100,
531
+ size: 10,
532
+ isBuy: true,
533
+ timeInForce: TimeInForce.ImmediateOrCancel,
534
+ isReduceOnly: true,
535
+ });
536
+ ```
537
+
538
+ #### Advanced Order Types
539
+
540
+ ```typescript
541
+ // Place order with stop-loss and take-profit
542
+ await writeDex.placeOrder({
543
+ marketName: "BTC-USD",
544
+ price: 45000,
545
+ size: 1.0,
546
+ isBuy: true,
547
+ timeInForce: TimeInForce.GoodTillCanceled,
548
+ isReduceOnly: false,
549
+ stopPrice: 44000, // stop-loss trigger
550
+ tpTriggerPrice: 46000, // take-profit trigger
551
+ tpLimitPrice: 45900, // take-profit limit price
552
+ slTriggerPrice: 44000, // stop-loss trigger
553
+ slLimitPrice: 44100, // stop-loss limit price
554
+ });
555
+
556
+ // Place order with builder fee
557
+ await writeDex.placeOrder({
558
+ marketName: "BTC-USD",
559
+ price: 45000,
560
+ size: 1.0,
561
+ isBuy: true,
562
+ timeInForce: TimeInForce.GoodTillCanceled,
563
+ isReduceOnly: false,
564
+ builderAddr: "builder_account_address",
565
+ builderFee: 100, // fee in basis points
566
+ });
567
+ ```
568
+
569
+ #### TWAP Orders
570
+
571
+ ```typescript
572
+ // Place a Time-Weighted Average Price order
573
+ await writeDex.placeTwapOrder({
574
+ marketName: "BTC-USD",
575
+ size: 10.0,
576
+ isBuy: true,
577
+ isReduceOnly: false,
578
+ twapFrequencySeconds: 60, // execute every 60 seconds
579
+ twapDurationSeconds: 3600, // over 1 hour period
580
+ subaccountAddr: "subaccount_address", // optional
581
+ });
582
+ ```
583
+
584
+ #### Cancel Orders
585
+
586
+ ```typescript
587
+ // Cancel order by ID and market name
588
+ await writeDex.cancelOrder({
589
+ orderId: 12345,
590
+ marketName: "BTC-USD",
591
+ subaccountAddr: "subaccount_address", // optional
592
+ });
593
+
594
+ // Cancel order by ID and market address
595
+ await writeDx.cancelOrder({
596
+ orderId: 12345,
597
+ marketAddr: "market_address",
598
+ subaccountAddr: "subaccount_address", // optional
599
+ });
600
+
601
+ // Cancel order by client order ID
602
+ await writeDex.cancelClientOrder({
603
+ clientOrderId: "54321",
604
+ marketName: "BTC-USD",
605
+ subaccountAddr: "subaccount_address", // optional
606
+ });
607
+ ```
608
+
609
+ ### Position Management
610
+
611
+ #### Take-Profit / Stop-Loss Orders
612
+
613
+ ```typescript
614
+ // Place TP/SL order for existing position
615
+ await writeDx.placeTpSlOrderForPosition({
616
+ marketAddr: "market_address",
617
+ tpTriggerPrice: 46000,
618
+ tpLimitPrice: 45900,
619
+ tpSize: 0.5, // partial position size
620
+ slTriggerPrice: 44000,
621
+ slLimitPrice: 44100,
622
+ slSize: 1.0, // full position size
623
+ subaccountAddr: "subaccount_address", // optional
624
+ });
625
+
626
+ // Update existing TP/SL order
627
+ await writeDex.updateTpSlOrderForPosition({
628
+ marketAddr: "market_address",
629
+ prevOrderId: "previous_order_id",
630
+ tpTriggerPrice: 47000, // new TP trigger
631
+ tpLimitPrice: 46900,
632
+ tpSize: 0.75,
633
+ // ... other parameters
634
+ });
635
+
636
+ // Cancel TP/SL order
637
+ await writeDex.cancelTpSlOrderForPosition({
638
+ marketName: "BTC-USD",
639
+ orderId: 12345,
640
+ subaccountAddr: "subaccount_address", // optional
641
+ });
642
+ ```
643
+
644
+ ### Order Status Tracking
645
+
646
+ The write client includes an order status client for tracking order execution:
647
+
648
+ ```typescript
649
+ // Access order status client
650
+ const orderStatus = writeDex.orderStatusClient;
651
+
652
+ // Use order status methods (implementation depends on OrderStatusClient)
653
+ ```
654
+
655
+ ### Session Accounts
656
+
657
+ You can override the default account for specific transactions using session accounts:
658
+
659
+ ```typescript
660
+ import { Account } from "@aptos-labs/ts-sdk";
661
+
662
+ const sessionAccount = Account.generate();
663
+
664
+ // Use session account for this transaction
665
+ await writeDex.placeOrder({
666
+ marketName: "BTC-USD",
667
+ price: 45000,
668
+ size: 1.0,
669
+ isBuy: true,
670
+ timeInForce: TimeInForce.GoodTillCanceled,
671
+ isReduceOnly: false,
672
+ accountOverride: sessionAccount,
673
+ });
674
+ ```
675
+
676
+ ### Error Handling
677
+
678
+ All write operations return transaction results. For order placement, you get a structured result:
679
+
680
+ ```typescript
681
+ interface PlaceOrderResult {
682
+ success: boolean;
683
+ orderId?: string;
684
+ transactionHash: string;
685
+ error?: string;
686
+ }
687
+
688
+ const result = await writeDex.placeOrder({
689
+ // ... order parameters
690
+ });
691
+
692
+ if (result.success) {
693
+ console.log("Order placed successfully:", result.orderId);
694
+ console.log("Transaction:", result.transactionHash);
695
+ } else {
696
+ console.error("Order failed:", result.error);
697
+ }
698
+ ```
699
+
700
+ ## Constants and Enums
701
+
702
+ ### Time in Force
703
+
704
+ ```typescript
705
+ export const TimeInForce = {
706
+ GoodTillCanceled: 0,
707
+ PostOnly: 1,
708
+ ImmediateOrCancel: 2,
709
+ } as const;
710
+ ```
711
+
712
+ ### Candlestick Intervals
713
+
714
+ ```typescript
715
+ export enum CandlestickInterval {
716
+ MINUTE_1 = "1m",
717
+ MINUTE_5 = "5m",
718
+ MINUTE_15 = "15m",
719
+ HOUR_1 = "1h",
720
+ HOUR_4 = "4h",
721
+ DAY_1 = "1d",
722
+ }
723
+ ```
724
+
725
+ ## Utilities
726
+
727
+ ### Address Utilities
728
+
729
+ ```typescript
730
+ import { getPrimarySubaccountAddr, getMarketAddr } from "@decibeltrade/sdk";
731
+
732
+ // Get primary subaccount address for an account
733
+ const subaccountAddr = getPrimarySubaccountAddr("account_address");
734
+
735
+ // Get market address from name
736
+ const marketAddr = getMarketAddr("BTC-USD", "perp_engine_global_address");
737
+ ```
738
+
739
+ ## WebSocket Subscriptions
740
+
741
+ All read operations that support real-time updates return an unsubscribe function:
742
+
743
+ ```typescript
744
+ // Subscribe to multiple streams
745
+ const unsubscribeDepth = readDex.marketDepth.subscribeByName("BTC-USD", handleDepth);
746
+ const unsubscribePrices = readDex.marketPrices.subscribeByName("BTC-USD", handlePrices);
747
+ const unsubscribeOrders = readDex.userOpenOrders.subscribeByAddr("subaccount", handleOrders);
748
+
749
+ // Clean up subscriptions
750
+ function cleanup() {
751
+ unsubscribeDepth();
752
+ unsubscribePrices();
753
+ unsubscribeOrders();
754
+ }
755
+
756
+ // Handle errors
757
+ const readDex = new DecibelReadDex(NETNA_CONFIG, {
758
+ onWsError: (error) => {
759
+ console.error("WebSocket error:", error);
760
+ // Implement reconnection logic
761
+ },
762
+ });
763
+ ```
764
+
765
+ ## TypeScript Types
766
+
767
+ The SDK is fully typed with Zod schemas for runtime validation. Import types for better development experience:
768
+
769
+ ```typescript
770
+ import type {
771
+ DecibelConfig,
772
+ PerpMarket,
773
+ UserPosition,
774
+ MarketDepth,
775
+ CandlestickData,
776
+ AccountOverview,
777
+ PlaceOrderResult,
778
+ } from "@decibeltrade/sdk";
779
+ ```
780
+
781
+ ## Best Practices
782
+
783
+ 1. **Connection Management**: Reuse SDK instances where possible to maintain WebSocket connections.
784
+
785
+ 2. **Error Handling**: Always wrap SDK calls in try-catch blocks and handle errors appropriately.
786
+
787
+ 3. **Subscription Cleanup**: Always call unsubscribe functions to prevent memory leaks.
788
+
789
+ 4. **Rate Limiting**: Be mindful of API rate limits when making frequent requests.
790
+
791
+ 5. **Account Security**: Never expose private keys in client-side code. Use environment variables or secure key management.
792
+
793
+ 6. **Precision**: Be careful with number precision for prices and sizes. The SDK handles decimal precision internally.
794
+
795
+ ## Examples
796
+
797
+ ### Complete Trading Bot Example
798
+
799
+ ```typescript
800
+ import {
801
+ DecibelReadDex,
802
+ DecibelWriteDex,
803
+ NETNA_CONFIG,
804
+ TimeInForce,
805
+ Account,
806
+ } from "@decibeltrade/sdk";
807
+
808
+ class TradingBot {
809
+ private readDex: DecibelReadDex;
810
+ private writeDex: DecibelWriteDex;
811
+ private subaccountAddr: string;
812
+
813
+ constructor(privateKey: string, subaccountAddr: string) {
814
+ this.readDex = new DecibelReadDex(NETNA_CONFIG);
815
+
816
+ const account = Account.fromPrivateKey({ privateKey });
817
+ this.writeDex = new DecibelWriteDex(NETNA_CONFIG, account);
818
+ this.subaccountAddr = subaccountAddr;
819
+ }
820
+
821
+ async start() {
822
+ // Subscribe to market data
823
+ this.readDx.marketPrices.subscribeByName("BTC-USD", this.handlePriceUpdate.bind(this));
824
+ this.readDex.marketDepth.subscribeByName("BTC-USD", 1, this.handleDepthUpdate.bind(this));
825
+
826
+ // Subscribe to account updates
827
+ this.readDex.userPositions.subscribeByAddr(
828
+ this.subaccountAddr,
829
+ this.handlePositionUpdate.bind(this),
830
+ );
831
+ }
832
+
833
+ private async handlePriceUpdate(priceData: any) {
834
+ // Implement your trading logic here
835
+ console.log("Price update:", priceData);
836
+ }
837
+
838
+ private async handleDepthUpdate(depthData: any) {
839
+ // Analyze order book for trading opportunities
840
+ console.log("Depth update:", depthData);
841
+ }
842
+
843
+ private async handlePositionUpdate(positionData: any) {
844
+ // Monitor positions and manage risk
845
+ console.log("Position update:", positionData);
846
+ }
847
+
848
+ async placeMarketBuyOrder(size: number) {
849
+ try {
850
+ const result = await this.writeDex.placeOrder({
851
+ marketName: "BTC-USD",
852
+ price: 0, // Market order (implementation may vary)
853
+ size,
854
+ isBuy: true,
855
+ timeInForce: TimeInForce.ImmediateOrCancel,
856
+ isReduceOnly: false,
857
+ subaccountAddr: this.subaccountAddr,
858
+ });
859
+
860
+ if (result.success) {
861
+ console.log(`Market buy order placed: ${result.orderId}`);
862
+ } else {
863
+ console.error(`Order failed: ${result.error}`);
864
+ }
865
+ } catch (error) {
866
+ console.error("Error placing order:", error);
867
+ }
868
+ }
869
+ }
870
+
871
+ // Usage
872
+ const bot = new TradingBot("your-private-key", "your-subaccount-address");
873
+ bot.start();
874
+ ```
875
+
876
+ This SDK provides comprehensive access to the Decibel derivatives exchange, enabling both simple trading operations and complex algorithmic trading strategies.