@himalaya-quant/ctrader-x 0.0.7

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 (308) hide show
  1. package/.env +6 -0
  2. package/.prettierrc +7 -0
  3. package/README.md +96 -0
  4. package/changelog.md +46 -0
  5. package/dist/src/classes/client.d.ts +21 -0
  6. package/dist/src/classes/client.d.ts.map +1 -0
  7. package/dist/src/classes/client.js +83 -0
  8. package/dist/src/classes/client.js.map +1 -0
  9. package/dist/src/classes/client.test.d.ts +2 -0
  10. package/dist/src/classes/client.test.d.ts.map +1 -0
  11. package/dist/src/classes/client.test.js +83 -0
  12. package/dist/src/classes/client.test.js.map +1 -0
  13. package/dist/src/classes/errors/client-not-connected.error.d.ts +5 -0
  14. package/dist/src/classes/errors/client-not-connected.error.d.ts.map +1 -0
  15. package/dist/src/classes/errors/client-not-connected.error.js +11 -0
  16. package/dist/src/classes/errors/client-not-connected.error.js.map +1 -0
  17. package/dist/src/classes/errors/connection.error.d.ts +5 -0
  18. package/dist/src/classes/errors/connection.error.d.ts.map +1 -0
  19. package/dist/src/classes/errors/connection.error.js +11 -0
  20. package/dist/src/classes/errors/connection.error.js.map +1 -0
  21. package/dist/src/classes/logger.d.ts +13 -0
  22. package/dist/src/classes/logger.d.ts.map +1 -0
  23. package/dist/src/classes/logger.js +21 -0
  24. package/dist/src/classes/logger.js.map +1 -0
  25. package/dist/src/classes/managers/authentication/authentication.manager.d.ts +13 -0
  26. package/dist/src/classes/managers/authentication/authentication.manager.d.ts.map +1 -0
  27. package/dist/src/classes/managers/authentication/authentication.manager.js +49 -0
  28. package/dist/src/classes/managers/authentication/authentication.manager.js.map +1 -0
  29. package/dist/src/classes/managers/authentication/authentication.manager.test.d.ts +2 -0
  30. package/dist/src/classes/managers/authentication/authentication.manager.test.d.ts.map +1 -0
  31. package/dist/src/classes/managers/authentication/authentication.manager.test.js +114 -0
  32. package/dist/src/classes/managers/authentication/authentication.manager.test.js.map +1 -0
  33. package/dist/src/classes/managers/authentication/errors/application-auth.error.d.ts +5 -0
  34. package/dist/src/classes/managers/authentication/errors/application-auth.error.d.ts.map +1 -0
  35. package/dist/src/classes/managers/authentication/errors/application-auth.error.js +11 -0
  36. package/dist/src/classes/managers/authentication/errors/application-auth.error.js.map +1 -0
  37. package/dist/src/classes/managers/authentication/errors/user-auth.error.d.ts +5 -0
  38. package/dist/src/classes/managers/authentication/errors/user-auth.error.d.ts.map +1 -0
  39. package/dist/src/classes/managers/authentication/errors/user-auth.error.js +11 -0
  40. package/dist/src/classes/managers/authentication/errors/user-auth.error.js.map +1 -0
  41. package/dist/src/classes/managers/models/base.manager.d.ts +15 -0
  42. package/dist/src/classes/managers/models/base.manager.d.ts.map +1 -0
  43. package/dist/src/classes/managers/models/base.manager.js +35 -0
  44. package/dist/src/classes/managers/models/base.manager.js.map +1 -0
  45. package/dist/src/classes/managers/models/credentials.model.d.ts +8 -0
  46. package/dist/src/classes/managers/models/credentials.model.d.ts.map +1 -0
  47. package/dist/src/classes/managers/models/credentials.model.js +3 -0
  48. package/dist/src/classes/managers/models/credentials.model.js.map +1 -0
  49. package/dist/src/classes/managers/symbols/errors/get-symbols-details.error.d.ts +5 -0
  50. package/dist/src/classes/managers/symbols/errors/get-symbols-details.error.d.ts.map +1 -0
  51. package/dist/src/classes/managers/symbols/errors/get-symbols-details.error.js +11 -0
  52. package/dist/src/classes/managers/symbols/errors/get-symbols-details.error.js.map +1 -0
  53. package/dist/src/classes/managers/symbols/errors/get-symbols-list.error.d.ts +5 -0
  54. package/dist/src/classes/managers/symbols/errors/get-symbols-list.error.d.ts.map +1 -0
  55. package/dist/src/classes/managers/symbols/errors/get-symbols-list.error.js +11 -0
  56. package/dist/src/classes/managers/symbols/errors/get-symbols-list.error.js.map +1 -0
  57. package/dist/src/classes/managers/symbols/errors/get-trend-bars.error.d.ts +6 -0
  58. package/dist/src/classes/managers/symbols/errors/get-trend-bars.error.d.ts.map +1 -0
  59. package/dist/src/classes/managers/symbols/errors/get-trend-bars.error.js +13 -0
  60. package/dist/src/classes/managers/symbols/errors/get-trend-bars.error.js.map +1 -0
  61. package/dist/src/classes/managers/symbols/errors/subscribe-live-trend-bars.error.d.ts +8 -0
  62. package/dist/src/classes/managers/symbols/errors/subscribe-live-trend-bars.error.d.ts.map +1 -0
  63. package/dist/src/classes/managers/symbols/errors/subscribe-live-trend-bars.error.js +17 -0
  64. package/dist/src/classes/managers/symbols/errors/subscribe-live-trend-bars.error.js.map +1 -0
  65. package/dist/src/classes/managers/symbols/errors/subscribe-spot-events.error.d.ts +5 -0
  66. package/dist/src/classes/managers/symbols/errors/subscribe-spot-events.error.d.ts.map +1 -0
  67. package/dist/src/classes/managers/symbols/errors/subscribe-spot-events.error.js +11 -0
  68. package/dist/src/classes/managers/symbols/errors/subscribe-spot-events.error.js.map +1 -0
  69. package/dist/src/classes/managers/symbols/errors/unsubscribe-live-trend-bars.error.d.ts +5 -0
  70. package/dist/src/classes/managers/symbols/errors/unsubscribe-live-trend-bars.error.d.ts.map +1 -0
  71. package/dist/src/classes/managers/symbols/errors/unsubscribe-live-trend-bars.error.js +11 -0
  72. package/dist/src/classes/managers/symbols/errors/unsubscribe-live-trend-bars.error.js.map +1 -0
  73. package/dist/src/classes/managers/symbols/symbols-updates.manager.d.ts +54 -0
  74. package/dist/src/classes/managers/symbols/symbols-updates.manager.d.ts.map +1 -0
  75. package/dist/src/classes/managers/symbols/symbols-updates.manager.js +250 -0
  76. package/dist/src/classes/managers/symbols/symbols-updates.manager.js.map +1 -0
  77. package/dist/src/classes/managers/symbols/symbols.manager.d.ts +30 -0
  78. package/dist/src/classes/managers/symbols/symbols.manager.d.ts.map +1 -0
  79. package/dist/src/classes/managers/symbols/symbols.manager.js +78 -0
  80. package/dist/src/classes/managers/symbols/symbols.manager.js.map +1 -0
  81. package/dist/src/classes/managers/symbols/symbols.manager.test.d.ts +2 -0
  82. package/dist/src/classes/managers/symbols/symbols.manager.test.d.ts.map +1 -0
  83. package/dist/src/classes/managers/symbols/symbols.manager.test.js +364 -0
  84. package/dist/src/classes/managers/symbols/symbols.manager.test.js.map +1 -0
  85. package/dist/src/classes/models/client-configuration.model.d.ts +10 -0
  86. package/dist/src/classes/models/client-configuration.model.d.ts.map +1 -0
  87. package/dist/src/classes/models/client-configuration.model.js +3 -0
  88. package/dist/src/classes/models/client-configuration.model.js.map +1 -0
  89. package/dist/src/classes/models/ctrader-x-error.model.d.ts +6 -0
  90. package/dist/src/classes/models/ctrader-x-error.model.d.ts.map +1 -0
  91. package/dist/src/classes/models/ctrader-x-error.model.js +21 -0
  92. package/dist/src/classes/models/ctrader-x-error.model.js.map +1 -0
  93. package/dist/src/config/config.d.ts +10 -0
  94. package/dist/src/config/config.d.ts.map +1 -0
  95. package/dist/src/config/config.js +40 -0
  96. package/dist/src/config/config.js.map +1 -0
  97. package/dist/src/examples/authentication.example.d.ts +2 -0
  98. package/dist/src/examples/authentication.example.d.ts.map +1 -0
  99. package/dist/src/examples/authentication.example.js +9 -0
  100. package/dist/src/examples/authentication.example.js.map +1 -0
  101. package/dist/src/examples/get-symbols-bars.example.d.ts +2 -0
  102. package/dist/src/examples/get-symbols-bars.example.d.ts.map +1 -0
  103. package/dist/src/examples/get-symbols-bars.example.js +18 -0
  104. package/dist/src/examples/get-symbols-bars.example.js.map +1 -0
  105. package/dist/src/examples/get-symbols-list.example.d.ts +2 -0
  106. package/dist/src/examples/get-symbols-list.example.d.ts.map +1 -0
  107. package/dist/src/examples/get-symbols-list.example.js +13 -0
  108. package/dist/src/examples/get-symbols-list.example.js.map +1 -0
  109. package/dist/src/examples/subscribe-live-bars.example.d.ts +2 -0
  110. package/dist/src/examples/subscribe-live-bars.example.d.ts.map +1 -0
  111. package/dist/src/examples/subscribe-live-bars.example.js +42 -0
  112. package/dist/src/examples/subscribe-live-bars.example.js.map +1 -0
  113. package/dist/src/index.d.ts +4 -0
  114. package/dist/src/index.d.ts.map +1 -0
  115. package/dist/src/index.js +20 -0
  116. package/dist/src/index.js.map +1 -0
  117. package/dist/src/models/common/ohlcv.d.ts +10 -0
  118. package/dist/src/models/common/ohlcv.d.ts.map +1 -0
  119. package/dist/src/models/common/ohlcv.js +13 -0
  120. package/dist/src/models/common/ohlcv.js.map +1 -0
  121. package/dist/src/models/proto/base-proto.d.ts +5 -0
  122. package/dist/src/models/proto/base-proto.d.ts.map +1 -0
  123. package/dist/src/models/proto/base-proto.js +9 -0
  124. package/dist/src/models/proto/base-proto.js.map +1 -0
  125. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthReq.d.ts +5 -0
  126. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthReq.d.ts.map +1 -0
  127. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthReq.js +9 -0
  128. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthReq.js.map +1 -0
  129. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthRes.d.ts +4 -0
  130. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthRes.d.ts.map +1 -0
  131. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthRes.js +8 -0
  132. package/dist/src/models/proto/messages/authentication/ProtoOAAccountAuthRes.js.map +1 -0
  133. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthReq.d.ts +6 -0
  134. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthReq.d.ts.map +1 -0
  135. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthReq.js +10 -0
  136. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthReq.js.map +1 -0
  137. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthRes.d.ts +4 -0
  138. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthRes.d.ts.map +1 -0
  139. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthRes.js +8 -0
  140. package/dist/src/models/proto/messages/authentication/ProtoOAApplicationAuthRes.js.map +1 -0
  141. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsReq.d.ts +6 -0
  142. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsReq.d.ts.map +1 -0
  143. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsReq.js +10 -0
  144. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsReq.js.map +1 -0
  145. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsRes.d.ts +4 -0
  146. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsRes.d.ts.map +1 -0
  147. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsRes.js +8 -0
  148. package/dist/src/models/proto/messages/common/ProtoOASubscribeSpotsRes.js.map +1 -0
  149. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsReq.d.ts +10 -0
  150. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsReq.d.ts.map +1 -0
  151. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsReq.js +13 -0
  152. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsReq.js.map +1 -0
  153. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsRes.d.ts +11 -0
  154. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsRes.d.ts.map +1 -0
  155. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsRes.js +13 -0
  156. package/dist/src/models/proto/messages/symbols/ProtoOAGetTrendbarsRes.js.map +1 -0
  157. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarReq.d.ts +7 -0
  158. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarReq.d.ts.map +1 -0
  159. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarReq.js +10 -0
  160. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarReq.js.map +1 -0
  161. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarRes.d.ts +4 -0
  162. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarRes.d.ts.map +1 -0
  163. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarRes.js +8 -0
  164. package/dist/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarRes.js.map +1 -0
  165. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdReq.d.ts +5 -0
  166. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdReq.d.ts.map +1 -0
  167. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdReq.js +9 -0
  168. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdReq.js.map +1 -0
  169. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdRes.d.ts +8 -0
  170. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdRes.d.ts.map +1 -0
  171. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdRes.js +10 -0
  172. package/dist/src/models/proto/messages/symbols/ProtoOASymbolByIdRes.js.map +1 -0
  173. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListReq.d.ts +5 -0
  174. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListReq.d.ts.map +1 -0
  175. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListReq.js +9 -0
  176. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListReq.js.map +1 -0
  177. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListRes.d.ts +7 -0
  178. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListRes.d.ts.map +1 -0
  179. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListRes.js +10 -0
  180. package/dist/src/models/proto/messages/symbols/ProtoOASymbolsListRes.js.map +1 -0
  181. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarReq.d.ts +7 -0
  182. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarReq.d.ts.map +1 -0
  183. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarReq.js +10 -0
  184. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarReq.js.map +1 -0
  185. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarRes.d.ts +4 -0
  186. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarRes.d.ts.map +1 -0
  187. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarRes.js +8 -0
  188. package/dist/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarRes.js.map +1 -0
  189. package/dist/src/models/proto/models/ProtoOAArchivedSymbol.d.ts +7 -0
  190. package/dist/src/models/proto/models/ProtoOAArchivedSymbol.d.ts.map +1 -0
  191. package/dist/src/models/proto/models/ProtoOAArchivedSymbol.js +11 -0
  192. package/dist/src/models/proto/models/ProtoOAArchivedSymbol.js.map +1 -0
  193. package/dist/src/models/proto/models/ProtoOAErrorRes.d.ts +8 -0
  194. package/dist/src/models/proto/models/ProtoOAErrorRes.d.ts.map +1 -0
  195. package/dist/src/models/proto/models/ProtoOAErrorRes.js +12 -0
  196. package/dist/src/models/proto/models/ProtoOAErrorRes.js.map +1 -0
  197. package/dist/src/models/proto/models/ProtoOAHoliday.d.ts +9 -0
  198. package/dist/src/models/proto/models/ProtoOAHoliday.d.ts.map +1 -0
  199. package/dist/src/models/proto/models/ProtoOAHoliday.js +13 -0
  200. package/dist/src/models/proto/models/ProtoOAHoliday.js.map +1 -0
  201. package/dist/src/models/proto/models/ProtoOAInterval.d.ts +6 -0
  202. package/dist/src/models/proto/models/ProtoOAInterval.d.ts.map +1 -0
  203. package/dist/src/models/proto/models/ProtoOAInterval.js +10 -0
  204. package/dist/src/models/proto/models/ProtoOAInterval.js.map +1 -0
  205. package/dist/src/models/proto/models/ProtoOALightSymbol.d.ts +11 -0
  206. package/dist/src/models/proto/models/ProtoOALightSymbol.d.ts.map +1 -0
  207. package/dist/src/models/proto/models/ProtoOALightSymbol.js +15 -0
  208. package/dist/src/models/proto/models/ProtoOALightSymbol.js.map +1 -0
  209. package/dist/src/models/proto/models/ProtoOASpotEvent.d.ts +11 -0
  210. package/dist/src/models/proto/models/ProtoOASpotEvent.d.ts.map +1 -0
  211. package/dist/src/models/proto/models/ProtoOASpotEvent.js +14 -0
  212. package/dist/src/models/proto/models/ProtoOASpotEvent.js.map +1 -0
  213. package/dist/src/models/proto/models/ProtoOASymbol.d.ts +44 -0
  214. package/dist/src/models/proto/models/ProtoOASymbol.d.ts.map +1 -0
  215. package/dist/src/models/proto/models/ProtoOASymbol.js +46 -0
  216. package/dist/src/models/proto/models/ProtoOASymbol.js.map +1 -0
  217. package/dist/src/models/proto/models/ProtoOATrendbar.d.ts +11 -0
  218. package/dist/src/models/proto/models/ProtoOATrendbar.d.ts.map +1 -0
  219. package/dist/src/models/proto/models/ProtoOATrendbar.js +14 -0
  220. package/dist/src/models/proto/models/ProtoOATrendbar.js.map +1 -0
  221. package/dist/src/models/proto/models/ProtoOATrendbarPeriod.d.ts +17 -0
  222. package/dist/src/models/proto/models/ProtoOATrendbarPeriod.d.ts.map +1 -0
  223. package/dist/src/models/proto/models/ProtoOATrendbarPeriod.js +21 -0
  224. package/dist/src/models/proto/models/ProtoOATrendbarPeriod.js.map +1 -0
  225. package/dist/src/models/proto/payload-types/payload-types.enum.d.ts +78 -0
  226. package/dist/src/models/proto/payload-types/payload-types.enum.d.ts.map +1 -0
  227. package/dist/src/models/proto/payload-types/payload-types.enum.js +82 -0
  228. package/dist/src/models/proto/payload-types/payload-types.enum.js.map +1 -0
  229. package/dist/src/utils/price.utils.d.ts +4 -0
  230. package/dist/src/utils/price.utils.d.ts.map +1 -0
  231. package/dist/src/utils/price.utils.js +36 -0
  232. package/dist/src/utils/price.utils.js.map +1 -0
  233. package/dist/src/utils/sleep.utils.d.ts +5 -0
  234. package/dist/src/utils/sleep.utils.d.ts.map +1 -0
  235. package/dist/src/utils/sleep.utils.js +15 -0
  236. package/dist/src/utils/sleep.utils.js.map +1 -0
  237. package/dist/src/utils/timeframe.utils.d.ts +6 -0
  238. package/dist/src/utils/timeframe.utils.d.ts.map +1 -0
  239. package/dist/src/utils/timeframe.utils.js +47 -0
  240. package/dist/src/utils/timeframe.utils.js.map +1 -0
  241. package/dist/src/utils/trendbar.utils.d.ts +7 -0
  242. package/dist/src/utils/trendbar.utils.d.ts.map +1 -0
  243. package/dist/src/utils/trendbar.utils.js +28 -0
  244. package/dist/src/utils/trendbar.utils.js.map +1 -0
  245. package/dist/tsconfig.tsbuildinfo +1 -0
  246. package/dist/vitest.config.d.ts +3 -0
  247. package/dist/vitest.config.d.ts.map +1 -0
  248. package/dist/vitest.config.js +12 -0
  249. package/dist/vitest.config.js.map +1 -0
  250. package/package.json +48 -0
  251. package/src/classes/client.test.ts +100 -0
  252. package/src/classes/client.ts +102 -0
  253. package/src/classes/errors/client-not-connected.error.ts +7 -0
  254. package/src/classes/errors/connection.error.ts +7 -0
  255. package/src/classes/logger.ts +26 -0
  256. package/src/classes/managers/authentication/authentication.manager.test.ts +187 -0
  257. package/src/classes/managers/authentication/authentication.manager.ts +65 -0
  258. package/src/classes/managers/authentication/errors/application-auth.error.ts +9 -0
  259. package/src/classes/managers/authentication/errors/user-auth.error.ts +9 -0
  260. package/src/classes/managers/models/base.manager.ts +50 -0
  261. package/src/classes/managers/models/credentials.model.ts +15 -0
  262. package/src/classes/managers/symbols/errors/get-symbols-details.error.ts +9 -0
  263. package/src/classes/managers/symbols/errors/get-symbols-list.error.ts +9 -0
  264. package/src/classes/managers/symbols/errors/get-trend-bars.error.ts +7 -0
  265. package/src/classes/managers/symbols/errors/subscribe-live-trend-bars.error.ts +17 -0
  266. package/src/classes/managers/symbols/errors/subscribe-spot-events.error.ts +9 -0
  267. package/src/classes/managers/symbols/errors/unsubscribe-live-trend-bars.error.ts +9 -0
  268. package/src/classes/managers/symbols/symbols-updates.manager.ts +440 -0
  269. package/src/classes/managers/symbols/symbols.manager.test.ts +455 -0
  270. package/src/classes/managers/symbols/symbols.manager.ts +134 -0
  271. package/src/classes/models/client-configuration.model.ts +39 -0
  272. package/src/classes/models/ctrader-x-error.model.ts +16 -0
  273. package/src/config/config.ts +48 -0
  274. package/src/index.ts +4 -0
  275. package/src/models/common/ohlcv.ts +19 -0
  276. package/src/models/proto/base-proto.ts +13 -0
  277. package/src/models/proto/messages/authentication/ProtoOAAccountAuthReq.ts +8 -0
  278. package/src/models/proto/messages/authentication/ProtoOAAccountAuthRes.ts +3 -0
  279. package/src/models/proto/messages/authentication/ProtoOAApplicationAuthReq.ts +13 -0
  280. package/src/models/proto/messages/authentication/ProtoOAApplicationAuthRes.ts +3 -0
  281. package/src/models/proto/messages/common/ProtoOASubscribeSpotsReq.ts +6 -0
  282. package/src/models/proto/messages/common/ProtoOASubscribeSpotsRes.ts +3 -0
  283. package/src/models/proto/messages/symbols/ProtoOAGetTrendbarsReq.ts +29 -0
  284. package/src/models/proto/messages/symbols/ProtoOAGetTrendbarsRes.ts +30 -0
  285. package/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarReq.ts +7 -0
  286. package/src/models/proto/messages/symbols/ProtoOASubscribeLiveTrendbarRes.ts +3 -0
  287. package/src/models/proto/messages/symbols/ProtoOASymbolByIdReq.ts +8 -0
  288. package/src/models/proto/messages/symbols/ProtoOASymbolByIdRes.ts +15 -0
  289. package/src/models/proto/messages/symbols/ProtoOASymbolsListReq.ts +8 -0
  290. package/src/models/proto/messages/symbols/ProtoOASymbolsListRes.ts +14 -0
  291. package/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarReq.ts +11 -0
  292. package/src/models/proto/messages/symbols/ProtoOAUnsubscribeLiveTrendbarRes.ts +3 -0
  293. package/src/models/proto/models/ProtoOAArchivedSymbol.ts +21 -0
  294. package/src/models/proto/models/ProtoOAErrorRes.ts +20 -0
  295. package/src/models/proto/models/ProtoOAHoliday.ts +31 -0
  296. package/src/models/proto/models/ProtoOAInterval.ts +16 -0
  297. package/src/models/proto/models/ProtoOALightSymbol.ts +38 -0
  298. package/src/models/proto/models/ProtoOASpotEvent.ts +31 -0
  299. package/src/models/proto/models/ProtoOASymbol.ts +220 -0
  300. package/src/models/proto/models/ProtoOATrendbar.ts +11 -0
  301. package/src/models/proto/models/ProtoOATrendbarPeriod.ts +16 -0
  302. package/src/models/proto/payload-types/payload-types.enum.ts +77 -0
  303. package/src/utils/price.utils.ts +42 -0
  304. package/src/utils/sleep.utils.ts +13 -0
  305. package/src/utils/timeframe.utils.ts +50 -0
  306. package/src/utils/trendbar.utils.ts +59 -0
  307. package/tsconfig.tsbuildinfo +1 -0
  308. package/vitest.config.ts +11 -0
