Skip to content

Commit

Permalink
chore: lint and prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed May 10, 2024
1 parent 3d0752e commit c1ea1ce
Show file tree
Hide file tree
Showing 24 changed files with 64 additions and 57 deletions.
12 changes: 6 additions & 6 deletions apps/frontend/src/utils/charts/priceLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ export function computePriceLine(
const color = isWaitingLinePrice
? "gray"
: price > waitingPrice
? "red"
: "green";
? "red"
: "green";

const label = isWaitingLinePrice
? `Waiting line · ${index}`
: isUpperLimitPrice
? `High price · ${index}`
: isLowerLimitPrice
? `Low price · ${index}`
: `${index}`;
? `High price · ${index}`
: isLowerLimitPrice
? `Low price · ${index}`
: `${index}`;

return priceLine(price, color, label);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/backtesting-playground/src/grid-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ async function run() {
console.log("Bot config", config);

const backtesting = new Backtesting({
// @ts-ignore-next-line - @todo fix type
// @ts-expect-error-next-line - @todo fix type
botConfig: config,
// @ts-ignore-next-line - @todo fix type
botTemplate: gridbot,
// @ts-expect-error-next-line - @todo fix type
botTemplate: gridBot,
});

const {
Expand Down
2 changes: 1 addition & 1 deletion packages/backtesting/src/backtesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type {
} from "@opentrader/bot-processor";
import { BotProcessor } from "@opentrader/bot-processor";
import type { ICandlestick } from "@opentrader/types";
import { logger, format } from "@opentrader/logger";
import { fulfilledTable, gridTable } from "./debugging";
import { BacktestingReport } from "./backtesting-report";
import type { ReportResult } from "./types";
import { MarketSimulator } from "./market-simulator";
import { MemoryExchange } from "./exchange/memory-exchange";
import { MemoryStore } from "./store/memory-store";
import { logger, format } from "@opentrader/logger";

export class Backtesting<T extends IBotConfiguration<T>> {
private marketSimulator: MarketSimulator;
Expand Down
8 changes: 4 additions & 4 deletions packages/backtesting/src/debugging/fulfilledTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export function fulfilledTable(smartTrades: SmartTrade[]) {
isBuy || isBuyFilled
? "buy"
: isSell || isSellFilled
? "sell"
: "unknown";
? "sell"
: "unknown";

const price =
side === "sell"
? smartTrade.sell.price
: side === "buy"
? smartTrade.buy.price
: "unknown";
? smartTrade.buy.price
: "unknown";

const gridLine = {
stIndex: i,
Expand Down
4 changes: 2 additions & 2 deletions packages/backtesting/src/debugging/gridTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function gridTable(smartTrades: SmartTrade[]) {
side === "sell"
? smartTrade.sell.price
: side === "buy"
? smartTrade.buy.price
: "unknown";
? smartTrade.buy.price
: "unknown";

const gridLine = {
stIndex: i,
Expand Down
6 changes: 3 additions & 3 deletions packages/bot-templates/src/templates/grid-bot-lite.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { IBotConfiguration, TBotContext } from "@opentrader/bot-processor";
import type { IBotConfiguration, TBotContext } from "@opentrader/bot-processor";
import { calcGridLines } from "@opentrader/tools";

import { GridBotConfig, gridBot } from "./grid-bot";
import type { GridBotConfig } from "./grid-bot";
import { gridBot } from "./grid-bot";

/**
* Wrapper for the `gridBot` template with a simplified configuration.
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { CCXTCandlesProvider } from "./market-data/ccxt-candles.provider";
export { Processor } from './processing'
export { Processor } from "./processing";
18 changes: 9 additions & 9 deletions packages/bot/src/market-data/candles-provider.interface.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { EventEmitter } from "node:events";
import { ICandlestick } from "@opentrader/types";
import type { EventEmitter } from "node:events";
import type { ICandlestick } from "@opentrader/types";

export interface ICandlesProvider extends EventEmitter {
/**
* Alias for `emit("start")`
*/
start(): void;
start: () => void;
/**
* Start fetching candles
*/
emit(event: "start"): boolean;
emit(event: "done"): boolean;
emit(event: "candle", candle: ICandlestick): boolean;
emit: ((event: "start") => boolean) &
((event: "done") => boolean) &
((event: "candle", candle: ICandlestick) => boolean);

on(event: "start", listener: () => void): this;
on(event: "done", listener: () => void): this;
on(event: "candle", listener: (candle: ICandlestick) => void): this;
on: ((event: "start", listener: () => void) => this) &
((event: "done", listener: () => void) => this) &
((event: "candle", listener: (candle: ICandlestick) => void) => this);
}
4 changes: 2 additions & 2 deletions packages/bot/src/market-data/ccxt-candles.provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from "node:events";
import { type Exchange, type OHLCV } from "ccxt";
import { BarSize, ICandlestick } from "@opentrader/types";
import { ICandlesProvider } from "./candles-provider.interface";
import type { BarSize, ICandlestick } from "@opentrader/types";
import type { ICandlesProvider } from "./candles-provider.interface";

export class CCXTCandlesProvider
extends EventEmitter
Expand Down
5 changes: 4 additions & 1 deletion packages/bot/src/processing/exchange-accounts.watcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { IWatchOrder } from "@opentrader/types";
import { BotProcessing } from "@opentrader/processing";
import type { OrderWithSmartTrade , ExchangeAccountWithCredentials } from "@opentrader/db";
import type {
OrderWithSmartTrade,
ExchangeAccountWithCredentials,
} from "@opentrader/db";
import { xprisma } from "@opentrader/db";
import { logger } from "@opentrader/logger";
import { processingQueue } from "./processing.queue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export class OrderSynchronizerWsWatcher extends OrderSynchronizerWatcher {
);

if (!order) {
logger.info(`Order "${exchangeOrder.exchangeOrderId}" is not linked to any SmartTrade`);
logger.info(
`Order "${exchangeOrder.exchangeOrderId}" is not linked to any SmartTrade`,
);
continue;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/api/grid-lines.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { calcGridLines } from "@opentrader/tools";
import { logger } from "@opentrader/logger";
import { IGridLine } from "@opentrader/types";
import { CommandResult } from "../types";
import type { CommandResult } from "../types";

export function buildGridLines(
maxPrice: number,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/api/run-backtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { templates } from "@opentrader/bot-templates";
import { Backtesting } from "@opentrader/backtesting";
import { CCXTCandlesProvider } from "@opentrader/bot";
import { logger } from "@opentrader/logger";
import { BarSize, ICandlestick } from "@opentrader/types";
import { CommandResult, ConfigName } from "../types";
import type { BarSize, ICandlestick } from "@opentrader/types";
import type { CommandResult, ConfigName } from "../types";
import { readBotConfig } from "../config";
import { exchangeClassMap } from "../utils/ccxt";

Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/api/run-trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export async function runTrading(
await processor.onApplicationBootstrap();

if (bot.enabled) {
logger.info(`Bot "${bot.label}" is already enabled. Cancelling previous orders...`);
logger.info(
`Bot "${bot.label}" is already enabled. Cancelling previous orders...`,
);
await stopBot(bot.id);
logger.info(`The bot state were cleared`);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/api/stop-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { BotProcessing } from "@opentrader/processing";
import type { CommandResult, ConfigName } from "../types";
import { readBotConfig, readExchangesConfig } from "../config";

export async function stopCommand(
options: {
config: ConfigName;
},
): Promise<CommandResult> {
export async function stopCommand(options: {
config: ConfigName;
}): Promise<CommandResult> {
const config = readBotConfig(options.config);
logger.debug(config, "Parsed bot config");

Expand All @@ -19,7 +17,7 @@ export async function stopCommand(
const bot = await xprisma.bot.custom.findUnique({
where: {
label: config.label,
}
},
});

if (!bot) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/backtest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Argument, Command, Option } from "commander";
import type { Command } from "commander";
import { Argument, Option } from "commander";
import { DEFAULT_CONFIG_NAME } from "../config";
import { handle } from "../utils/command";
import * as api from "../api";
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/grid-lines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Argument, Command, Option } from "commander";
import type { Command } from "commander";
import { Argument, Option } from "commander";
import { handle } from "../utils/command";
import * as api from "../api";

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/stop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, Option } from "commander";
import type { Command } from "commander";
import { Option } from "commander";
import { DEFAULT_CONFIG_NAME } from "../config";
import { handle } from "../utils/command";
import * as api from "../api";
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/trade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Argument, Command, Option } from "commander";
import type { Command } from "commander";
import { Argument, Option } from "commander";
import { DEFAULT_CONFIG_NAME } from "../config";
import { handle } from "../utils/command";
import * as api from "../api";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExchangeAccount } from "@prisma/client";
import type { ExchangeAccount } from "@prisma/client";

export type ConfigName = "default" | "dev" | "prod";

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/utils/ccxt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExchangeCode } from "@opentrader/types";
import { pro as ccxt } from "ccxt";
import type { ExchangeCode } from "@opentrader/types";
import type { pro as ccxt } from "ccxt";

export const exchangeClassMap: Record<ExchangeCode, keyof typeof ccxt> = {
OKX: "okex",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logger } from "@opentrader/logger";
import { CommandResult } from "../types";
import type { CommandResult } from "../types";

/**
* Return a wrapper what will process an async function and log the result
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICandlestick } from "@opentrader/types";
import type { ICandlestick } from "@opentrader/types";
import c from "chalk";

const pad = (value: string | number, length: number) =>
Expand Down
6 changes: 3 additions & 3 deletions packages/processing/src/smart-trade/smart-trade.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class SmartTradeProcessor {
entryOrder.status === "Idle"
? entryOrder
: entryOrder.status === "Filled" && takeProfitOrder.status === "Idle"
? takeProfitOrder
: null;
? takeProfitOrder
: null;

if (orderPendingPlacement) {
const exchangeOrder = await this.placeOrder(orderPendingPlacement);
Expand Down Expand Up @@ -158,7 +158,7 @@ export class SmartTradeProcessor {

try {
await this.exchange.cancelLimitOrder({
orderId: order.exchangeOrderId!,
orderId: order.exchangeOrderId,
symbol: this.smartTrade.exchangeSymbolId,
});
await xprisma.order.updateStatus("Canceled", order.id);
Expand Down

0 comments on commit c1ea1ce

Please sign in to comment.