Skip to content

Commit 86bab4b

Browse files
committed
typed imports
1 parent f6210a2 commit 86bab4b

26 files changed

+65
-121
lines changed

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ program
1313
.action(async (options: any) => {
1414
await services.boot(__dirname);
1515

16-
const cmd = new TradeCommand(options.instance);
16+
const cmd = new TradeCommand();
1717
cmd.execute();
1818
});
1919

@@ -42,7 +42,7 @@ program
4242
.description('')
4343
.option('-i, --instance <file>', 'Instance to start', 'instance.json')
4444
.action((options: any) => {
45-
const cmd = new ServerCommand(options.instance);
45+
const cmd = new ServerCommand();
4646
cmd.execute();
4747
});
4848

src/command/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import services from '../modules/services';
22

33
export class ServerCommand {
4-
constructor(_instance: string) {}
4+
constructor() {}
55

66
execute(): void {
77
services.createWebserverInstance().start();

src/command/trade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import services from '../modules/services';
22

33
export class TradeCommand {
4-
constructor(_instance: string) {}
4+
constructor() {}
55

66
execute(): void {
77
services.createTradeInstance().start();

src/controller/base_controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface TemplateHelpers {
1515
}
1616

1717
export abstract class BaseController implements Controller {
18-
constructor(protected templateHelpers: TemplateHelpers) {}
18+
protected constructor(protected templateHelpers: TemplateHelpers) {}
1919

2020
abstract registerRoutes(router: express.Router): void;
2121

src/controller/trades_controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { BaseController, TemplateHelpers } from './base_controller';
22
import { ExchangeManager } from '../modules/exchange/exchange_manager';
3-
import { OrdersHttp } from '../modules/orders/orders_http';
43
import { Tickers } from '../storage/tickers';
5-
import { OrderUtil } from '../utils/order_util';
4+
import { getPercentDifferent } from '../utils/order_util';
65
import express from 'express';
76

87
export class TradesController extends BaseController {
98
constructor(
109
templateHelpers: TemplateHelpers,
1110
private exchangeManager: ExchangeManager,
12-
private ordersHttp: OrdersHttp,
1311
private tickers: Tickers
1412
) {
1513
super(templateHelpers);
@@ -62,7 +60,7 @@ export class TradesController extends BaseController {
6260

6361
const ticker = this.tickers.get(exchange.getName(), order.symbol);
6462
if (ticker) {
65-
items.percent_to_price = OrderUtil.getPercentDifferent(order.price, ticker.bid);
63+
items.percent_to_price = getPercentDifferent(order.price, ticker.bid);
6664
}
6765

6866
orders.push(items);

src/exchange/binance.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ExchangeCandlestick } from '../dict/exchange_candlestick';
66
import { Ticker } from '../dict/ticker';
77
import { TickerEvent } from '../event/ticker_event';
88
import { ExchangeOrder } from '../dict/exchange_order';
9-
import { OrderUtil } from '../utils/order_util';
9+
import { calculateNearestSize } from '../utils/order_util';
1010
import { Position } from '../dict/position';
1111
import { Order } from '../dict/order';
1212
import { OrderBag } from './utils/order_bag';
@@ -414,7 +414,7 @@ export class Binance {
414414
return undefined;
415415
}
416416

417-
return parseFloat(String(OrderUtil.calculateNearestSize(price, pairInfo.tick_size)));
417+
return parseFloat(String(calculateNearestSize(price, pairInfo.tick_size)));
418418
}
419419

420420
/**
@@ -430,7 +430,7 @@ export class Binance {
430430
return undefined;
431431
}
432432

433-
return parseFloat(String(OrderUtil.calculateNearestSize(amount, pairInfo.lot_size)));
433+
return parseFloat(String(calculateNearestSize(amount, pairInfo.lot_size)));
434434
}
435435

436436
async getPositions(): Promise<Position[]> {

src/exchange/binance_margin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ExchangeCandlestick } from '../dict/exchange_candlestick';
99
import { Ticker } from '../dict/ticker';
1010
import { TickerEvent } from '../event/ticker_event';
1111
import { ExchangeOrder } from '../dict/exchange_order';
12-
import { OrderUtil } from '../utils/order_util';
12+
import { calculateNearestSize } from '../utils/order_util';
1313
import { TradesUtil } from './utils/trades_util';
1414
import { Position } from '../dict/position';
1515
import { Order } from '../dict/order';
@@ -276,7 +276,7 @@ export class BinanceMargin {
276276
return undefined;
277277
}
278278

279-
return parseFloat(String(OrderUtil.calculateNearestSize(price, pairInfo.tick_size)));
279+
return parseFloat(String(calculateNearestSize(price, pairInfo.tick_size)));
280280
}
281281

282282
/**
@@ -292,7 +292,7 @@ export class BinanceMargin {
292292
return undefined;
293293
}
294294

295-
return parseFloat(String(OrderUtil.calculateNearestSize(amount, pairInfo.lot_size)));
295+
return parseFloat(String(calculateNearestSize(amount, pairInfo.lot_size)));
296296
}
297297

298298
async getPositions(): Promise<Position[]> {

src/exchange/bitmex.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { Candlestick } from '../dict/candlestick';
99
import { Ticker } from '../dict/ticker';
1010
import { ExchangeCandlestick } from '../dict/exchange_candlestick';
1111
import { TickerEvent } from '../event/ticker_event';
12-
import { Resample } from '../utils/resample';
12+
import { resampleMinutes, convertPeriodToMinute } from '../utils/resample';
1313
import { Position } from '../dict/position';
1414
import { Order } from '../dict/order';
1515
import { ExchangeOrder, ExchangeOrderStatus, ExchangeOrderType } from '../dict/exchange_order';
16-
import { orderUtil } from '../utils/order_util';
16+
import { calculateNearestSize } from '../utils/order_util';
1717

1818
// Types for BitMEX API responses
1919
interface BitmexInstrument {
@@ -291,9 +291,9 @@ export class Bitmex {
291291
resamples[symbol.symbol][period].length > 0
292292
) {
293293
for (const periodTo of resamples[symbol.symbol][period]) {
294-
const resampledCandles = Resample.resampleMinutes(
294+
const resampledCandles = resampleMinutes(
295295
candleSticks.slice(),
296-
Resample.convertPeriodToMinute(periodTo) // 15m > 15
296+
convertPeriodToMinute(periodTo) // 15m > 15
297297
);
298298

299299
const candles = resampledCandles.map(candle => {
@@ -560,7 +560,7 @@ export class Bitmex {
560560
return undefined;
561561
}
562562

563-
return orderUtil.calculateNearestSize(price, this.tickSizes[symbol]);
563+
return calculateNearestSize(price, this.tickSizes[symbol]);
564564
}
565565

566566
/**
@@ -594,7 +594,7 @@ export class Bitmex {
594594
return undefined;
595595
}
596596

597-
return orderUtil.calculateNearestSize(amount, this.lotSizes[symbol]);
597+
return calculateNearestSize(amount, this.lotSizes[symbol]);
598598
}
599599

600600
getName(): string {

src/exchange/bybit.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { Ticker } from '../dict/ticker';
88
import { TickerEvent } from '../event/ticker_event';
99
import { Order } from '../dict/order';
1010
import { ExchangeCandlestick } from '../dict/exchange_candlestick';
11-
import { Resample } from '../utils/resample';
11+
import { convertPeriodToMinute } from '../utils/resample';
1212
import { Position } from '../dict/position';
1313
import { ExchangeOrder, ExchangeOrderStatus } from '../dict/exchange_order';
14-
import { orderUtil } from '../utils/order_util';
14+
import { calculateNearestSize } from '../utils/order_util';
1515
import { EventEmitter } from 'events';
1616
import type { Logger } from '../modules/services';
1717
import type { QueueManager } from '../utils/queue';
@@ -81,7 +81,7 @@ export class Bybit {
8181

8282
symbols.forEach((symbol: any) => {
8383
symbol.periods.forEach((p: string) => {
84-
const periodMinute = Resample.convertPeriodToMinute(p);
84+
const periodMinute = convertPeriodToMinute(p);
8585

8686
ws.send(JSON.stringify({ op: 'subscribe', args: [`klineV2.${periodMinute}.${symbol.symbol}`] }));
8787
});
@@ -180,8 +180,8 @@ export class Bybit {
180180
// add price spread around the last price; as we not getting the bid and ask of the orderbook directly
181181
// prevent also floating issues
182182
if (symbol in me.tickSizes) {
183-
bid = parseFloat(String(orderUtil.calculateNearestSize(bid - me.tickSizes[symbol], me.tickSizes[symbol])));
184-
ask = parseFloat(String(orderUtil.calculateNearestSize(ask + me.tickSizes[symbol], me.tickSizes[symbol])));
183+
bid = parseFloat(String(calculateNearestSize(bid - me.tickSizes[symbol], me.tickSizes[symbol])));
184+
ask = parseFloat(String(calculateNearestSize(ask + me.tickSizes[symbol], me.tickSizes[symbol])));
185185
}
186186

187187
eventEmitter.emit(
@@ -243,7 +243,7 @@ export class Bybit {
243243
symbol.periods.forEach((period: string) => {
244244
// for bot init prefill data: load latest candles from api
245245
this.queue.add(async () => {
246-
const minutes = Resample.convertPeriodToMinute(period);
246+
const minutes = convertPeriodToMinute(period);
247247

248248
// from is required calculate to be inside window
249249
const from = Math.floor(new Date().getTime() / 1000) - minutes * 195 * 60;
@@ -397,7 +397,7 @@ export class Bybit {
397397
return undefined;
398398
}
399399

400-
return parseFloat(String(orderUtil.calculateNearestSize(price, tickSize)));
400+
return parseFloat(String(calculateNearestSize(price, tickSize)));
401401
}
402402

403403
/**
@@ -432,7 +432,7 @@ export class Bybit {
432432
return undefined;
433433
}
434434

435-
return parseFloat(String(orderUtil.calculateNearestSize(amount, lotSize)));
435+
return parseFloat(String(calculateNearestSize(amount, lotSize)));
436436
}
437437

438438
getName(): string {

src/exchange/bybit_unified.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Ticker } from '../dict/ticker';
44
import { TickerEvent } from '../event/ticker_event';
55
import { ExchangeCandlestick } from '../dict/exchange_candlestick';
66
import { Position } from '../dict/position';
7-
import CommonUtil = require('../utils/common_util');
7+
import { getProfitAsPercent } from '../utils/common_util';
88
import { ExchangeOrder } from '../dict/exchange_order';
99
import { OrderBag } from './utils/order_bag';
1010
import { Order } from '../dict/order';
11-
import { orderUtil } from '../utils/order_util';
11+
import { calculateNearestSize } from '../utils/order_util';
1212
import { EventEmitter } from 'events';
1313
import type { Logger } from '../modules/services';
1414
import type { QueueManager } from '../utils/queue';
@@ -280,7 +280,7 @@ export class BybitUnified {
280280
position.symbol,
281281
side,
282282
size,
283-
position.markPrice && position.entryPrice ? CommonUtil.getProfitAsPercent(side, position.markPrice, position.entryPrice) : undefined,
283+
position.markPrice && position.entryPrice ? getProfitAsPercent(side, position.markPrice, position.entryPrice) : undefined,
284284
new Date(),
285285
parseFloat(position.entryPrice),
286286
new Date(),
@@ -328,7 +328,7 @@ export class BybitUnified {
328328
return undefined;
329329
}
330330

331-
return parseFloat(String(orderUtil.calculateNearestSize(price, tickSize)));
331+
return parseFloat(String(calculateNearestSize(price, tickSize)));
332332
}
333333

334334
/**
@@ -344,7 +344,7 @@ export class BybitUnified {
344344
return undefined;
345345
}
346346

347-
return parseFloat(String(orderUtil.calculateNearestSize(amount, lotSize)));
347+
return parseFloat(String(calculateNearestSize(amount, lotSize)));
348348
}
349349

350350
getName(): string {

0 commit comments

Comments
 (0)