Skip to content

Commit

Permalink
fix:unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
RexBearIU committed Apr 22, 2024
1 parent 94653ff commit 0457a02
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-trade",
"version": "0.0.1+4",
"version": "0.0.1+5",
"description": "",
"author": "",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion src/price_ticker/price_ticker.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PriceTickerController } from './price_ticker.controller';
import PriceTickerService from './price_ticker.service';
import { PriceTickerService } from './price_ticker.service';
import { HttpModule } from '@nestjs/axios';

describe('PriceTickerController', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/price_ticker/price_ticker.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('PriceTickerService', () => {

it('should return an array of tickers', async () => {
const array = [1, 2, 3, 4, 5];
jest.spyOn(service, 'getTickers').mockImplementation(async () => array);
expect(await service.getTickers()).toStrictEqual([1, 2, 3, 4, 5]);
jest.spyOn(service, 'fetchTickers').mockImplementation(async () => array);
expect(await service.fetchTickers()).toStrictEqual([1, 2, 3, 4, 5]);
});

it('should return an array of candlestick', async () => {
Expand All @@ -43,7 +43,7 @@ describe('PriceTickerService', () => {
for (let i = 0; i < 11; i++) {
const begin = Date.now() - 90000000 * (i + 1);
const end = Date.now() - 90000000 * i;
const r = await service.getCandlesticksV2('ETH-USDT', '5m', begin, end);
const r = await service.fetchCandlesticksV2('ETH-USDT', '5m', begin, end);
const tempArr = r.data.candlesticks.candlesticks.map(
(item) => item.y.close,
);
Expand Down
2 changes: 1 addition & 1 deletion src/strategies/etharr.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ describe('RL test', () => {
[1, 0],
[1, 1],
]);
const ys = tf.tensor2d([[0], [1], [1], [0]]);
const ys = tf.tensor2d([
[0, 1],
[1, 0],
[1, 0],
[0, 1],
]); // Modify the target tensor shape

// Train the model
model.fit(xs, ys, { epochs: 100 }).then(() => {
Expand Down
10 changes: 5 additions & 5 deletions src/strategies/strategy/rl-dqn/train.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export async function train(
const averageReward100 = rewardAverager100.average();
if (averageReward100 > averageReward100Best) {
averageReward100Best = averageReward100;
if (savePath != null) {
await agent.onlineNetwork.save(
'file://src/strategies/strategy/rl-dqn/models/dqn',
);
}
// if (savePath != null) {
// await agent.onlineNetwork.save(
// 'file://src/strategies/strategy/rl-dqn/models/dqn',
// );
// }
}
syncCount++;
return agent.cumulativeReward_;
Expand Down

0 comments on commit 0457a02

Please sign in to comment.