strategy-tools 1.0.0 → 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.
@@ -1,4 +1,4 @@
1
- import { ExternalApiConnection, StandardKeyGroup } from "itrm-tools";
1
+ import { ApiResponse, ExternalApiConnection, StandardKeyGroup } from "itrm-tools";
2
2
  export interface CetusStrategy {
3
3
  id: number;
4
4
  name: string;
@@ -15,6 +15,19 @@ export declare enum StrategyStatus {
15
15
  SELL_ONLY = "SELL_ONLY",
16
16
  STOPPED = "STOPPED"
17
17
  }
18
+ export interface StrategyRate {
19
+ symbol: string;
20
+ source: string;
21
+ date: string;
22
+ bid?: string;
23
+ ask?: string;
24
+ prevDayClose?: string;
25
+ spot?: {
26
+ time: string;
27
+ price: string;
28
+ volume: string;
29
+ };
30
+ }
18
31
  export declare class CetusStrategyApiConnection extends ExternalApiConnection {
19
32
  constructor(apiUrl: string, keys: StandardKeyGroup);
20
33
  getStrategies(params: {
@@ -22,4 +35,6 @@ export declare class CetusStrategyApiConnection extends ExternalApiConnection {
22
35
  pair: string;
23
36
  account: string;
24
37
  }): Promise<CetusStrategy[]>;
38
+ saveMemory(strategy: CetusStrategy): Promise<ApiResponse<null>>;
39
+ getRates(): Promise<StrategyRate[]>;
25
40
  }
@@ -9,6 +9,7 @@ var StrategyStatus;
9
9
  StrategyStatus["SELL_ONLY"] = "SELL_ONLY";
10
10
  StrategyStatus["STOPPED"] = "STOPPED";
11
11
  })(StrategyStatus || (exports.StrategyStatus = StrategyStatus = {}));
