Skip to content

Commit 116d08f

Browse files
authored
Merge branch 'develop' into feature/modify_priceticker
2 parents 5e5d894 + 689322b commit 116d08f

24 files changed

+1044
-125
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: 2 additions & 0 deletions
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+
38+
# package-lock.json
3739
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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@nestjs/mapped-types": "*",
2828
"@nestjs/platform-express": "^10.0.0",
2929
"@nestjs/schedule": "^4.0.1",
30+
"@tensorflow/tfjs-node": "^4.17.0",
3031
"arima": "^0.2.5",
3132
"axios": "^1.5.1",
3233
"bignumber.js": "^9.1.2",

src/price_ticker/price_ticker.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
22
import PriceTickerService from './price_ticker.service';
33
import { HttpModule } from '@nestjs/axios';
44
import { QuotationDto } from './dto/quotation.dto';
5+
import * as fs from 'fs';
56

67
describe('PriceTickerService', () => {
78
let service: PriceTickerService;
@@ -36,4 +37,21 @@ describe('PriceTickerService', () => {
3637
.mockImplementation(async () => array);
3738
expect(await service.getCandlesticks()).toStrictEqual([1, 2, 3, 4, 5]);
3839
});
40+
41+
it('should return an array of candlestick', async () => {
42+
let etharr = [];
43+
for (let i = 0; i < 11; i++) {
44+
const begin = Date.now() - 90000000 * (i + 1);
45+
const end = Date.now() - 90000000 * i;
46+
const r = await service.getCandlesticksV2('ETH-USDT', '5m', begin, end);
47+
const tempArr = r.data.candlesticks.candlesticks.map(
48+
(item) => item.y.close,
49+
);
50+
etharr = tempArr.concat(etharr);
51+
}
52+
const etharrJson = JSON.stringify(etharr);
53+
// console.log(etharr);
54+
// use fs to write the etharr to a file
55+
fs.writeFileSync('src/strategies/etharr.txt', etharrJson);
56+
});
3957
});

src/strategies/ETH-USD.csv

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,4 @@ Date,Open,High,Low,Close,Adj Close,Volume
364364
2024-03-10,3915.590576,3968.723633,3800.564453,3881.193115,3881.193115,15783924355
365365
2024-03-11,3881.237793,4087.050049,3745.125244,4066.445068,4066.445068,28806262507
366366
2024-03-12,4066.690430,4092.284180,3831.889893,3980.273193,3980.273193,26917010932
367-
2024-03-13,3980.265137,4083.007324,3936.627197,4006.457031,4006.457031,22028114691
368-
2024-03-14,null,null,null,null,null,null
367+
2024-03-13,3980.265137,4083.007324,3936.627197,4006.457031,4006.457031,22028114691

src/strategies/ethCandle.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/strategies/etharr.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { Controller } from '@nestjs/common';
1+
import { Controller, Get } from '@nestjs/common';
22
import { StrategiesService } from './strategies.service';
33

44
@Controller('strategies')
55
export class StrategiesController {
66
constructor(private readonly strategiesService: StrategiesService) {}
7+
8+
@Get()
9+
async trainDqn() {
10+
await this.strategiesService.trainDqn();
11+
return 'Training DQN finished';
12+
}
713
}

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)