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