gateio-api 0.0.1 → 1.0.2

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 (320) hide show
  1. package/README.md +251 -106
  2. package/dist/cjs/RestClient.d.ts +2534 -0
  3. package/dist/cjs/RestClient.js +2700 -0
  4. package/dist/cjs/RestClient.js.map +1 -0
  5. package/dist/cjs/WebsocketClient.d.ts +107 -0
  6. package/dist/cjs/WebsocketClient.js +504 -0
  7. package/dist/cjs/WebsocketClient.js.map +1 -0
  8. package/dist/cjs/index.d.ts +43 -0
  9. package/dist/cjs/index.js +64 -0
  10. package/dist/cjs/index.js.map +1 -0
  11. package/dist/cjs/lib/BaseRestClient.d.ts +63 -0
  12. package/dist/cjs/lib/BaseRestClient.js +324 -0
  13. package/dist/cjs/lib/BaseRestClient.js.map +1 -0
  14. package/dist/cjs/lib/BaseWSClient.d.ts +172 -0
  15. package/dist/cjs/lib/BaseWSClient.js +619 -0
  16. package/dist/cjs/lib/BaseWSClient.js.map +1 -0
  17. package/dist/cjs/lib/logger.d.ts +6 -0
  18. package/dist/cjs/lib/logger.js +16 -0
  19. package/dist/cjs/lib/logger.js.map +1 -0
  20. package/dist/cjs/lib/misc-util.d.ts +1 -0
  21. package/dist/cjs/lib/misc-util.js +8 -0
  22. package/dist/cjs/lib/misc-util.js.map +1 -0
  23. package/dist/cjs/lib/requestUtils.d.ts +38 -0
  24. package/dist/cjs/lib/requestUtils.js +47 -0
  25. package/dist/cjs/lib/requestUtils.js.map +1 -0
  26. package/dist/cjs/lib/webCryptoAPI.d.ts +10 -0
  27. package/dist/cjs/lib/webCryptoAPI.js +57 -0
  28. package/dist/cjs/lib/webCryptoAPI.js.map +1 -0
  29. package/dist/cjs/lib/websocket/WsStore.d.ts +57 -0
  30. package/dist/cjs/lib/websocket/WsStore.js +249 -0
  31. package/dist/cjs/lib/websocket/WsStore.js.map +1 -0
  32. package/dist/cjs/lib/websocket/WsStore.types.d.ts +44 -0
  33. package/dist/cjs/lib/websocket/WsStore.types.js +13 -0
  34. package/dist/cjs/lib/websocket/WsStore.types.js.map +1 -0
  35. package/dist/cjs/lib/websocket/websocket-util.d.ts +78 -0
  36. package/dist/cjs/lib/websocket/websocket-util.js +153 -0
  37. package/dist/cjs/lib/websocket/websocket-util.js.map +1 -0
  38. package/dist/cjs/package.json +3 -0
  39. package/dist/cjs/types/request/account.d.ts +10 -0
  40. package/dist/cjs/types/request/account.js +7 -0
  41. package/dist/cjs/types/request/account.js.map +1 -0
  42. package/dist/cjs/types/request/collateralLoan.d.ts +39 -0
  43. package/dist/cjs/types/request/collateralLoan.js +7 -0
  44. package/dist/cjs/types/request/collateralLoan.js.map +1 -0
  45. package/dist/cjs/types/request/delivery.d.ts +89 -0
  46. package/dist/cjs/types/request/delivery.js +7 -0
  47. package/dist/cjs/types/request/delivery.js.map +1 -0
  48. package/dist/cjs/types/request/earn.d.ts +16 -0
  49. package/dist/cjs/types/request/earn.js +7 -0
  50. package/dist/cjs/types/request/earn.js.map +1 -0
  51. package/dist/cjs/types/request/earnuni.d.ts +30 -0
  52. package/dist/cjs/types/request/earnuni.js +7 -0
  53. package/dist/cjs/types/request/earnuni.js.map +1 -0
  54. package/dist/cjs/types/request/flashswap.d.ts +28 -0
  55. package/dist/cjs/types/request/flashswap.js +7 -0
  56. package/dist/cjs/types/request/flashswap.js.map +1 -0
  57. package/dist/cjs/types/request/futures.d.ts +168 -0
  58. package/dist/cjs/types/request/futures.js +7 -0
  59. package/dist/cjs/types/request/futures.js.map +1 -0
  60. package/dist/cjs/types/request/margin.d.ts +47 -0
  61. package/dist/cjs/types/request/margin.js +7 -0
  62. package/dist/cjs/types/request/margin.js.map +1 -0
  63. package/dist/cjs/types/request/marginuni.d.ts +29 -0
  64. package/dist/cjs/types/request/marginuni.js +7 -0
  65. package/dist/cjs/types/request/marginuni.js.map +1 -0
  66. package/dist/cjs/types/request/multicollateralLoan.d.ts +55 -0
  67. package/dist/cjs/types/request/multicollateralLoan.js +7 -0
  68. package/dist/cjs/types/request/multicollateralLoan.js.map +1 -0
  69. package/dist/cjs/types/request/options.d.ts +81 -0
  70. package/dist/cjs/types/request/options.js +3 -0
  71. package/dist/cjs/types/request/options.js.map +1 -0
  72. package/dist/cjs/types/request/rebate.d.ts +26 -0
  73. package/dist/cjs/types/request/rebate.js +3 -0
  74. package/dist/cjs/types/request/rebate.js.map +1 -0
  75. package/dist/cjs/types/request/spot.d.ts +115 -0
  76. package/dist/cjs/types/request/spot.js +7 -0
  77. package/dist/cjs/types/request/spot.js.map +1 -0
  78. package/dist/cjs/types/request/subaccount.d.ts +19 -0
  79. package/dist/cjs/types/request/subaccount.js +3 -0
  80. package/dist/cjs/types/request/subaccount.js.map +1 -0
  81. package/dist/cjs/types/request/unified.d.ts +64 -0
  82. package/dist/cjs/types/request/unified.js +3 -0
  83. package/dist/cjs/types/request/unified.js.map +1 -0
  84. package/dist/cjs/types/request/wallet.d.ts +50 -0
  85. package/dist/cjs/types/request/wallet.js +3 -0
  86. package/dist/cjs/types/request/wallet.js.map +1 -0
  87. package/dist/cjs/types/request/withdrawal.d.ts +12 -0
  88. package/dist/cjs/types/request/withdrawal.js +7 -0
  89. package/dist/cjs/types/request/withdrawal.js.map +1 -0
  90. package/dist/cjs/types/response/account.d.ts +24 -0
  91. package/dist/cjs/types/response/account.js +7 -0
  92. package/dist/cjs/types/response/account.js.map +1 -0
  93. package/dist/cjs/types/response/collateralloan.d.ts +58 -0
  94. package/dist/cjs/types/response/collateralloan.js +7 -0
  95. package/dist/cjs/types/response/collateralloan.js.map +1 -0
  96. package/dist/cjs/types/response/delivery.d.ts +144 -0
  97. package/dist/cjs/types/response/delivery.js +7 -0
  98. package/dist/cjs/types/response/delivery.js.map +1 -0
  99. package/dist/cjs/types/response/earn.d.ts +60 -0
  100. package/dist/cjs/types/response/earn.js +7 -0
  101. package/dist/cjs/types/response/earn.js.map +1 -0
  102. package/dist/cjs/types/response/earnuni.d.ts +40 -0
  103. package/dist/cjs/types/response/earnuni.js +7 -0
  104. package/dist/cjs/types/response/earnuni.js.map +1 -0
  105. package/dist/cjs/types/response/flashswap.d.ts +32 -0
  106. package/dist/cjs/types/response/flashswap.js +7 -0
  107. package/dist/cjs/types/response/flashswap.js.map +1 -0
  108. package/dist/cjs/types/response/futures.d.ts +398 -0
  109. package/dist/cjs/types/response/futures.js +7 -0
  110. package/dist/cjs/types/response/futures.js.map +1 -0
  111. package/dist/cjs/types/response/margin.d.ts +96 -0
  112. package/dist/cjs/types/response/margin.js +7 -0
  113. package/dist/cjs/types/response/margin.js.map +1 -0
  114. package/dist/cjs/types/response/marginuni.d.ts +39 -0
  115. package/dist/cjs/types/response/marginuni.js +7 -0
  116. package/dist/cjs/types/response/marginuni.js.map +1 -0
  117. package/dist/cjs/types/response/multicollateralLoan.d.ts +151 -0
  118. package/dist/cjs/types/response/multicollateralLoan.js +7 -0
  119. package/dist/cjs/types/response/multicollateralLoan.js.map +1 -0
  120. package/dist/cjs/types/response/options.d.ts +192 -0
  121. package/dist/cjs/types/response/options.js +7 -0
  122. package/dist/cjs/types/response/options.js.map +1 -0
  123. package/dist/cjs/types/response/rebate.d.ts +40 -0
  124. package/dist/cjs/types/response/rebate.js +3 -0
  125. package/dist/cjs/types/response/rebate.js.map +1 -0
  126. package/dist/cjs/types/response/shared.d.ts +5 -0
  127. package/dist/cjs/types/response/shared.js +3 -0
  128. package/dist/cjs/types/response/shared.js.map +1 -0
  129. package/dist/cjs/types/response/spot.d.ts +224 -0
  130. package/dist/cjs/types/response/spot.js +7 -0
  131. package/dist/cjs/types/response/spot.js.map +1 -0
  132. package/dist/cjs/types/response/subaccount.d.ts +40 -0
  133. package/dist/cjs/types/response/subaccount.js +3 -0
  134. package/dist/cjs/types/response/subaccount.js.map +1 -0
  135. package/dist/cjs/types/response/unified.d.ts +113 -0
  136. package/dist/cjs/types/response/unified.js +3 -0
  137. package/dist/cjs/types/response/unified.js.map +1 -0
  138. package/dist/cjs/types/response/wallet.d.ts +181 -0
  139. package/dist/cjs/types/response/wallet.js +3 -0
  140. package/dist/cjs/types/response/wallet.js.map +1 -0
  141. package/dist/cjs/types/response/withdrawal.d.ts +12 -0
  142. package/dist/cjs/types/response/withdrawal.js +3 -0
  143. package/dist/cjs/types/response/withdrawal.js.map +1 -0
  144. package/dist/cjs/types/shared.d.ts +16 -0
  145. package/dist/cjs/types/shared.js +3 -0
  146. package/dist/cjs/types/shared.js.map +1 -0
  147. package/dist/cjs/types/websockets/client.d.ts +44 -0
  148. package/dist/cjs/types/websockets/client.js +6 -0
  149. package/dist/cjs/types/websockets/client.js.map +1 -0
  150. package/dist/cjs/types/websockets/events.d.ts +5 -0
  151. package/dist/cjs/types/websockets/events.js +3 -0
  152. package/dist/cjs/types/websockets/events.js.map +1 -0
  153. package/dist/cjs/types/websockets/requests.d.ts +36 -0
  154. package/dist/cjs/types/websockets/requests.js +3 -0
  155. package/dist/cjs/types/websockets/requests.js.map +1 -0
  156. package/dist/cjs/types/websockets/wsAPI.d.ts +101 -0
  157. package/dist/cjs/types/websockets/wsAPI.js +8 -0
  158. package/dist/cjs/types/websockets/wsAPI.js.map +1 -0
  159. package/dist/mjs/RestClient.d.ts +2534 -0
  160. package/dist/mjs/RestClient.js +2696 -0
  161. package/dist/mjs/RestClient.js.map +1 -0
  162. package/dist/mjs/WebsocketClient.d.ts +107 -0
  163. package/dist/mjs/WebsocketClient.js +500 -0
  164. package/dist/mjs/WebsocketClient.js.map +1 -0
  165. package/dist/mjs/index.d.ts +43 -0
  166. package/dist/mjs/index.js +48 -0
  167. package/dist/mjs/index.js.map +1 -0
  168. package/dist/mjs/lib/BaseRestClient.d.ts +63 -0
  169. package/dist/mjs/lib/BaseRestClient.js +317 -0
  170. package/dist/mjs/lib/BaseRestClient.js.map +1 -0
  171. package/dist/mjs/lib/BaseWSClient.d.ts +172 -0
  172. package/dist/mjs/lib/BaseWSClient.js +612 -0
  173. package/dist/mjs/lib/BaseWSClient.js.map +1 -0
  174. package/dist/mjs/lib/logger.d.ts +6 -0
  175. package/dist/mjs/lib/logger.js +13 -0
  176. package/dist/mjs/lib/logger.js.map +1 -0
  177. package/dist/mjs/lib/misc-util.d.ts +1 -0
  178. package/dist/mjs/lib/misc-util.js +4 -0
  179. package/dist/mjs/lib/misc-util.js.map +1 -0
  180. package/dist/mjs/lib/requestUtils.d.ts +38 -0
  181. package/dist/mjs/lib/requestUtils.js +41 -0
  182. package/dist/mjs/lib/requestUtils.js.map +1 -0
  183. package/dist/mjs/lib/webCryptoAPI.d.ts +10 -0
  184. package/dist/mjs/lib/webCryptoAPI.js +52 -0
  185. package/dist/mjs/lib/webCryptoAPI.js.map +1 -0
  186. package/dist/mjs/lib/websocket/WsStore.d.ts +57 -0
  187. package/dist/mjs/lib/websocket/WsStore.js +244 -0
  188. package/dist/mjs/lib/websocket/WsStore.js.map +1 -0
  189. package/dist/mjs/lib/websocket/WsStore.types.d.ts +44 -0
  190. package/dist/mjs/lib/websocket/WsStore.types.js +10 -0
  191. package/dist/mjs/lib/websocket/WsStore.types.js.map +1 -0
  192. package/dist/mjs/lib/websocket/websocket-util.d.ts +78 -0
  193. package/dist/mjs/lib/websocket/websocket-util.js +145 -0
  194. package/dist/mjs/lib/websocket/websocket-util.js.map +1 -0
  195. package/dist/mjs/package.json +3 -0
  196. package/dist/mjs/types/request/account.d.ts +10 -0
  197. package/dist/mjs/types/request/account.js +6 -0
  198. package/dist/mjs/types/request/account.js.map +1 -0
  199. package/dist/mjs/types/request/collateralLoan.d.ts +39 -0
  200. package/dist/mjs/types/request/collateralLoan.js +6 -0
  201. package/dist/mjs/types/request/collateralLoan.js.map +1 -0
  202. package/dist/mjs/types/request/delivery.d.ts +89 -0
  203. package/dist/mjs/types/request/delivery.js +6 -0
  204. package/dist/mjs/types/request/delivery.js.map +1 -0
  205. package/dist/mjs/types/request/earn.d.ts +16 -0
  206. package/dist/mjs/types/request/earn.js +6 -0
  207. package/dist/mjs/types/request/earn.js.map +1 -0
  208. package/dist/mjs/types/request/earnuni.d.ts +30 -0
  209. package/dist/mjs/types/request/earnuni.js +6 -0
  210. package/dist/mjs/types/request/earnuni.js.map +1 -0
  211. package/dist/mjs/types/request/flashswap.d.ts +28 -0
  212. package/dist/mjs/types/request/flashswap.js +6 -0
  213. package/dist/mjs/types/request/flashswap.js.map +1 -0
  214. package/dist/mjs/types/request/futures.d.ts +168 -0
  215. package/dist/mjs/types/request/futures.js +6 -0
  216. package/dist/mjs/types/request/futures.js.map +1 -0
  217. package/dist/mjs/types/request/margin.d.ts +47 -0
  218. package/dist/mjs/types/request/margin.js +6 -0
  219. package/dist/mjs/types/request/margin.js.map +1 -0
  220. package/dist/mjs/types/request/marginuni.d.ts +29 -0
  221. package/dist/mjs/types/request/marginuni.js +6 -0
  222. package/dist/mjs/types/request/marginuni.js.map +1 -0
  223. package/dist/mjs/types/request/multicollateralLoan.d.ts +55 -0
  224. package/dist/mjs/types/request/multicollateralLoan.js +6 -0
  225. package/dist/mjs/types/request/multicollateralLoan.js.map +1 -0
  226. package/dist/mjs/types/request/options.d.ts +81 -0
  227. package/dist/mjs/types/request/options.js +2 -0
  228. package/dist/mjs/types/request/options.js.map +1 -0
  229. package/dist/mjs/types/request/rebate.d.ts +26 -0
  230. package/dist/mjs/types/request/rebate.js +2 -0
  231. package/dist/mjs/types/request/rebate.js.map +1 -0
  232. package/dist/mjs/types/request/spot.d.ts +115 -0
  233. package/dist/mjs/types/request/spot.js +6 -0
  234. package/dist/mjs/types/request/spot.js.map +1 -0
  235. package/dist/mjs/types/request/subaccount.d.ts +19 -0
  236. package/dist/mjs/types/request/subaccount.js +2 -0
  237. package/dist/mjs/types/request/subaccount.js.map +1 -0
  238. package/dist/mjs/types/request/unified.d.ts +64 -0
  239. package/dist/mjs/types/request/unified.js +2 -0
  240. package/dist/mjs/types/request/unified.js.map +1 -0
  241. package/dist/mjs/types/request/wallet.d.ts +50 -0
  242. package/dist/mjs/types/request/wallet.js +2 -0
  243. package/dist/mjs/types/request/wallet.js.map +1 -0
  244. package/dist/mjs/types/request/withdrawal.d.ts +12 -0
  245. package/dist/mjs/types/request/withdrawal.js +6 -0
  246. package/dist/mjs/types/request/withdrawal.js.map +1 -0
  247. package/dist/mjs/types/response/account.d.ts +24 -0
  248. package/dist/mjs/types/response/account.js +6 -0
  249. package/dist/mjs/types/response/account.js.map +1 -0
  250. package/dist/mjs/types/response/collateralloan.d.ts +58 -0
  251. package/dist/mjs/types/response/collateralloan.js +6 -0
  252. package/dist/mjs/types/response/collateralloan.js.map +1 -0
  253. package/dist/mjs/types/response/delivery.d.ts +144 -0
  254. package/dist/mjs/types/response/delivery.js +6 -0
  255. package/dist/mjs/types/response/delivery.js.map +1 -0
  256. package/dist/mjs/types/response/earn.d.ts +60 -0
  257. package/dist/mjs/types/response/earn.js +6 -0
  258. package/dist/mjs/types/response/earn.js.map +1 -0
  259. package/dist/mjs/types/response/earnuni.d.ts +40 -0
  260. package/dist/mjs/types/response/earnuni.js +6 -0
  261. package/dist/mjs/types/response/earnuni.js.map +1 -0
  262. package/dist/mjs/types/response/flashswap.d.ts +32 -0
  263. package/dist/mjs/types/response/flashswap.js +6 -0
  264. package/dist/mjs/types/response/flashswap.js.map +1 -0
  265. package/dist/mjs/types/response/futures.d.ts +398 -0
  266. package/dist/mjs/types/response/futures.js +6 -0
  267. package/dist/mjs/types/response/futures.js.map +1 -0
  268. package/dist/mjs/types/response/margin.d.ts +96 -0
  269. package/dist/mjs/types/response/margin.js +6 -0
  270. package/dist/mjs/types/response/margin.js.map +1 -0
  271. package/dist/mjs/types/response/marginuni.d.ts +39 -0
  272. package/dist/mjs/types/response/marginuni.js +6 -0
  273. package/dist/mjs/types/response/marginuni.js.map +1 -0
  274. package/dist/mjs/types/response/multicollateralLoan.d.ts +151 -0
  275. package/dist/mjs/types/response/multicollateralLoan.js +6 -0
  276. package/dist/mjs/types/response/multicollateralLoan.js.map +1 -0
  277. package/dist/mjs/types/response/options.d.ts +192 -0
  278. package/dist/mjs/types/response/options.js +6 -0
  279. package/dist/mjs/types/response/options.js.map +1 -0
  280. package/dist/mjs/types/response/rebate.d.ts +40 -0
  281. package/dist/mjs/types/response/rebate.js +2 -0
  282. package/dist/mjs/types/response/rebate.js.map +1 -0
  283. package/dist/mjs/types/response/shared.d.ts +5 -0
  284. package/dist/mjs/types/response/shared.js +2 -0
  285. package/dist/mjs/types/response/shared.js.map +1 -0
  286. package/dist/mjs/types/response/spot.d.ts +224 -0
  287. package/dist/mjs/types/response/spot.js +6 -0
  288. package/dist/mjs/types/response/spot.js.map +1 -0
  289. package/dist/mjs/types/response/subaccount.d.ts +40 -0
  290. package/dist/mjs/types/response/subaccount.js +2 -0
  291. package/dist/mjs/types/response/subaccount.js.map +1 -0
  292. package/dist/mjs/types/response/unified.d.ts +113 -0
  293. package/dist/mjs/types/response/unified.js +2 -0
  294. package/dist/mjs/types/response/unified.js.map +1 -0
  295. package/dist/mjs/types/response/wallet.d.ts +181 -0
  296. package/dist/mjs/types/response/wallet.js +2 -0
  297. package/dist/mjs/types/response/wallet.js.map +1 -0
  298. package/dist/mjs/types/response/withdrawal.d.ts +12 -0
  299. package/dist/mjs/types/response/withdrawal.js +2 -0
  300. package/dist/mjs/types/response/withdrawal.js.map +1 -0
  301. package/dist/mjs/types/shared.d.ts +16 -0
  302. package/dist/mjs/types/shared.js +2 -0
  303. package/dist/mjs/types/shared.js.map +1 -0
  304. package/dist/mjs/types/websockets/client.d.ts +44 -0
  305. package/dist/mjs/types/websockets/client.js +5 -0
  306. package/dist/mjs/types/websockets/client.js.map +1 -0
  307. package/dist/mjs/types/websockets/events.d.ts +5 -0
  308. package/dist/mjs/types/websockets/events.js +2 -0
  309. package/dist/mjs/types/websockets/events.js.map +1 -0
  310. package/dist/mjs/types/websockets/requests.d.ts +36 -0
  311. package/dist/mjs/types/websockets/requests.js +2 -0
  312. package/dist/mjs/types/websockets/requests.js.map +1 -0
  313. package/dist/mjs/types/websockets/wsAPI.d.ts +101 -0
  314. package/dist/mjs/types/websockets/wsAPI.js +7 -0
  315. package/dist/mjs/types/websockets/wsAPI.js.map +1 -0
  316. package/package.json +49 -38
  317. package/index.js +0 -1
  318. package/lib/index.d.ts +0 -1
  319. package/lib/index.js +0 -16
  320. package/lib/index.js.map +0 -1
