Skip to content

Commit 689322b

Browse files
authored
Merge pull request #20 from CAFECA-IO/feature/aiTrade
Feature/ai trade
2 parents b7a3fe3 + 6739146 commit 689322b

20 files changed

+453
-159
lines changed

.github/workflows/autotrade.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
node-version: 18
2323
- name: Install dependencies
24-
run: npm ci
24+
run: npm i
2525
- name: Build nestjs app
2626
run: npm run build
2727
- name: Run tests

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ lerna-debug.log*
3434
!.vscode/launch.json
3535
!.vscode/extensions.json
3636
request.http
37-
package-lock.json
37+
38+
# package-lock.json
39+
package-lock.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Parameters
176176

177177
```typescript
178178

179-
PUT /tradebot?id=tradebotId
179+
GET /tradebot?id=tradebotId
180180

181181
```
182182

dqn/model.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

dqn/weights.bin

-193 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auto-trade",
3-
"version": "0.0.1+1",
3+
"version": "0.0.1+2",
44
"description": "",
55
"author": "",
66
"private": true,

src/price_ticker/price_ticker.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ import { PriceTickerService } from './price_ticker.service';
44
@Controller('price-ticker')
55
export class PriceTickerController {
66
constructor(private readonly priceTickerService: PriceTickerService) {}
7-
87
}

