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

add enzyme-arbitrum-eth-btc-rsi strategy #827

Merged
merged 3 commits into from
Sep 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
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,"hiddenPositions":[4]},{"id":"enzyme-ethereum-btc-eth-stoch-rsi","name":"Stochastic ETH/BTC long","url":"https://enzyme-ethereum-btc-eth-stoch-rsi.tradingstrategy.ai","frontpage":true},{"id":"enzyme-polygon-eth-rolling-ratio","name":"ETH/BTC rolling ratio","url":"https://enzyme-polygon-eth-rolling-ratio.tradingstrategy.ai/","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-matic-eth-usdc","name":"ETH-MATIC-USDC momentum","url":"https://enzyme-polygon-matic-eth-usdc.tradingstrategy.ai","frontpage":true},{"id":"enzyme-arbitrum-eth-btc-rsi","name":"ETH-BTC price surge (Arbitrum)","url":"https://enzyme-arbitrum-eth-btc-rsi.tradingstrategy.ai/","depositOnEnzyme":true,"frontpage":true},{"id":"enzyme-polygon-eth-rolling-ratio","name":"ETH/BTC rolling ratio","url":"https://enzyme-polygon-eth-rolling-ratio.tradingstrategy.ai/","frontpage":true},{"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","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
2 changes: 1 addition & 1 deletion src/lib/chart/ChartContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Display a chart container with title, description and timespan selector.
import { SegmentedControl } from '$lib/components';

export let title = '';
export let selected = '3M';

type TimeSpan = {
performanceLabel: string;
Expand Down Expand Up @@ -48,7 +49,6 @@ Display a chart container with title, description and timespan selector.
}
};

let selected = '3M';
$: timeSpan = timeSpans[selected];
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export function formatDaysAgo(unixTimestamp: MaybeNumber): string {
if (!isNumber(unixTimestamp)) return notFilledMarker;
const seconds = Date.now() / 1000 - unixTimestamp;
const days = Math.floor(seconds / DAY);
return days < 1 ? 'Less than a day' : days === 1 ? '1 day' : `${days} days`;
return days < 1 ? '< 1 day' : days === 1 ? '1 day' : `${days} days`;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/routes/FeaturedStrategies.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Alert, Button, Section } from '$lib/components';
import StrategyTile from './strategies/StrategyTile.svelte';
import StrategyDifferentiator from './StrategyDifferentiator.svelte';
import { formatDaysAgo } from '$lib/helpers/formatters';
import { getStrategyChartDateRange } from 'trade-executor/chart/helpers';

export let strategies: StrategyRuntimeState[];
Expand Down
21 changes: 15 additions & 6 deletions src/routes/strategies/[strategy]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<script lang="ts">
import type { CIQ } from 'chartiq/js/standard';
import type { ComponentEvents } from 'svelte';
import type { Candle, Quote, QuoteFeed, RawTick } from '$lib/chart';
import {
type Candle,
type Quote,
type QuoteFeed,
quoteFeed,
normalizeDataForInterval,
periodicityToTimeBucket,
Expand All @@ -20,16 +18,18 @@
import { relativeProfitability } from 'trade-executor/helpers/profit';
import { isGeoBlocked } from '$lib/helpers/geo';
import { type BenchmarkToken, getBenchmarkTokens } from 'trade-executor/helpers/benchmarks';
import { differenceInCalendarDays } from 'date-fns';

export let data;
const { chain, strategy, admin, ipCountry } = data;

const backtestLink = `/strategies/${strategy.id}/backtest`;
const keyMetrics = strategy.summary_statistics.key_metrics;
const geoBlocked = !admin && isGeoBlocked('strategies:deposit', ipCountry);

const periodPerformance: Record<string, MaybeNumber> = {};

let initialTimeframe = '3M';

type ChartChangeDetail = ComponentEvents<PerformanceChart>['change']['detail'];

function getPeriodPerformance({ first, last, firstTickPosition }: ChartChangeDetail, spanDays: MaybeNumber) {
Expand All @@ -54,6 +54,15 @@
source: 'live_trading'
});

$: setInitialTimeframe($chartClient.data);

function setInitialTimeframe(data: RawTick[] | undefined) {
const firstTs = data?.[0]?.[0] as number | undefined;
if (firstTs === undefined) return;
const age = differenceInCalendarDays(new Date(), firstTs * 1000);
initialTimeframe = age <= 7 ? '1W' : age <= 30 ? '1M' : '3M';
}

const benchmarkTokens = getBenchmarkTokens(strategy);
let selectedBenchmarks = benchmarkTokens.map((t) => t.symbol);
let benchmarksUpdating = 0;
Expand Down Expand Up @@ -123,7 +132,7 @@
return d >= first.DT && d <= last.DT;
});

const initialValue = candles[0].c;
const initialValue = candles[0]?.c ?? 0;

return candles.map(({ ts, c }: Candle) => {
const percentChange = (c - initialValue) / initialValue;
Expand Down Expand Up @@ -162,7 +171,7 @@
<MyDeposits {strategy} {chain} {geoBlocked} {ipCountry} />

<div class="chart">
<ChartContainer let:timeSpan={{ spanDays, interval }}>
<ChartContainer selected={initialTimeframe} let:timeSpan={{ spanDays, interval }}>
<div class="period-performance" slot="title" let:timeSpan={{ performanceLabel }}>
{#if periodPerformance[strategy.id] !== undefined}
<UpDownCell value={periodPerformance[strategy.id]} formatter={formatProfitability} />
Expand Down
Loading