Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unfrozen open position bug #809

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/trade-executor/state/position-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,28 @@ describe('closed position with stats entries', () => {
expect(spy).toHaveBeenCalledOnce();
});
});

describe('position with frozen_at value', () => {
const frozenPosition = { ...position, frozen_at: new Date() };
const frozenPositionInfo = createTradingPositionInfo(frozenPosition);

test('should be frozen', () => {
expect(frozenPositionInfo.frozen).toBeTruthy();
});

test('should not be stillOpen', () => {
expect(frozenPositionInfo.stillOpen).toBeFalsy();
});

describe('and unfrozen_at value', () => {
const unfrozenPositionInfo = createTradingPositionInfo({ ...frozenPosition, unfrozen_at: new Date() });

test('should no longer be frozen', () => {
expect(unfrozenPositionInfo.frozen).toBeFalsy();
});

test('should be stillOpen', () => {
expect(unfrozenPositionInfo.stillOpen).toBeTruthy();
});
});
});
2 changes: 1 addition & 1 deletion src/lib/trade-executor/state/position-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const tradingPositionInfoPrototype = {
},

get stillOpen() {
return this.closed_at == null && this.frozen_at == null;
return !this.closed && !this.frozen;
},

get frozen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
$: positionsStore.set(positions);

const statusColumns = {
open: ['description', 'flags', 'profitability', 'value', 'opened_at', 'cta'],
open: ['description', 'flags', 'profitability', 'current_value', 'opened_at', 'cta'],
closed: ['description', 'flags', 'profitability', 'value_at_open', 'closed_at', 'cta'],
frozen: ['description', 'flags', 'frozen_on', 'frozen_value', 'frozen_at', 'cta']
};
Expand Down Expand Up @@ -76,7 +76,8 @@
}),
table.column({
header: 'Value',
accessor: 'value',
id: 'current_value',
accessor: 'currentValue',
cell: ({ value }) => formatDollar(value)
}),
table.column({
Expand Down Expand Up @@ -147,7 +148,7 @@
padding-block: 0;
}

:is(.profitability, .value, .value_at_open, .frozen_value, .opened_at, .closed_at, .frozen_at) {
:is(.profitability, .current_value, .value_at_open, .frozen_value, .opened_at, .closed_at, .frozen_at) {
text-align: right;
}

Expand Down
Loading