src/price_ticker/price_ticker.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class PriceTickerService {
4646
async getCandlesticks(
4747
instId: string = 'ETH-USDT',
4848
timeSpan: string = '5m',
49-
limit: number = 300,
49+
limit: number = 100,
5050
): Promise<number[]> {
5151
const { data } = await firstValueFrom(
5252
this.httpService.get<CandlestickDto>(

src/strategies/strategies.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class StrategiesController {
77

88
@Get()
99
async trainDqn() {
10-
this.strategiesService.trainDqn();
10+
await this.strategiesService.trainDqn();
11+
return 'Training DQN finished';
1112
}
1213
}

src/strategies/strategies.service.spec.ts

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,58 +116,22 @@ describe('StrategiesService', () => {
116116
// Info: (20240320 - Jacky) this is aim to sum the profit of all trades
117117
const profitArray = tradeArray.map((trade) => trade.profit);
118118
const sum = profitArray.reduce((total, profit) => total + profit, 0);
119-
expect(sum).toBe(-1069.9531315100012);
119+
expect(sum).toBe(-1060.9868554650009);
120120
});
121121

122122
it('should backtest use api', async () => {
123123
console.log = () => {};
124-
const ETHPriceArray = [
125-
3250.92, 3227.38, 3264, 3252.43, 3277.55, 3264.01, 3280.58, 3260.4,
126-
3258.96, 3275.94, 3292.73, 3281.7, 3273.62, 3259.7, 3222.2, 3228.48,
127-
3225.21, 3229.59, 3228, 3230.22, 3245.07, 3244.62, 3227.1, 3213.34,
128-
3205.78, 3218.81, 3212.59, 3216.6, 3243.82, 3254.6, 3260.18, 3276.6,
129-
3273.45, 3276.47, 3270, 3289.41, 3278.61, 3257.55, 3272.34, 3264.35,
130-
3278.03, 3292.56, 3303.6, 3295.36, 3305.09, 3295.91, 3282.62, 3279.36,
131-
3279.6, 3273.79, 3296.25, 3306.6, 3285.4, 3295.09, 3279.6, 3272.93,
132-
3277.75, 3292.59, 3260, 3242.66, 3241.78, 3237.8, 3222.6, 3234.3, 3238.34,
133-
3252.28, 3267.21, 3264.54, 3258.5, 3259.2, 3250.44, 3248.98, 3235.4,
134-
3245.99, 3257.86, 3251.08, 3277.35, 3295.41, 3312.28, 3323.59, 3308.63,
135-
3302.98, 3306.66, 3317.32, 3303.59, 3299.27, 3296.26, 3299, 3302.28,
136-
3315.59, 3324.42, 3323.63, 3332.26, 3327.73, 3338.18, 3332.01, 3341.54,
137-
3335.91, 3342.99, 3350.09, 3331.74, 3322.51, 3317.57, 3312.87, 3312.96,
138-
3314.18, 3307.64, 3295.61, 3287, 3304.74, 3301.41, 3306.23, 3311.47,
139-
3312.52, 3329.5, 3314.01, 3312.61, 3316.38, 3306.79, 3329.9, 3332.61,
140-
3342.5, 3356, 3344.52, 3334.21, 3342.99, 3339.01, 3332.32, 3327.49,
141-
3333.23, 3312.47, 3297.72, 3297.61, 3287.31, 3272.79, 3276.98, 3293.86,
142-
3295.18, 3278.81, 3291.58, 3279.67, 3279.21, 3283.9, 3272.82, 3275.05,
143-
3282.55, 3262.38, 3273.59, 3273.32, 3280.56, 3284.08, 3298.75, 3294.55,
144-
3291.02, 3285.03, 3278.96, 3252.62, 3246.18, 3233.95, 3226.14, 3243.15,
145-
3229.47, 3211.81, 3216.67, 3201.42, 3211.38, 3184.59, 3177.5, 3170.81,
146-
3174.33, 3155.81, 3159.2, 3173.39, 3162.93, 3162.81, 3175.59, 3163.63,
147-
3158.4, 3158.05, 3173.82, 3168.86, 3193.39, 3201.67, 3206.98, 3199.53,
148-
3213.39, 3215.19, 3213.22, 3220.43, 3235.22, 3220.58, 3212.89, 3211.78,
149-
3188.78, 3168.61, 3188.41, 3174.71, 3175.2, 3164.39, 3179.45, 3187.09,
150-
3175.39, 3187.27, 3195.52, 3203.25, 3214.48, 3210.22, 3218.77, 3216.85,
151-
3221, 3221.37, 3225.99, 3216.23, 3224, 3230.16, 3227.6, 3224.2, 3240,
152-
3251.13, 3263.32, 3253.84, 3248.38, 3232.99, 3210.99, 3197.31, 3160.85,
153-
3174.81, 3193.03, 3191.8, 3187.52, 3162.31, 3160.3, 3121.62, 3130,
154-
3119.86, 3133, 3128.61, 3128.84, 3125.61, 3114.78, 3102.2, 3104.79,
155-
3069.41, 3074, 3087.97, 3096.29, 3098.59, 3092.15, 3095.56, 3110.15,
156-
3113.2, 3119.41, 3128.17, 3124.95, 3136.15, 3142.86, 3140, 3137.91,
157-
3144.45, 3143.04, 3146.88, 3140.86, 3148.23, 3154.01, 3160.57, 3165.67,
158-
3174.26, 3184.2, 3184.82, 3181.76, 3210.49, 3205.48, 3218.07, 3217.91,
159-
3210.38, 3221.28, 3220.03, 3219.03, 3220.01, 3224.01, 3228.11, 3212.89,
160-
3211.79, 3224.31, 3216.85, 3207.8, 3224.44, 3220.49, 3212.7, 3219.26,
161-
];
124+
const ethArrFile = fs.readFileSync('src/strategies/etharr.txt', 'utf8');
125+
const etharr = JSON.parse(ethArrFile);
162126
const { tradeArray } = await strategiesService.backTesting(
163127
'autoArima',
164128
'autoArima',
165129
'autoArima',
166-
ETHPriceArray,
130+
etharr,
167131
);
168132
// Info: (20240320 - Jacky) this is aim to sum the profit of all trades
169133
const profitArray = tradeArray.map((trade) => trade.profit);
170134
const sum = profitArray.reduce((total, profit) => total + profit, 0);
171-
expect(sum).toBe(-673.9419000000021);
135+
expect(sum).toBe(-7023.318874999997);
172136
});
173137
});

0 commit comments

Comments
 (0)