Skip to content

Commit f6210a2

Browse files
committed
constructor parameter migrations / unused removal
1 parent ca16545 commit f6210a2

33 files changed

+243
-593
lines changed

src/dict/candlestick.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
export class Candlestick {
2-
time: number;
3-
open: number;
4-
high: number;
5-
low: number;
6-
close: number;
7-
volume: number;
8-
9-
constructor(time: number, open: number, high: number, low: number, close: number, volume: number) {
10-
this.time = time;
11-
this.open = open;
12-
this.high = high;
13-
this.low = low;
14-
this.close = close;
15-
this.volume = volume;
16-
}
2+
constructor(
3+
public time: number,
4+
public open: number,
5+
public high: number,
6+
public low: number,
7+
public close: number,
8+
public volume: number
9+
) {}
1710

1811
getArray(): { time: number; open: number; high: number; low: number; close: number; volume: number } {
1912
return {

src/dict/exchange_candlestick.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,16 @@ export interface CandlestickLike {
88
}
99

1010
export class ExchangeCandlestick {
11-
exchange: string;
12-
period: string;
13-
symbol: string;
14-
time: number;
15-
open: number;
16-
high: number;
17-
low: number;
18-
close: number;
19-
volume: number;
20-
2111
constructor(
22-
exchange: string,
23-
symbol: string,
24-
period: string,
25-
time: number,
26-
open: number,
27-
high: number,
28-
low: number,
29-
close: number,
30-
volume: number
12+
public exchange: string,
13+
public symbol: string,
14+
public period: string,
15+
public time: number,
16+
public open: number,
17+
public high: number,
18+
public low: number,
19+
public close: number,
20+
public volume: number
3121
) {
3222
if (!['m', 'h', 'd', 'y'].includes(period.slice(-1))) {
3323
throw `Invalid candlestick period: ${period} - ${JSON.stringify(Object.values(arguments))}`;
@@ -38,16 +28,6 @@ export class ExchangeCandlestick {
3828
if (time <= 631148400) {
3929
throw `Invalid candlestick time given: ${time} - ${JSON.stringify(Object.values(arguments))}`;
4030
}
41-
42-
this.exchange = exchange;
43-
this.period = period;
44-
this.symbol = symbol;
45-
this.time = time;
46-
this.open = open;
47-
this.high = high;
48-
this.low = low;
49-
this.close = close;
50-
this.volume = volume;
5131
}
5232

5333
static createFromCandle(exchange: string, symbol: string, period: string, candle: CandlestickLike): ExchangeCandlestick {

src/dict/exchange_order.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,25 @@ export class ExchangeOrder {
2828
static readonly SIDE_SHORT: ExchangeOrderSideLongShort = 'short';
2929
static readonly SIDE_LONG: ExchangeOrderSideLongShort = 'long';
3030

31-
id: string | number;
32-
symbol: string;
33-
status: ExchangeOrderStatus;
34-
price: number;
35-
amount: number;
36-
retry: boolean;
37-
ourId: string | number | undefined;
3831
side: ExchangeOrderSide;
3932
type: ExchangeOrderType;
4033
createdAt: Date;
4134
updatedAt: Date;
42-
raw?: any;
4335
options: ExchangeOrderOptions;
4436

4537
constructor(
46-
id: string | number,
47-
symbol: string,
48-
status: ExchangeOrderStatus,
49-
price: number,
50-
amount: number,
51-
retry: boolean,
52-
ourId?: string | number,
38+
public id: string | number,
39+
public symbol: string,
40+
public status: ExchangeOrderStatus,
41+
public price: number,
42+
public amount: number,
43+
public retry: boolean,
44+
public ourId?: string | number,
5345
side?: ExchangeOrderSide,
5446
type?: ExchangeOrderType,
5547
createdAt?: Date,
5648
updatedAt?: Date,
57-
raw?: any,
49+
public raw?: any,
5850
options: ExchangeOrderOptions = {}
5951
) {
6052
if (side && side !== 'buy' && side !== 'sell') {
@@ -75,18 +67,10 @@ export class ExchangeOrder {
7567
throw `Invalid order type: ${type}`;
7668
}
7769

78-
this.id = id;
79-
this.symbol = symbol;
80-
this.status = status;
81-
this.price = price;
82-
this.amount = amount;
83-
this.retry = retry;
84-
this.ourId = ourId;
8570
this.side = side || 'buy';
8671
this.type = type || 'unknown';
8772
this.createdAt = createdAt || new Date();
8873
this.updatedAt = updatedAt || new Date();
89-
this.raw = raw;
9074
this.options = options;
9175
}
9276

src/dict/exchange_position.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { Position } from './position';
22

33
export class ExchangePosition {
4-
private readonly _exchange: string;
5-
private readonly _position: Position;
6-
7-
constructor(exchange: string, position: Position) {
8-
if (!(position instanceof Position)) {
4+
constructor(
5+
private readonly _exchange: string,
6+
private readonly _position: Position
7+
) {
8+
if (!(_position instanceof Position)) {
99
throw new Error(`TypeError: invalid position`);
1010
}
11-
12-
this._exchange = exchange;
13-
this._position = position;
1411
}
1512

1613
getKey(): string {

src/dict/order.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,18 @@ export class Order {
2424

2525
static readonly OPTION_POST_ONLY = 'post_only';
2626

27-
id: string | number;
28-
symbol: string;
29-
side: OrderSide;
30-
price: number;
31-
amount: number;
32-
type: OrderType;
33-
options: OrderOptions;
34-
35-
constructor(id: string | number, symbol: string, side: OrderSide, price: number, amount: number, type: OrderType, options: OrderOptions = {}) {
27+
constructor(
28+
public id: string | number,
29+
public symbol: string,
30+
public side: OrderSide,
31+
public price: number,
32+
public amount: number,
33+
public type: OrderType,
34+
public options: OrderOptions = {}
35+
) {
3636
if (![Order.SIDE_LONG, Order.SIDE_SHORT].includes(side)) {
3737
throw new Error(`Invalid order side given: ${side}`);
3838
}
39-
40-
this.id = id;
41-
this.symbol = symbol;
42-
this.side = side;
43-
this.price = price;
44-
this.amount = amount;
45-
this.type = type;
46-
this.options = options;
4739
}
4840

4941
hasAdjustedPrice(): boolean {

src/dict/orderbook.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@ export interface OrderbookLevel {
44
}
55

66
export class Orderbook {
7-
asks: OrderbookLevel[];
8-
bids: OrderbookLevel[];
9-
10-
constructor(asks: OrderbookLevel[], bids: OrderbookLevel[]) {
11-
this.asks = asks;
12-
this.bids = bids;
13-
}
7+
constructor(public asks: OrderbookLevel[], public bids: OrderbookLevel[]) {}
148
}

src/dict/pair_state.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@ export class PairState {
1313
static readonly STATE_CANCEL: PairStateType = 'cancel';
1414

1515
time: Date;
16-
exchange: string;
17-
symbol: string;
18-
state: PairStateType;
19-
options?: any;
2016
capital?: OrderCapital;
2117
order?: Order;
2218
exchangeOrder?: ExchangeOrder;
2319
retries: number;
24-
adjustedPrice: boolean;
25-
clearCallback: ClearCallback;
2620
cleared: boolean;
2721

2822
/**
@@ -78,12 +72,12 @@ export class PairState {
7872
}
7973

8074
constructor(
81-
exchange: string,
82-
symbol: string,
83-
state: PairStateType,
84-
options?: any,
85-
adjustedPrice: boolean = false,
86-
clearCallback: ClearCallback = () => {}
75+
public exchange: string,
76+
public symbol: string,
77+
public state: PairStateType,
78+
public options?: any,
79+
public adjustedPrice: boolean = false,
80+
public clearCallback: ClearCallback = () => {}
8781
) {
8882
if (![PairState.STATE_LONG, PairState.STATE_SHORT, PairState.STATE_CLOSE, PairState.STATE_CANCEL].includes(state)) {
8983
throw new Error(`Invalidate state: ${state}`);
@@ -94,15 +88,7 @@ export class PairState {
9488
}
9589

9690
this.time = new Date();
97-
this.exchange = exchange;
98-
this.symbol = symbol;
99-
this.state = state;
100-
this.options = options;
101-
this.order = undefined;
102-
this.exchangeOrder = undefined;
10391
this.retries = 0;
104-
this.adjustedPrice = adjustedPrice;
105-
this.clearCallback = clearCallback;
10692
this.cleared = false;
10793
}
10894

src/dict/period.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
export class Period {
2-
time: any; // lookbacks - keeping any for now since type is unclear
3-
4-
constructor(lookbacks: any) {
5-
this.time = lookbacks;
6-
}
2+
constructor(public time: any) {} // lookbacks - keeping any for now since type is unclear
73
}

src/dict/position.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ export class Position {
44
static readonly SIDE_LONG: PositionSide = 'long';
55
static readonly SIDE_SHORT: PositionSide = 'short';
66

7-
symbol: string;
8-
side: PositionSide;
9-
amount: number;
10-
profit: number;
11-
updatedAt: Date;
12-
entry: number;
13-
createdAt: Date;
14-
raw?: any;
15-
167
/**
178
* @param symbol 'BTCUSD'
189
* @param side "long" or "short"
@@ -23,7 +14,16 @@ export class Position {
2314
* @param createdAt
2415
* @param raw
2516
*/
26-
constructor(symbol: string, side: PositionSide, amount: number, profit: number, updatedAt: Date, entry: number, createdAt: Date, raw?: any) {
17+
constructor(
18+
public symbol: string,
19+
public side: PositionSide,
20+
public amount: number,
21+
public profit: number,
22+
public updatedAt: Date,
23+
public entry: number,
24+
public createdAt: Date,
25+
public raw?: any
26+
) {
2727
if (![Position.SIDE_LONG, Position.SIDE_SHORT].includes(side)) {
2828
throw new Error(`Invalid position direction given:${side}`);
2929
}
@@ -35,15 +35,6 @@ export class Position {
3535
if (amount > 0 && side === Position.SIDE_SHORT) {
3636
throw new Error(`Invalid direction amount:${side}`);
3737
}
38-
39-
this.symbol = symbol;
40-
this.side = side;
41-
this.amount = amount;
42-
this.profit = profit;
43-
this.updatedAt = updatedAt;
44-
this.entry = entry;
45-
this.createdAt = createdAt;
46-
this.raw = raw;
4738
}
4839

4940
getSide(): PositionSide {

src/dict/signal.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
export class Signal {
2-
id: string;
3-
exchange: string;
4-
symbol: string;
5-
side: string;
6-
income_at: number;
7-
8-
constructor(id: string, exchange: string, symbol: string, side: string, income_at: number) {
9-
this.id = id;
10-
this.exchange = exchange;
11-
this.symbol = symbol;
12-
this.side = side;
13-
this.income_at = income_at;
14-
}
2+
constructor(
3+
public id: string,
4+
public exchange: string,
5+
public symbol: string,
6+
public side: string,
7+
public income_at: number
8+
) {}
159
}

0 commit comments

Comments
 (0)