package/README.md CHANGED
@@ -1,104 +1,135 @@
1
- # gateio-api
2
- [![Tests](https://circleci.com/gh/tiagosiebler/gateio-api.svg?style=shield)](https://circleci.com/gh/tiagosiebler/gateio-api)
3
- [![npm version](https://img.shields.io/npm/v/gateio-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/gateio-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/gateio-api)][1]
1
+ # Node.js & JavaScript SDK for Gate.io REST APIs, WebSockets & WebSocket API
2
+
3
+ ![GitHub-Mark-Light](https://github.com/tiagosiebler/gateio-api/blob/master/docs/images/logoDarkMode2.svg?raw=true#gh-dark-mode-only)
4
+ ![GitHub-Mark-Dark](./docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only)
5
+
6
+ [![npm version](https://img.shields.io/npm/v/gateio-api)][1]
7
+ [![npm size](https://img.shields.io/bundlephobia/min/gateio-api/latest)][1]
8
+ [![npm downloads](https://img.shields.io/npm/dt/gateio-api)][1]
9
+ [![Build & Test](https://github.com/tiagosiebler/gateio-api/actions/workflows/e2etest.yml/badge.svg?branch=master)](https://github.com/tiagosiebler/gateio-api/actions/workflows/e2etest.yml)
4
10
  [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/gateio-api)][1]
5
- [![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/gateio-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/gateio-api)
11
+ [![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/nodetraders)
6
12
 
7
13
  [1]: https://www.npmjs.com/package/gateio-api
8
14
 
9
- WARNING: This package is still early beta, following the designs of my other connectors. If you want to stay informed when this may be ready for testing, please get in touch via telegram.
10
-
11
- Node.js connector for the gateio APIs and WebSockets, with TypeScript & browser support.
15
+ Updated & performant JavaScript & Node.js SDK for the Gate.io REST APIs and WebSockets:
16
+
17
+ - Extensive integration with Gate.io REST APIs and WebSockets.
18
+ - TypeScript support (with type declarations for most API requests & responses).
19
+ - Gate.io REST APIs for Gate.io Spot, Margin, Perpetual Futures, Delivery Futures, Options & Announcements APIs.
20
+ - Strongly typed on most requests and responses.
21
+ - Extremely robust & performant JavaScript/Node.js Gate.io SDK.
22
+ - Actively maintained with a modern, promise-driven interface.
23
+ - Support for seamless API authentication for private Gate.io REST API and WebSocket calls.
24
+ - Gate.io Spot, Margin, Perpetual Futures, Delivery Futures & Options.
25
+ - Event driven messaging.
26
+ - Smart websocket persistence
27
+ - Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
28
+ - Automatically handle listenKey persistence and expiration/refresh.
29
+ - Emit `reconnected` event when dropped connection is restored.
30
+ - Websocket API for Gate.io Spot, Margin, Perpetual Futures & Delivery Futures.
31
+ - Automatic connectivity via existing WebsocketClient, just call sendWSAPIRequest to trigger a request.
32
+ - Automatic authentication, just call sendWSAPIRequest with channel & parameters.
33
+ - Choose between two interfaces for WS API communication:
34
+ - Event-driven interface, fire & forget via sendWSAPIRequest and receive async replies via wsClient's event emitter.
35
+ - Promise-driven interface, simply call and await sendWSAPIRequest for a REST-API-like behaviour with the WS API.
36
+ - Proxy support via axios integration.
37
+ - Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
12
38
 
13
39
  ## Installation
40
+
14
41
  `npm install --save gateio-api`
15
42
 
16
43
  ## Issues & Discussion
44
+
17
45
  - Issues? Check the [issues tab](https://github.com/tiagosiebler/gateio-api/issues).
18
46
  - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
19
47
 
48
+ ## Related projects
49
+
50
+ Check out my related JavaScript/TypeScript/Node.js projects:
51
+
52
+ - Try my REST API & WebSocket SDKs:
53
+ - [Bybit-api Node.js SDK](https://www.npmjs.com/package/bybit-api)
54
+ - [Binance Node.js SDK](https://www.npmjs.com/package/binance)
55
+ - [Okx-api Node.js SDK](https://www.npmjs.com/package/okx-api)
56
+ - [Gateio-api Node.js SDK](https://www.npmjs.com/package/gateio-api)
57
+ - [Bitget-api Node.js SDK](https://www.npmjs.com/package/bitget-api)
58
+ - [Bitmart-api Node.js SDK](https://www.npmjs.com/package/bitmart-api)
59
+ - Try my misc utilities:
60
+ - [OrderBooks Node.js](https://www.npmjs.com/package/orderbooks)
61
+ - [Crypto Exchange Account State Cache](https://www.npmjs.com/package/accountstate)
62
+ - Check out my examples:
63
+ - [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)
64
+
20
65
  ## Documentation
66
+
21
67
  Most methods accept JS objects. These can be populated using parameters specified by gateio's API documentation.
68
+
22
69
  - [Gate.io API Documentation](https://www.gate.io/docs/developers/apiv4/en/).
70
+ - [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/gateio-api)
23
71
 
24
72
  ## Structure
25
- This project uses typescript. Resources are stored in 3 key structures:
73
+
74
+ This project uses typescript. Resources are stored in 2 key structures:
75
+
26
76
  - [src](./src) - the whole connector written in typescript
27
- - [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
28
- - [dist](./dist) - the packed bundle of the project for use in browser environments.
29
77
  - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
30
78
 
31
79
  ---
32
80
 
33
81
  # Usage
34
- <!-- Create API credentials at okx
35
- - [OKX my-api](https://www.okx.com/account/my-api) -->
36
-
37
- <!--
38
- ### REST Inverse
39
- To use the inverse REST APIs, import the `InverseClient`:
40
-
41
- ```javascript
42
- const { InverseClient } = require('gateio-api');
43
82
 
44
- const restClientOptions = {
45
- // override the max size of the request window (in ms)
46
- recv_window?: number;
83
+ Create API credentials
47
84
 
48
- // how often to sync time drift with gateio servers
49
- sync_interval_ms?: number | string;
85
+ - [Gate.io API Key Management](https://www.gate.io/myaccount/api_key_manage)
50
86
 
51
- // Default: false. Disable above sync mechanism if true.
52
- disable_time_sync?: boolean;
87
+ ### REST API
53
88
 
54
- // Default: false. If true, we'll throw errors if any params are undefined
55
- strict_param_validation?: boolean;
89
+ To use any of Gate.io's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `RestClient`:
56
90
 
57
- // Optionally override API protocol + domain
58
- // e.g 'https://api.bytick.com'
59
- baseUrl?: string;
60
-
61
- // Default: true. whether to try and post-process request exceptions.
62
- parse_exceptions?: boolean;
63
- };
91
+ ```javascript
92
+ const { RestClient } = require('gateio-api');
64
93
 
65
94
  const API_KEY = 'xxx';
66
95
  const PRIVATE_KEY = 'yyy';
67
- const useLivenet = false;
68
-
69
- const client = new InverseClient(
70
- API_KEY,
71
- PRIVATE_KEY,
72
96
 
73
- // optional, uses testnet by default. Set to 'true' to use livenet.
74
- useLivenet,
75
-
76
- // restClientOptions,
77
- // requestLibraryOptions
78
- );
97
+ const client = new RestClient({
98
+ apiKey: API_KEY,
99
+ apiSecret: PRIVATE_KEY,
100
+ });
79
101
 
80
- client.getApiKeyInfo()
81
- .then(result => {
82
- console.log("apiKey result: ", result);
102
+ client
103
+ .getSpotTicker()
104
+ .then((result) => {
105
+ console.log('all spot tickers result: ', result);
83
106
  })
84
- .catch(err => {
85
- console.error("apiKey error: ", err);
107
+ .catch((err) => {
108
+ console.error('spot ticker error: ', err);
86
109
  });
87
110
 
88
- client.getOrderBook({ symbol: 'BTCUSD' })
89
- .then(result => {
90
- console.log("getOrderBook inverse result: ", result);
111
+ client
112
+ .getSpotOrders({
113
+ currency_pair: 'BTC_USDT', // Specify the currency pair
114
+ status: 'open', // Specify the status of the orders to fetch
91
115
  })
92
- .catch(err => {
93
- console.error("getOrderBook inverse error: ", err);
116
+ .then((result) => {
117
+ console.log('getSpotOrders result: ', result);
118
+ })
119
+ .catch((err) => {
120
+ console.error('getSpotOrders error: ', err);
94
121
  });
95
122
  ```
96
123
 
97
-
98
- See [inverse-client.ts](./src/inverse-client.ts) for further information. -->
124
+ See [RestClient](./src/RestClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
99
125
 
100
126
  ## WebSockets
101
- Inverse, linear & spot WebSockets can be used via a shared `WebsocketClient`. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
127
+
128
+ All available WebSockets can be used via a shared `WebsocketClient`. The WebSocket client will automatically open/track/manage connections as needed. Each unique connection (one per server URL) is tracked using a WsKey (each WsKey is a string - see [WS_KEY_MAP](src/lib/websocket/websocket-util.ts) for a list of supported values).
129
+
130
+ Any subscribe/unsubscribe events will need to include a WsKey, so the WebSocket client understands which connection the event should be routed to. See examples below or in the [examples](./examples/) folder on GitHub.
131
+
132
+ Data events are emitted from the WebsocketClient via the `update` event, see example below:
102
133
 
103
134
  ```javascript
104
135
  const { WebsocketClient } = require('gateio-api');
@@ -107,22 +138,15 @@ const API_KEY = 'xxx';
107
138
  const PRIVATE_KEY = 'yyy';
108
139
 
109
140
  const wsConfig = {
110
- key: API_KEY,
111
- secret: PRIVATE_KEY,
141
+ apiKey: API_KEY,
142
+ apiSecret: PRIVATE_KEY,
112
143
 
113
144
  /*
114
145
  The following parameters are optional:
115
146
  */
116
147
 
117
- // defaults to false == testnet. Set to true for livenet.
118
- // livenet: true
119
-
120
- // NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
121
-
122
- // defaults to inverse:
123
- // market: 'inverse'
124
- // market: 'linear'
125
- // market: 'spot'
148
+ // Livenet is used by default, use this to enable testnet:
149
+ // useTestnet: true
126
150
 
127
151
  // how long to wait (in ms) before deciding the connection should be terminated & reconnected
128
152
  // pongTimeout: 1000,
@@ -138,22 +162,51 @@ const wsConfig = {
138
162
 
139
163
  // config for axios used for HTTP requests. E.g for proxy support
140
164
  // requestOptions: { }
141
-
142
- // override which URL to use for websocket connections
143
- // wsUrl: 'wss://stream.bytick.com/realtime'
144
165
  };
145
166
 
146
167
  const ws = new WebsocketClient(wsConfig);
147
168
 
169
+ /**
170
+ * Subscribing to data:
171
+ **/
172
+
173
+ const userOrders = {
174
+ topic: 'spot.orders',
175
+ payload: ['BTC_USDT', 'ETH_USDT', 'MATIC_USDT'],
176
+ };
177
+
178
+ const userTrades = {
179
+ topic: 'spot.usertrades',
180
+ payload: ['BTC_USDT', 'ETH_USDT', 'MATIC_USDT'],
181
+ };
182
+
183
+ const userPriceOrders = {
184
+ topic: 'spot.priceorders',
185
+ payload: ['!all'],
186
+ };
187
+
148
188
  // subscribe to multiple topics at once
149
- ws.subscribe(['position', 'execution', 'trade']);
189
+ ws.subscribe([userOrders, userTrades, userPriceOrders], 'spotV4');
150
190
 
151
191
  // and/or subscribe to individual topics on demand
152
- ws.subscribe('kline.BTCUSD.1m');
192
+ ws.subscribe(
193
+ {
194
+ topic: 'spot.priceorders',
195
+ payload: ['!all'],
196
+ },
197
+ 'spotV4',
198
+ );
199
+
200
+ // Some topics don't need params, for those you can just subscribe with a string (or use a topic + payload object as above)
201
+ ws.subscribe('spot.balances', 'spotV4');
202
+
203
+ /**
204
+ * Handling events:
205
+ **/
153
206
 
154
207
  // Listen to events coming from websockets. This is the primary data source
155
- ws.on('update', data => {
156
- console.log('update', data);
208
+ ws.on('update', (data) => {
209
+ console.log('data', data);
157
210
  });
158
211
 
159
212
  // Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)
@@ -161,8 +214,8 @@ ws.on('open', ({ wsKey, event }) => {
161
214
  console.log('connection open for websocket with ID: ' + wsKey);
162
215
  });
163
216
 
164
- // Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic)
165
- ws.on('response', response => {
217
+ // Optional: Listen to responses to websocket queries (e.g. the reply after subscribing to a topic)
218
+ ws.on('response', (response) => {
166
219
  console.log('response', response);
167
220
  });
168
221
 
@@ -171,21 +224,126 @@ ws.on('close', () => {
171
224
  console.log('connection closed');
172
225
  });
173
226
 
227
+ // Optional: listen to internal exceptions. Useful for debugging if something weird happens
228
+ ws.on('exception', (data) => {
229
+ console.error('exception: ', data);
230
+ });
231
+
174
232
  // Optional: Listen to raw error events.
175
- // Note: responses to invalid topics are currently only sent in the "response" event.
176
- ws.on('error', err => {
233
+ ws.on('error', (err) => {
177
234
  console.error('ERR', err);
178
235
  });
179
236
  ```
180
237
 
238
+ See [WebsocketClient](./src/WebsocketClient.ts) for further information and make sure to check the [examples](./examples/) folder for much more detail.
181
239
 
182
- See [websocket-client.ts](./src/websocket-client.ts) for further information.
240
+ ### Websocket API
183
241
 
184
- Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient.
242
+ The [WebsocketClient](./src/WebsocketClient.ts) supports this exchange's Websocket API. There are two ways to use the WS API, depending on individual preference:
243
+
244
+ - event-driven:
245
+ - send requests via `client.sendWSAPIRequest(wsKey, channel, params)`, fire and forget, don't use await
246
+ - handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)`
247
+ - promise-driven:
248
+ - send requests via `const result = await client.sendWSAPIRequest(wsKey, channel, params)`, which returns a promise
249
+ - await each call
250
+ - use try/catch blocks to handle promise rejections
251
+
252
+ The below example demonstrates the promise-driven approach, which behaves similar to a REST API. For more detailed examples, refer to the [examples](./examples/) folder (e.g the [ws-private-spot-wsapi.ts](./examples/ws-private-spot-wsapi.ts) example).
253
+
254
+ ```javascript
255
+ const { WebsocketClient } = require('gateio-api');
256
+
257
+ const API_KEY = 'xxx';
258
+ const PRIVATE_KEY = 'yyy';
259
+
260
+ async function start() {
261
+ const client = new WebsocketClient({
262
+ apiKey: API_KEY,
263
+ apiSecret: PRIVATE_KEY,
264
+ // Automatically re-auth WS API, if we were auth'd before and get reconnected
265
+ reauthWSAPIOnReconnect: true,
266
+ });
267
+
268
+ /**
269
+ * Setup basic event handlers for core connectivity events.
270
+ * Note for this approach, the `response` and `update` events are not needed (but you can use them too/instead if you prefer).
271
+ **/
272
+
273
+ // Successfully connected
274
+ client.on('open', (data) => {
275
+ console.log(new Date(), 'ws connected ', data?.wsKey);
276
+ });
277
+
278
+ // Something happened, attempting to reconnect
279
+ client.on('reconnect', (data) => {
280
+ console.log(new Date(), 'ws reconnect: ', data);
281
+ });
282
+
283
+ // Reconnect successful
284
+ client.on('reconnected', (data) => {
285
+ console.log(new Date(), 'ws reconnected: ', data);
286
+ });
287
+
288
+ // Connection closed. If unexpected, expect reconnect -> reconnected.
289
+ client.on('close', (data) => {
290
+ console.error(new Date(), 'ws close: ', data);
291
+ });
292
+
293
+ client.on('exception', (data) => {
294
+ console.error(new Date(), 'ws exception: ', data);
295
+ });
296
+
297
+ client.on('authenticated', (data) => {
298
+ console.error(new Date(), 'ws authenticated: ', data);
299
+ });
300
+
301
+ try {
302
+ /**
303
+ * All WebSocket API (WS API) messaging should be done via the sendWSAPIRequest method.
304
+ */
305
+
306
+ // The WSKey identifies which connection this request is for.
307
+ // (e.g. "spotV4" | "perpFuturesUSDTV4" | "perpFuturesBTCV4" | "deliveryFuturesUSDTV4" | "deliveryFuturesBTCV4" | "optionsV4")
308
+ const wsKey = 'spotV4';
309
+
310
+ /**
311
+ * To authenticate, send an empty request to "spot.login". The SDK will handle all the parameters.
312
+ *
313
+ * By default (reauthWSAPIOnReconnect: true), if we get reconnected later on (e.g. connection temporarily lost), we will try to re-authenticate the WS API automatically when the connection is restored.
314
+ */
315
+ console.log(new Date(), 'try authenticate');
316
+ const loginResult = await client.sendWSAPIRequest(wsKey, 'spot.login');
317
+ console.log(new Date(), 'authenticated!', loginResult);
318
+
319
+ /**
320
+ * For other channels, you should include any parameters for the request (the payload) in your call.
321
+ *
322
+ * Note that internal parameters such as "signature" etc are all handled automatically by the SDK. Only the core request parameters are needed.
323
+ */
324
+ console.log(new Date(), 'try get order status');
325
+ const orderStatus = await client.sendWSAPIRequest(
326
+ wsKey,
327
+ 'spot.order_status',
328
+ {
329
+ order_id: '600995435390',
330
+ currency_pair: 'BTC_USDT',
331
+ },
332
+ );
333
+
334
+ console.log(new Date(), 'orderStatus result!', orderStatus);
335
+ } catch (e) {
336
+ console.error(`WS API Error: `, e);
337
+ }
338
+ }
339
+
340
+ start();
341
+ ```
185
342
 
186
343
  ---
187
344
 
188
345
  ## Customise Logging
346
+
189
347
  Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
190
348
 
191
349
  ```javascript
@@ -194,34 +352,21 @@ const { WebsocketClient, DefaultLogger } = require('gateio-api');
194
352
  // Disable all logging on the silly level
195
353
  DefaultLogger.silly = () => {};
196
354
 
197
- const ws = new WebsocketClient(
198
- { key: 'xxx', secret: 'yyy' },
199
- DefaultLogger
200
- );
355
+ const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, DefaultLogger);
201
356
  ```
202
357
 
203
- ## Browser Usage
204
- Build a bundle using webpack:
205
- - `npm install`
206
- - `npm build`
207
- - `npm pack`
208
-
209
- The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
210
-
211
358
  ---
212
359
 
213
360
  ## Contributions & Thanks
214
- ### Donations
215
- #### tiagosiebler
216
- Support my efforts to make algo trading accessible to all - register with my referral links:
217
- - [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
218
- - [Binance](https://www.binance.com/en/register?ref=20983262)
219
- - [OKX](https://www.okx.com/join/18504944)
220
- - [FTX](https://ftx.com/referrals#a=ftxapigithub)
221
-
222
- Or buy me a coffee using any of these:
223
- - BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`
224
- - ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
361
+
362
+ Have my projects helped you? Share the love, there are many ways you can show your thanks:
363
+
364
+ - Star & share my projects.
365
+ - Are my projects useful? Sponsor me on Github and support my effort to maintain & improve them: https://github.com/sponsors/tiagosiebler
366
+ - Have an interesting project? Get in touch & invite me to it.
367
+ - Or buy me all the coffee:
368
+ - ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` <!-- metamask -->
225
369
 
226
370
  ### Contributions & Pull Requests
371
+
227
372
  Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.