@@ -0,0 +1,455 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { ProtoOASymbolsListReq } from '../../../models/proto/messages/symbols/ProtoOASymbolsListReq';
3
+ import { ProtoOASymbolsListRes } from '../../../models/proto/messages/symbols/ProtoOASymbolsListRes';
4
+ import { ProtoOASymbolByIdReq } from '../../../models/proto/messages/symbols/ProtoOASymbolByIdReq';
5
+ import { ProtoOASymbolByIdRes } from '../../../models/proto/messages/symbols/ProtoOASymbolByIdRes';
6
+ import { ProtoOAGetTrendbarsReq } from '../../../models/proto/messages/symbols/ProtoOAGetTrendbarsReq';
7
+ import { ProtoOAGetTrendbarsRes } from '../../../models/proto/messages/symbols/ProtoOAGetTrendbarsRes';
8
+ import { GetSymbolsListError } from './errors/get-symbols-list.error';
9
+ import { GetSymbolsDetailsError } from './errors/get-symbols-details.error';
10
+ import { GetTrendBarsError } from './errors/get-trend-bars.error';
11
+ import { SymbolsManager } from './symbols.manager';
12
+ import { OHLCVPositions } from '../../../models/common/ohlcv';
13
+
14
+ describe('SymbolsManager - Unit Tests', () => {
15
+ let symbolsManager: SymbolsManager;
16
+ let mockConnection: any;
17
+ let mockLogger: any;
18
+ let mockCredentials: any;
19
+
20
+ beforeEach(() => {
21
+ mockConnection = {
22
+ sendCommand: vi.fn(),
23
+ on: vi.fn(),
24
+ };
25
+
26
+ mockLogger = {
27
+ debug: vi.fn(),
28
+ error: vi.fn(),
29
+ };
30
+
31
+ mockCredentials = {
32
+ clientId: 'test-client-id',
33
+ clientSecret: 'test-client-secret',
34
+ accessToken: 'test-access-token',
35
+ ctidTraderAccountId: 12345,
36
+ };
37
+
38
+ symbolsManager = new SymbolsManager(
39
+ mockCredentials,
40
+ mockConnection,
41
+ mockLogger,
42
+ );
43
+ });
44
+
45
+ describe('getSymbolsList', () => {
46
+ it('should return full symbols list successfully', async () => {
47
+ const mockSymbolsListResponse: ProtoOASymbolsListRes = {
48
+ ctidTraderAccountId: 12345,
49
+ symbol: [
50
+ {
51
+ symbolId: 1,
52
+ symbolName: 'EURUSD',
53
+ enabled: true,
54
+ baseAssetId: 10,
55
+ quoteAssetId: 11,
56
+ },
57
+ {
58
+ symbolId: 2,
59
+ symbolName: 'GBPUSD',
60
+ enabled: true,
61
+ baseAssetId: 12,
62
+ quoteAssetId: 11,
63
+ },
64
+ ],
65
+ archivedSymbol: [],
66
+ };
67
+
68
+ const mockSymbolDetailsResponse: ProtoOASymbolByIdRes = {
69
+ ctidTraderAccountId: 12345,
70
+ archivedSymbol: null!,
71
+ symbol: [
72
+ {
73
+ symbolId: 1,
74
+ digits: 5,
75
+ pipPosition: 4,
76
+ enableShortSelling: true,
77
+ guaranteedStopLoss: false,
78
+ swapLong: -1.5,
79
+ swapShort: 0.5,
80
+ maxVolume: 10000000,
81
+ minVolume: 1000,
82
+ stepVolume: 1000,
83
+ description: 'Euro vs US Dollar',
84
+ },
85
+ {
86
+ symbolId: 2,
87
+ digits: 5,
88
+ pipPosition: 4,
89
+ enableShortSelling: true,
90
+ guaranteedStopLoss: false,
91
+ swapLong: -2.0,
92
+ swapShort: 1.0,
93
+ maxVolume: 10000000,
94
+ minVolume: 1000,
95
+ stepVolume: 1000,
96
+ description: 'British Pound vs US Dollar',
97
+ },
98
+ ],
99
+ };
100
+
101
+ mockConnection.sendCommand
102
+ .mockResolvedValueOnce(mockSymbolsListResponse)
103
+ .mockResolvedValueOnce(mockSymbolDetailsResponse);
104
+
105
+ const result = await symbolsManager.getSymbolsList();
106
+
107
+ // Il risultato deve essere il merge tra ProtoOASymbol e ProtoOALightSymbol
108
+ const expected = [
109
+ {
110
+ symbolId: 1,
111
+ digits: 5,
112
+ pipPosition: 4,
113
+ enableShortSelling: true,
114
+ guaranteedStopLoss: false,
115
+ swapLong: -1.5,
116
+ swapShort: 0.5,
117
+ maxVolume: 10000000,
118
+ minVolume: 1000,
119
+ stepVolume: 1000,
120
+ description: 'Euro vs US Dollar',
121
+ symbolName: 'EURUSD',
122
+ enabled: true,
123
+ baseAssetId: 10,
124
+ quoteAssetId: 11,
125
+ },
126
+ {
127
+ symbolId: 2,
128
+ digits: 5,
129
+ pipPosition: 4,
130
+ enableShortSelling: true,
131
+ guaranteedStopLoss: false,
132
+ swapLong: -2.0,
133
+ swapShort: 1.0,
134
+ maxVolume: 10000000,
135
+ minVolume: 1000,
136
+ stepVolume: 1000,
137
+ description: 'British Pound vs US Dollar',
138
+ symbolName: 'GBPUSD',
139
+ enabled: true,
140
+ baseAssetId: 12,
141
+ quoteAssetId: 11,
142
+ },
143
+ ];
144
+
145
+ expect(result).toEqual(expected);
146
+ expect(mockConnection.sendCommand).toHaveBeenCalledTimes(2);
147
+ expect(mockConnection.sendCommand).toHaveBeenNthCalledWith(
148
+ 1,
149
+ ProtoOASymbolsListReq.name,
150
+ {
151
+ includeArchivedSymbols: undefined,
152
+ ctidTraderAccountId: 12345,
153
+ },
154
+ );
155
+ expect(mockConnection.sendCommand).toHaveBeenNthCalledWith(
156
+ 2,
157
+ ProtoOASymbolByIdReq.name,
158
+ {
159
+ symbolId: [1, 2],
160
+ ctidTraderAccountId: 12345,
161
+ },
162
+ );
163
+ });
164
+
165
+ it('should pass includeArchivedSymbols option correctly', async () => {
166
+ const mockSymbolsListResponse: ProtoOASymbolsListRes = {
167
+ ctidTraderAccountId: 12345,
168
+ symbol: [],
169
+ archivedSymbol: [
170
+ {
171
+ symbolId: 99,
172
+ symbolName: 'ARCHIVED',
173
+ enabled: false,
174
+ baseAssetId: 1,
175
+ quoteAssetId: 2,
176
+ },
177
+ ],
178
+ };
179
+
180
+ const mockSymbolDetailsResponse: ProtoOASymbolByIdRes = {
181
+ ctidTraderAccountId: 12345,
182
+ archivedSymbol: null!,
183
+ symbol: [],
184
+ };
185
+
186
+ mockConnection.sendCommand
187
+ .mockResolvedValueOnce(mockSymbolsListResponse)
188
+ .mockResolvedValueOnce(mockSymbolDetailsResponse);
189
+
190
+ await symbolsManager.getSymbolsList({
191
+ includeArchivedSymbols: true,
192
+ });
193
+
194
+ expect(mockConnection.sendCommand).toHaveBeenNthCalledWith(
195
+ 1,
196
+ ProtoOASymbolsListReq.name,
197
+ {
198
+ includeArchivedSymbols: true,
199
+ ctidTraderAccountId: 12345,
200
+ },
201
+ );
202
+ });
203
+
204
+ it('should throw GetSymbolsListError on symbols list failure', async () => {
205
+ mockConnection.sendCommand.mockRejectedValue(
206
+ new Error('Connection failed'),
207
+ );
208
+
209
+ await expect(symbolsManager.getSymbolsList()).rejects.toThrow(
210
+ GetSymbolsListError,
211
+ );
212
+
213
+ expect(mockLogger.error).toHaveBeenCalled();
214
+ });
215
+
216
+ it('should throw GetSymbolsDetailsError on symbols details failure', async () => {
217
+ const mockSymbolsListResponse: ProtoOASymbolsListRes = {
218
+ ctidTraderAccountId: 12345,
219
+ symbol: [
220
+ {
221
+ symbolId: 1,
222
+ symbolName: 'EURUSD',
223
+ enabled: true,
224
+ baseAssetId: 10,
225
+ quoteAssetId: 11,
226
+ },
227
+ ],
228
+ archivedSymbol: [],
229
+ };
230
+
231
+ mockConnection.sendCommand
232
+ .mockResolvedValueOnce(mockSymbolsListResponse)
233
+ .mockRejectedValueOnce(new Error('Details fetch failed'));
234
+
235
+ await expect(symbolsManager.getSymbolsList()).rejects.toThrow(
236
+ GetSymbolsDetailsError,
237
+ );
238
+
239
+ expect(mockLogger.error).toHaveBeenCalled();
240
+ });
241
+ });
242
+
243
+ describe('getSymbolsDetails', () => {
244
+ it('should return symbols details successfully', async () => {
245
+ const mockResponse: ProtoOASymbolByIdRes = {
246
+ ctidTraderAccountId: 12345,
247
+ archivedSymbol: null!,
248
+ symbol: [
249
+ {
250
+ symbolId: 1,
251
+ digits: 5,
252
+ pipPosition: 4,
253
+ enableShortSelling: true,
254
+ guaranteedStopLoss: false,
255
+ swapLong: -1.5,
256
+ swapShort: 0.5,
257
+ maxVolume: 10000000,
258
+ minVolume: 1000,
259
+ stepVolume: 1000,
260
+ description: 'Euro vs US Dollar',
261
+ },
262
+ ],
263
+ };
264
+
265
+ mockConnection.sendCommand.mockResolvedValue(mockResponse);
266
+
267
+ const result = await symbolsManager.getSymbolsDetails([1]);
268
+
269
+ expect(result).toEqual(mockResponse);
270
+ expect(mockConnection.sendCommand).toHaveBeenCalledWith(
271
+ ProtoOASymbolByIdReq.name,
272
+ {
273
+ symbolId: [1],
274
+ ctidTraderAccountId: 12345,
275
+ },
276
+ );
277
+ });
278
+
279
+ it('should handle multiple symbol IDs', async () => {
280
+ const mockResponse: ProtoOASymbolByIdRes = {
281
+ ctidTraderAccountId: 12345,
282
+ archivedSymbol: null!,
283
+ symbol: [
284
+ {
285
+ symbolId: 1,
286
+ digits: 5,
287
+ pipPosition: 4,
288
+ },
289
+ {
290
+ symbolId: 2,
291
+ digits: 5,
292
+ pipPosition: 4,
293
+ },
294
+ {
295
+ symbolId: 3,
296
+ digits: 3,
297
+ pipPosition: 2,
298
+ },
299
+ ],
300
+ };
301
+
302
+ mockConnection.sendCommand.mockResolvedValue(mockResponse);
303
+
304
+ const result = await symbolsManager.getSymbolsDetails([1, 2, 3]);
305
+
306
+ expect(result).toEqual(mockResponse);
307
+ expect(mockConnection.sendCommand).toHaveBeenCalledWith(
308
+ ProtoOASymbolByIdReq.name,
309
+ {
310
+ symbolId: [1, 2, 3],
311
+ ctidTraderAccountId: 12345,
312
+ },
313
+ );
314
+ });
315
+
316
+ it('should throw GetSymbolsDetailsError on failure', async () => {
317
+ mockConnection.sendCommand.mockRejectedValue(
318
+ new Error('Connection failed'),
319
+ );
320
+
321
+ await expect(
322
+ symbolsManager.getSymbolsDetails([1, 2]),
323
+ ).rejects.toThrow(GetSymbolsDetailsError);
324
+
325
+ expect(mockLogger.error).toHaveBeenCalled();
326
+ });
327
+ });
328
+
329
+ describe('getTrendBars', () => {
330
+ it('should return trend bars with converted timestamps', async () => {
331
+ const mockResponse: ProtoOAGetTrendbarsRes = {
332
+ ctidTraderAccountId: 12345,
333
+ period: null!,
334
+ trendbar: [
335
+ {
336
+ utcTimestampInMinutes: 29350000,
337
+ deltaOpen: 108500,
338
+ deltaHigh: 108600,
339
+ low: 108400,
340
+ deltaClose: 108550,
341
+ volume: 1000000,
342
+ },
343
+ ],
344
+ };
345
+
346
+ mockConnection.sendCommand.mockResolvedValue(mockResponse);
347
+ const _getSymbolsDetails =
348
+ symbolsManager.getSymbolsDetails.bind(symbolsManager);
349
+ symbolsManager.getSymbolsDetails = vi.fn().mockResolvedValue({
350
+ symbol: [
351
+ {
352
+ digits: 3,
353
+ },
354
+ ],
355
+ });
356
+
357
+ const opts = {
358
+ symbolId: 1,
359
+ period: 'M1' as any,
360
+ fromTimestamp: 1640000000000,
361
+ toTimestamp: 1640086400000,
362
+ };
363
+
364
+ const result = await symbolsManager.getTrendBars(opts);
365
+ symbolsManager.getSymbolsDetails = _getSymbolsDetails;
366
+
367
+ // Verify timestamps are converted (multiplied by 60000)
368
+ expect(result[0][OHLCVPositions.TIME]).toBe(29350000 * 60000);
369
+ expect(mockConnection.sendCommand).toHaveBeenCalledWith(
370
+ ProtoOAGetTrendbarsReq.name,
371
+ {
372
+ ...opts,
373
+ ctidTraderAccountId: 12345,
374
+ },
375
+ );
376
+ });
377
+
378
+ it('should convert all timestamps in multiple trend bars', async () => {
379
+ const mockResponse: ProtoOAGetTrendbarsRes = {
380
+ ctidTraderAccountId: 12345,
381
+ period: null!,
382
+ trendbar: [
383
+ {
384
+ utcTimestampInMinutes: 1000,
385
+ deltaOpen: 108500,
386
+ deltaHigh: 108600,
387
+ low: 108400,
388
+ deltaClose: 108550,
389
+ volume: 1000000,
390
+ },
391
+ {
392
+ utcTimestampInMinutes: 2000,
393
+ deltaOpen: 108600,
394
+ deltaHigh: 108700,
395
+ low: 108500,
396
+ deltaClose: 108650,
397
+ volume: 1500000,
398
+ },
399
+ {
400
+ utcTimestampInMinutes: 3000,
401
+ deltaOpen: 108650,
402
+ deltaHigh: 108750,
403
+ low: 108600,
404
+ deltaClose: 108700,
405
+ volume: 2000000,
406
+ },
407
+ ],
408
+ };
409
+
410
+ mockConnection.sendCommand.mockResolvedValue(mockResponse);
411
+ const _getSymbolsDetails =
412
+ symbolsManager.getSymbolsDetails.bind(symbolsManager);
413
+ symbolsManager.getSymbolsDetails = vi.fn().mockResolvedValue({
414
+ symbol: [
415
+ {
416
+ digits: 3,
417
+ },
418
+ ],
419
+ });
420
+
421
+ const opts = {
422
+ symbolId: 1,
423
+ period: 'M1' as any,
424
+ fromTimestamp: 1640000000000,
425
+ toTimestamp: 1640086400000,
426
+ };
427
+
428
+ const result = await symbolsManager.getTrendBars(opts);
429
+ symbolsManager.getSymbolsDetails = _getSymbolsDetails;
430
+
431
+ expect(result[0][OHLCVPositions.TIME]).toBe(1000 * 60000);
432
+ expect(result[1][OHLCVPositions.TIME]).toBe(2000 * 60000);
433
+ expect(result[2][OHLCVPositions.TIME]).toBe(3000 * 60000);
434
+ });
435
+
436
+ it('should throw GetTrendBarsError on failure', async () => {
437
+ mockConnection.sendCommand.mockRejectedValue(
438
+ new Error('Connection failed'),
439
+ );
440
+
441
+ const opts = {
442
+ symbolId: 1,
443
+ period: 'M1' as any,
444
+ fromTimestamp: 1640000000000,
445
+ toTimestamp: 1640086400000,
446
+ };
447
+
448
+ await expect(symbolsManager.getTrendBars(opts)).rejects.toThrow(
449
+ GetTrendBarsError,
450
+ );
451
+
452
+ expect(mockLogger.error).toHaveBeenCalled();
453
+ });
454
+ });
455
+ });
@@ -0,0 +1,134 @@
1
+ import { CTraderConnection } from '@reiryoku/ctrader-layer';
2
+ import { ILogger } from '../../logger';
3
+ import { BaseManager } from '../models/base.manager';
4
+ import { ProtoOASymbolsListReq } from '../../../models/proto/messages/symbols/ProtoOASymbolsListReq';
5
+ import { ICredentials } from '../models/credentials.model';
6
+ import { ProtoOASymbolsListRes } from '../../../models/proto/messages/symbols/ProtoOASymbolsListRes';
7
+ import { GetSymbolsListError } from './errors/get-symbols-list.error';
8
+ import { ProtoOAGetTrendbarsRes } from '../../../models/proto/messages/symbols/ProtoOAGetTrendbarsRes';
9
+ import { ProtoOAGetTrendbarsReq } from '../../../models/proto/messages/symbols/ProtoOAGetTrendbarsReq';
10
+ import { GetTrendBarsError } from './errors/get-trend-bars.error';
11
+ import { ProtoOASymbolByIdRes } from '../../../models/proto/messages/symbols/ProtoOASymbolByIdRes';
12
+ import { ProtoOASymbolByIdReq } from '../../../models/proto/messages/symbols/ProtoOASymbolByIdReq';
13
+ import { GetSymbolsDetailsError } from './errors/get-symbols-details.error';
14
+ import { ProtoOASymbol } from '../../../models/proto/models/ProtoOASymbol';
15
+ import { ProtoOALightSymbol } from '../../../models/proto/models/ProtoOALightSymbol';
16
+ import { TrendBarUtils } from '../../../utils/trendbar.utils';
17
+ import { OHLCV } from '../../../models/common/ohlcv';
18
+ import { ProtoOATrendbarPeriod } from '../../../models/proto/models/ProtoOATrendbarPeriod';
19
+
20
+ export interface IGetSymbolsListOptions {
21
+ includeArchivedSymbols?: boolean;
22
+ }
23
+
24
+ export type GetSymbolsListResult = (ProtoOASymbol & ProtoOALightSymbol)[];
25
+
26
+ export interface SubscribeLiveTrendBarsEvent {
27
+ symbolId: number;
28
+ ohlcv: OHLCV;
29
+ lastBarTime: number;
30
+ period: ProtoOATrendbarPeriod;
31
+ }
32
+
33
+ export class SymbolsManager extends BaseManager {
34
+ constructor(
35
+ protected readonly credentials: ICredentials,
36
+ protected readonly connection: CTraderConnection,
37
+ protected readonly logger: ILogger,
38
+ ) {
39
+ super();
40
+ }
41
+
42
+ async getSymbolsList(
43
+ opts?: IGetSymbolsListOptions,
44
+ ): Promise<GetSymbolsListResult> {
45
+ this.logCallAttempt(this.getSymbolsList);
46
+
47
+ const payload: ProtoOASymbolsListReq = {
48
+ includeArchivedSymbols: opts?.includeArchivedSymbols,
49
+ ctidTraderAccountId: this.credentials.ctidTraderAccountId,
50
+ };
51
+
52
+ let result: ProtoOASymbolsListRes;
53
+ try {
54
+ result = (await this.connection.sendCommand(
55
+ ProtoOASymbolsListReq.name,
56
+ payload,
57
+ )) as ProtoOASymbolsListRes;
58
+ } catch (e) {
59
+ throw this.handleCTraderCallError(
60
+ e,
61
+ this.getSymbolsList,
62
+ new GetSymbolsListError(e),
63
+ );
64
+ }
65
+
66
+ this.logCallAttemptSuccess(this.getSymbolsList);
67
+
68
+ const fullSymbols = await this.getSymbolsDetails(
69
+ result.symbol.map(({ symbolId }) => +symbolId),
70
+ );
71
+
72
+ return fullSymbols.symbol.map((symbol) => ({
73
+ ...symbol,
74
+ ...result.symbol.find((s) => s.symbolId === symbol.symbolId),
75
+ }));
76
+ }
77
+
78
+ async getSymbolsDetails(
79
+ symbolsIds: number[],
80
+ ): Promise<ProtoOASymbolByIdRes> {
81
+ this.logCallAttempt(this.getSymbolsDetails);
82
+
83
+ const payload: ProtoOASymbolByIdReq = {
84
+ symbolId: symbolsIds,
85
+ ctidTraderAccountId: this.credentials.ctidTraderAccountId,
86
+ };
87
+
88
+ let result: ProtoOASymbolByIdRes;
89
+ try {
90
+ result = (await this.connection.sendCommand(
91
+ ProtoOASymbolByIdReq.name,
92
+ payload,
93
+ )) as ProtoOASymbolByIdRes;
94
+ } catch (e) {
95
+ throw this.handleCTraderCallError(
96
+ e,
97
+ this.getSymbolsDetails,
98
+ new GetSymbolsDetailsError(e),
99
+ );
100
+ }
101
+
102
+ this.logCallAttemptSuccess(this.getSymbolsDetails);
103
+ return result;
104
+ }
105
+
106
+ async getTrendBars(
107
+ opts: Omit<ProtoOAGetTrendbarsReq, 'ctidTraderAccountId'>,
108
+ ): Promise<OHLCV[]> {
109
+ this.logCallAttempt(this.getTrendBars);
110
+ let result: ProtoOAGetTrendbarsRes;
111
+ try {
112
+ const payload: ProtoOAGetTrendbarsReq = {
113
+ ...opts,
114
+ ctidTraderAccountId: this.credentials.ctidTraderAccountId,
115
+ };
116
+ result = (await this.connection.sendCommand(
117
+ ProtoOAGetTrendbarsReq.name,
118
+ payload,
119
+ )) as ProtoOAGetTrendbarsRes;
120
+ } catch (e) {
121
+ throw this.handleCTraderCallError(
122
+ e,
123
+ this.getTrendBars,
124
+ new GetTrendBarsError(e),
125
+ );
126
+ }
127
+
128
+ this.logCallAttemptSuccess(this.getTrendBars);
129
+
130
+ const symbolInfo = await this.getSymbolsDetails([opts.symbolId]);
131
+ const precision = +symbolInfo.symbol[0].digits;
132
+ return TrendBarUtils.mapTrendbarsToOHLCV(result.trendbar, precision);
133
+ }
134
+ }
@@ -0,0 +1,39 @@
1
+ import { ILogger } from '../logger';
2
+
3
+ export interface IConfiguration {
4
+ /**
5
+ * Will connect to the live API instead of the demo API
6
+ * By default the demo API is used.
7
+ */
8
+ live?: boolean;
9
+
10
+ /**
11
+ * The Spotware client id.
12
+ * If not specified will attempt loading from env
13
+ */
14
+ clientId?: string;
15
+
16
+ /**
17
+ * The Spotware client secret.
18
+ * If not specified will attempt loading from env
19
+ */
20
+ clientSecret?: string;
21
+
22
+ /**
23
+ * The Spotware access token.
24
+ * If not specified will attempt loading from env
25
+ */
26
+ accessToken?: string;
27
+
28
+ /**
29
+ * The Spotware ctid trader account id.
30
+ * In the sandbox environment can be found under the Trading accounts tab
31
+ * If not specified will attempt loading from env
32
+ */
33
+ ctidTraderAccountId?: number;
34
+
35
+ /**
36
+ * Custom logger implementation
37
+ */
38
+ logger?: ILogger;
39
+ }
@@ -0,0 +1,16 @@
1
+ import { ProtoOAErrorRes } from '../../models/proto/models/ProtoOAErrorRes';
2
+
3
+ export class cTraderXError extends Error {
4
+ static getMessageError(error: unknown): string {
5
+ if (this.isProtoOAErrorRes(error))
6
+ return `${error.errorCode} --> ${error.description} (RetryAfter: ${error.retryAfter} MaintenanceEnd: ${error.maintenanceEndTimestamp})`;
7
+ if (error instanceof Error) return error.message || error.name;
8
+ if (typeof error === 'string') return error;
9
+ return JSON.stringify(error);
10
+ }
11
+
12
+ static isProtoOAErrorRes(error: any): error is ProtoOAErrorRes {
13
+ if (error.payloadType && error.errorCode) return true;
14
+ return false;
15
+ }
16
+ }
@@ -0,0 +1,48 @@
1
+ import * as dotenv from 'dotenv';
2
+ import * as process from 'node:process';
3
+
4
+ dotenv.config({ override: true });
5
+
6
+ export class Config {
7
+ static get SPOTWARE_CTID_TRADER_ACCOUNT_ID() {
8
+ this.ensureConfigExistenceOrThrow(
9
+ 'CTRADERX_SPOTWARE_CTID_TRADER_ACCOUNT_ID',
10
+ );
11
+ const value = this.getConfig(
12
+ 'CTRADERX_SPOTWARE_CTID_TRADER_ACCOUNT_ID',
13
+ );
14
+ if (!!value && !isNaN(+value)) return +value;
15
+ throw new Error(
16
+ `Invalid CTRADERX_SPOTWARE_CTID_TRADER_ACCOUNT_ID. Should be a number`,
17
+ );
18
+ }
19
+
20
+ static get SPOTWARE_ACCESS_TOKEN() {
21
+ this.ensureConfigExistenceOrThrow('CTRADERX_SPOTWARE_ACCESS_TOKEN');
22
+ return this.getConfig('CTRADERX_SPOTWARE_ACCESS_TOKEN');
23
+ }
24
+
25
+ static get SPOTWARE_CLIENT_SECRET() {
26
+ this.ensureConfigExistenceOrThrow('CTRADERX_SPOTWARE_CLIENT_SECRET');
27
+ return this.getConfig('CTRADERX_SPOTWARE_CLIENT_SECRET');
28
+ }
29
+
30
+ static get SPOTWARE_CLIENT_ID() {
31
+ this.ensureConfigExistenceOrThrow('CTRADERX_SPOTWARE_CLIENT_ID');
32
+ return this.getConfig('CTRADERX_SPOTWARE_CLIENT_ID');
33
+ }
34
+
35
+ static get DEBUG_LOGS() {
36
+ this.ensureConfigExistenceOrThrow('CTRADERX_DEBUG_LOGS');
37
+ return this.getConfig('CTRADERX_DEBUG_LOGS') === 'true';
38
+ }
39
+
40
+ private static ensureConfigExistenceOrThrow(config: string): void {
41
+ if (!process.env[config])
42
+ throw new Error(`Missing env config ${config}. Please provide it`);
43
+ }
44
+
45
+ private static getConfig(config: string): string {
46
+ return process.env[config]!;
47
+ }
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './classes/client';
2
+ export * from './classes/logger';
3
+
4
+ export * from './utils/trendbar.utils';