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

hide designated "hidden" positions in position table #816

Merged
merged 1 commit into from
Sep 17, 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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TS_PUBLIC_TYPESENSE_API_URL=https://typesense.tradingstrategy.ai
TS_PUBLIC_TYPESENSE_API_KEY=npdPPJNELDhdr7v6IS9rQUpFG2VvdyAL
TS_PUBLIC_DISCORD_URL=https://discord.gg/5M88m9nM8H
TS_PUBLIC_WALLET_CONNECT_PROJECT_ID=9ee7efad98897eb60ba023db6aa72355
TS_PUBLIC_STRATEGIES='[{"id":"enzyme-polygon-eth-btc-rsi","name":"ETH-BTC price surge","url":"https://enzyme-polygon-eth-btc-rsi.tradingstrategy.ai/","frontpage":true},{"id":"enzyme-ethereum-btc-eth-stoch-rsi","name":"Stochastic ETH/BTC long","url":"https://enzyme-ethereum-btc-eth-stoch-rsi.tradingstrategy.ai","fees":{"trading_strategy_protocol_fee":0.02,"strategy_developer_fee":0.1},"frontpage":true},{"id":"enzyme-polygon-eth-rolling-ratio","name":"ETH/BTC rolling ratio","url":"https://enzyme-polygon-eth-rolling-ratio.tradingstrategy.ai/","fees":{"trading_strategy_protocol_fee":0.02,"strategy_developer_fee":0.05},"frontpage":true},{"id":"enzyme-polygon-matic-eth-usdc","name":"ETH-MATIC-USDC momentum","url":"https://enzyme-polygon-matic-eth-usdc.tradingstrategy.ai","frontpage":true},{"id":"enzyme-polygon-eth-btc-usdc","name":"ETH-BTC-USDC momentum","url":"https://enzyme-polygon-eth-btc-usdc.tradingstrategy.ai","new_version_id":"enzyme-polygon-eth-btc-rsi","frontpage":true},{"id":"enzyme-polygon-matic-usdc","name":"MATIC breakout","url":"https://enzyme-polygon-matic-usdc.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-breakout","name":"ETH breakout","url":"https://enzyme-polygon-eth-breakout.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-usdc","name":"ETH Breakout bounce","url":"https://enzyme-polygon-eth-usdc.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-usdc-sls","name":"ETH Balance snap","url":"https://enzyme-polygon-eth-usdc-sls.tradingstrategy.ai"},{"id":"polygon-eth-spot-short","name":"ETH mean reversion bounce","url":"https://polygon-eth-spot-short.tradingstrategy.ai"},{"id":"arbitrum-btc-breakout","name":"BTC Barrier Breach","url":"https://arbitrum-btc-breakout.tradingstrategy.ai"}]'
TS_PUBLIC_STRATEGIES='[{"id":"enzyme-polygon-eth-btc-rsi","name":"ETH-BTC price surge","url":"https://enzyme-polygon-eth-btc-rsi.tradingstrategy.ai/","frontpage":true,"hiddenPositions":[4]},{"id":"enzyme-ethereum-btc-eth-stoch-rsi","name":"Stochastic ETH/BTC long","url":"https://enzyme-ethereum-btc-eth-stoch-rsi.tradingstrategy.ai","fees":{"trading_strategy_protocol_fee":0.02,"strategy_developer_fee":0.1},"frontpage":true},{"id":"enzyme-polygon-eth-rolling-ratio","name":"ETH/BTC rolling ratio","url":"https://enzyme-polygon-eth-rolling-ratio.tradingstrategy.ai/","fees":{"trading_strategy_protocol_fee":0.02,"strategy_developer_fee":0.05},"frontpage":true},{"id":"enzyme-polygon-matic-eth-usdc","name":"ETH-MATIC-USDC momentum","url":"https://enzyme-polygon-matic-eth-usdc.tradingstrategy.ai","frontpage":true},{"id":"enzyme-polygon-eth-btc-usdc","name":"ETH-BTC-USDC momentum","url":"https://enzyme-polygon-eth-btc-usdc.tradingstrategy.ai","new_version_id":"enzyme-polygon-eth-btc-rsi","frontpage":true},{"id":"enzyme-polygon-matic-usdc","name":"MATIC breakout","url":"https://enzyme-polygon-matic-usdc.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-breakout","name":"ETH breakout","url":"https://enzyme-polygon-eth-breakout.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-usdc","name":"ETH Breakout bounce","url":"https://enzyme-polygon-eth-usdc.tradingstrategy.ai"},{"id":"enzyme-polygon-eth-usdc-sls","name":"ETH Balance snap","url":"https://enzyme-polygon-eth-usdc-sls.tradingstrategy.ai"},{"id":"polygon-eth-spot-short","name":"ETH mean reversion bounce","url":"https://polygon-eth-spot-short.tradingstrategy.ai"},{"id":"arbitrum-btc-breakout","name":"BTC Barrier Breach","url":"https://arbitrum-btc-breakout.tradingstrategy.ai"}]'
TS_PUBLIC_GEO_BLOCK='{"strategies:view":["CU","IR","KP","RU","SY"],"strategies:deposit":["CU","IR","KP","RU","SY","US","UK"]}'
# Uncomment to test chain maintenance error
# TS_PUBLIC_CHAINS_UNDER_MAINTENANCE='{ "binance": "BNB Chain" }'
Expand Down
4 changes: 3 additions & 1 deletion src/lib/explorer/TradingDescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ Used in DataTable context (vs. standard svelte component context).
<script lang="ts">
import { DataBadge } from '$lib/components';