12
+ ;
12
13
  class CetusStrategyApiConnection extends itrm_tools_1.ExternalApiConnection {
13
14
  constructor(apiUrl, keys) {
14
15
  super("cetus", apiUrl, keys);
@@ -17,6 +18,12 @@ class CetusStrategyApiConnection extends itrm_tools_1.ExternalApiConnection {
17
18
  const queryString = new URLSearchParams(params).toString();
18
19
  return this.request(itrm_tools_1.RequestMethod.GET, `/v1/strategies?${queryString}`);
19
20
  }
21
+ async saveMemory(strategy) {
22
+ return this.request(itrm_tools_1.RequestMethod.PUT, `/v1/strategies/${strategy.id}`, { memory: strategy.memory });
23
+ }
24
+ async getRates() {
25
+ return this.request(itrm_tools_1.RequestMethod.GET, `/v1/rates`);
26
+ }
20
27
  }
21
28
  exports.CetusStrategyApiConnection = CetusStrategyApiConnection;
22
29
  //# sourceMappingURL=CetusStrategyApiConnection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CetusStrategyApiConnection.js","sourceRoot":"","sources":["../../src/cetus/CetusStrategyApiConnection.ts"],"names":[],"mappings":";;;AAAA,2CAAoF;AAapF,IAAY,cAKX;AALD,WAAY,cAAc;IACtB,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;AACvB,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;AAED,MAAa,0BAA2B,SAAQ,kCAAqB;IACjE,YAAY,MAAc,EAAE,IAAsB;QAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAuD;QAC9E,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC,OAAO,CAAkB,0BAAa,CAAC,GAAG,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAC;IAC7F,CAAC;CACJ;AATD,gEASC"}
1
+ {"version":3,"file":"CetusStrategyApiConnection.js","sourceRoot":"","sources":["../../src/cetus/CetusStrategyApiConnection.ts"],"names":[],"mappings":";;;AAAA,2CAAiG;AAajG,IAAY,cAKX;AALD,WAAY,cAAc;IACtB,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;IACrB,yCAAuB,CAAA;IACvB,qCAAmB,CAAA;AACvB,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;AAcA,CAAC;AAEF,MAAa,0BAA2B,SAAQ,kCAAqB;IACjE,YAAY,MAAc,EAAE,IAAsB;QAC9C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAuD;QAC9E,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAa,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClE,OAAO,IAAI,CAAC,OAAO,CAAkB,0BAAa,CAAC,GAAG,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAC;IAC7F,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,QAAuB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAc,0BAAa,CAAC,GAAG,EAAE,kBAAkB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACtH,CAAC;IAEM,KAAK,CAAC,QAAQ;QACjB,OAAO,IAAI,CAAC,OAAO,CAAiB,0BAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACxE,CAAC;CACJ;AAjBD,gEAiBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strategy-tools",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Librería para el desarrollo de estrategias de Cetus",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { ExternalApiConnection, RequestMethod, StandardKeyGroup } from "itrm-tools";
1
+ import { ApiResponse, ExternalApiConnection, RequestMethod, StandardKeyGroup } from "itrm-tools";
2
2
 
3
3
  export interface CetusStrategy {
4
4
  id: number;
@@ -18,6 +18,20 @@ export enum StrategyStatus {
18
18
  STOPPED = "STOPPED"
19
19
  }
20
20
 
21
+ export interface StrategyRate {
22
+ symbol: string;
23
+ source: string;
24
+ date: string;
25
+ bid?: string;
26
+ ask?: string;
27
+ prevDayClose?: string;
28
+ spot?: {
29
+ time: string;
30
+ price: string;
31
+ volume: string;
32
+ };
33
+ };
34
+
21
35
  export class CetusStrategyApiConnection extends ExternalApiConnection {
22
36
  constructor(apiUrl: string, keys: StandardKeyGroup) {
23
37
  super("cetus", apiUrl, keys);
@@ -27,4 +41,12 @@ export class CetusStrategyApiConnection extends ExternalApiConnection {
27
41
  const queryString = new URLSearchParams(params as any).toString();
28
42
  return this.request<CetusStrategy[]>(RequestMethod.GET, `/v1/strategies?${queryString}`);
29
43
  }
44
+
45
+ public async saveMemory(strategy: CetusStrategy) {
46
+ return this.request<ApiResponse>(RequestMethod.PUT, `/v1/strategies/${strategy.id}`, { memory: strategy.memory });
47
+ }
48
+
49
+ public async getRates() {
50
+ return this.request<StrategyRate[]>(RequestMethod.GET, `/v1/rates`);
51
+ }
30
52
  }
@@ -1,27 +1,39 @@
1
1
  import { CetusStrategy, CetusStrategyApiConnection } from "../../dist";
2
2
 
3
- const API_URL = "https://api.cetus.mcvc.ai";
3
+ const API_URL = "http://localhost:8309";
4
4
  const PUBLIC_KEY = "24df533e3b1ffa697bb98201ca7eeb9c6a25b0d5322b3817280fd78ac61f499b";
5
5
  const SECRET_KEY = "WFCbWEDq4hJLrVjYZAOVWZlZou+Wly6Zpn9IR1DCoQzG4uireyxuYbqZeIj1JmLbbehzth+wIXU0Trve54fI1Q==";
6
6
  const SIGN_KEY = "EYox9cKS3ZPk5KC6zGXYrxjOS9g5S21ik7CHcKtuip6cuhtsNYKM6kSrWH5R7d4qGTB07M/S1V7QC9G6VHyJRA==";
7
7
 
8
+ const STRATEGY_SEARCH = { name: "CMA Streamer", pair: "USDCOP", account: "CETUS" };
9
+
8
10
  describe('testing Binance Signer', () => {
9
11
  const connection = new CetusStrategyApiConnection(API_URL, { publicKey: PUBLIC_KEY, secretKey: SECRET_KEY, signKey: SIGN_KEY });
10
- var strategy: CetusStrategy;
11
12
  test("> test GET Strategies", async () => {
12
- try {
13
- let strategies = await connection.getStrategies({ name: "CMA Streamer", pair: "USDCOP", account: "CETUS" });
13
+ let strategies = await connection.getStrategies(STRATEGY_SEARCH);
14
14
  for (let strategy of strategies) {
15
- console.log("> strategy:", strategy);
16
15
  expect(strategy.id).toBeGreaterThan(0);
17
16
  expect(strategy.name).toBe("CMA Streamer");
18
17
  expect(strategy.account).toBe("CETUS");
19
18
  expect(strategy.pair).toBe("USDCOP");
20
19
  }
21
- strategy = strategies[0];
22
- } catch (err: any) { console.log("> err:", err.response); }
23
20
  });
24
- /*test("> test PUT strategies", async () => {
25
-
26
- });*/
21
+ test("> test PUT strategies", async () => {
22
+ let strategy = (await connection.getStrategies(STRATEGY_SEARCH))[0];
23
+ expect(strategy).toBeDefined();
24
+ if (strategy) {
25
+ strategy.memory.rand = Math.random();
26
+ console.log("> strategy:", strategy);
27
+ let response = await connection.saveMemory(strategy);
28
+ expect(response.success).toBeTruthy();
29
+ let modifiedStrategy = (await connection.getStrategies(STRATEGY_SEARCH))[0];
30
+ expect(modifiedStrategy.memory.rand).toBe(strategy.memory.rand);
31
+ }
32
+ }, 15000);
33
+ test("> test GET rates", async () => {
34
+ let rates = await connection.getRates();
35
+ for (let rate of rates) {
36
+ expect(rate).toBeDefined();
37
+ }
38
+ });
27
39
  });