let classes = '';
export { classes as class };
export let label: string;
export let modifier = '';
export let isTest = false;
export let failed = false;
</script>

<div class="description-cell">
<div class="description-cell {classes}">
<span class="label">
{label}
</span>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/trade-executor/strategy/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { strategyConfig } from '$lib/config';
import { z } from 'zod';
import { percent } from '../state/utility-types';
import { percent, primaryKey } from '../state/utility-types';

export const strategyFeesSchema = z.object({
management_fee: percent.default(0),
Expand All @@ -16,7 +16,8 @@ export const strategyConfigurationSchema = z.object({
url: z.string().url(),
fees: strategyFeesSchema.default({}),
new_version_id: z.string().nullish(),
frontpage: z.boolean().nullish()
frontpage: z.boolean().nullish(),
hiddenPositions: primaryKey.array().default([])
});
export type StrategyConfiguration = z.infer<typeof strategyConfigurationSchema>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
{...options}
hasPagination={status === 'closed'}
hasSearch={status === 'closed'}
hiddenPositions={strategy.hiddenPositions}
on:change={handleChange}
/>
{:else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { getTradingPositionInfoArray } from 'trade-executor/state/position-info.
export async function load({ params, parent }) {
// status can be `open`, `closed` or `frozen` (see params/positionStatus.ts)
const { status } = params;
const { state } = await parent();
const { admin, strategy, state } = await parent();
const { hiddenPositions } = strategy;

const positions = getTradingPositionInfoArray(state, status);
let positions = getTradingPositionInfoArray(state, status);

if (!admin) {
positions = positions.filter((p) => !hiddenPositions.includes(p.position_id));
}

return { positions, status };
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let admin = false;
export let position: TradingPositionInfo;
export let baseUrl: string;
export let isHidden = false;

function getTradeLink(trade: TradeInfo) {
return `${baseUrl}/trade-${trade.trade_id}`;
Expand Down Expand Up @@ -83,6 +84,19 @@
</ul>
</PositionFlag>
{/if}

{#if admin && isHidden}
<PositionFlag status="warning" label="H" title="Hidden position">
<p>
<Alert size="xs" status="info" title="Note">This info is only displayed to admin users.</Alert>
</p>
<p>This position is hidden from non-admin users.</p>
<p>
Hidden positions are configured in <code>frontend</code> strategy configuration (on production, in the
<code>strategy.json</code> config file).
</p>
</PositionFlag>
{/if}
</div>

<style lang="postcss">
Expand All @@ -94,5 +108,15 @@
:global(.tooltip .popup) {
min-width: 32rem;
}

code {
font-family: var(--ff-mono);
font-size: 1em;
font-weight: 600;
color: var(--c-text-light);
background: color-mix(in srgb, transparent, gray 20%);
padding-inline: 0.5em;
border-radius: var(--radius-xs);
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
export let direction: 'asc' | 'desc' = 'desc';
export let hasSearch = false;
export let hasPagination = false;
export let hiddenPositions: number[] = [];

const positionsStore = writable([] as TradingPositionInfo[]);
$: positionsStore.set(positions);
Expand Down Expand Up @@ -53,15 +54,25 @@
table.column({
header: 'Position',
id: 'description',
accessor: ({ pair, isTest }) => ({ label: pair.symbol, modifier: pair.kindShortLabel, isTest }),
accessor: ({ position_id, pair, isTest }) => ({
class: hiddenPositions.includes(position_id) ? 'hidden' : '',
label: pair.symbol,
modifier: pair.kindShortLabel,
isTest
}),
cell: ({ value }) => createRender(TradingDescription, value)
}),
table.column({
header: 'Remarks',
id: 'flags',
accessor: (position) => position,
cell: ({ value }) =>
createRender(FlagCell, { admin, position: value, baseUrl: `./${status}-positions/${value.position_id}` }),
createRender(FlagCell, {
admin,
position: value,
baseUrl: `./${status}-positions/${value.position_id}`,
isHidden: hiddenPositions.includes(value.position_id)
}),
plugins: { sort: { disable: true } }
}),
table.column({
Expand Down Expand Up @@ -141,6 +152,23 @@
}

.position-table :global {
/* Make "hidden" position rows look 50% opaque w/out breaking nested tooltip style */
tr:has(.hidden) {
td {
background: var(--c-box-1);
}

/* only apply color-mix to text in leaf nodes */
*:not(:has(> *)) {
color: color-mix(in srgb, currentColor, var(--c-body) 50%);
}

/* revert the color-mix 50% opacity for the tooltip */
.tooltip .popup * {
color: var(--c-text);
}
}

.ticker {
white-space: pre;
}
Expand Down
Loading