|
1 | 1 | import BigNumber from 'bignumber.js' |
2 | 2 | import { Side } from './side' |
3 | 3 |
|
| 4 | +interface IOrder { |
| 5 | + id: string |
| 6 | + side: Side |
| 7 | + size: number |
| 8 | + price: number |
| 9 | + time: number |
| 10 | + isMaker: boolean |
| 11 | +} |
| 12 | + |
4 | 13 | export interface OrderUpdate { |
5 | 14 | size: number |
6 | 15 | price: number |
@@ -41,81 +50,73 @@ export class Order { |
41 | 50 | this._isMaker = isMaker ?? false |
42 | 51 | } |
43 | 52 |
|
44 | | - // returns orderId of the order |
| 53 | + // Getter for order ID |
45 | 54 | get id (): string { |
46 | 55 | return this._id |
47 | 56 | } |
48 | 57 |
|
49 | | - // returns side of the order |
| 58 | + // Getter for order side |
50 | 59 | get side (): Side { |
51 | 60 | return this._side |
52 | 61 | } |
53 | 62 |
|
54 | | - // returns price of the order |
| 63 | + // Getter for order price |
55 | 64 | get price (): number { |
56 | 65 | return this._price |
57 | 66 | } |
58 | 67 |
|
59 | | - // returns size of the order |
| 68 | + // Getter for order size |
60 | 69 | get size (): BigNumber { |
61 | 70 | return this._size |
62 | 71 | } |
63 | 72 |
|
| 73 | + // Setter for order size |
64 | 74 | set size (size: BigNumber) { |
65 | 75 | this._size = size |
66 | 76 | } |
67 | 77 |
|
68 | | - // returns timestamp of the order |
| 78 | + // Getter for order timestamp |
69 | 79 | get time (): number { |
70 | 80 | return this._time |
71 | 81 | } |
72 | 82 |
|
| 83 | + // Setter for order timestamp |
73 | 84 | set time (time: number) { |
74 | 85 | this._time = time |
75 | 86 | } |
76 | 87 |
|
| 88 | + // Getter for order isMaker |
77 | 89 | get isMaker (): boolean { |
78 | 90 | return this._isMaker |
79 | 91 | } |
80 | 92 |
|
81 | | - // returns string representation of the order |
82 | | - toString = (): string => { |
83 | | - return `${this._id}: |
| 93 | + // This method returns a string representation of the order |
| 94 | + toString = (): string => ( |
| 95 | + `${this._id}: |
84 | 96 | side: ${this._side} |
85 | | - size: ${this._size.toNumber() as unknown as string} |
| 97 | + size: ${this._size.toString()} |
86 | 98 | price: ${this._price} |
87 | 99 | time: ${this._time} |
88 | | - isMaker: ${this.isMaker as unknown as string}` |
89 | | - } |
| 100 | + isMaker: ${this._isMaker as unknown as string}` |
| 101 | + ) |
90 | 102 |
|
91 | | - // returns JSON string of the order |
92 | | - toJSON = (): string => { |
93 | | - return JSON.stringify({ |
94 | | - id: this._id, |
95 | | - side: this._side, |
96 | | - size: this._size.toNumber(), |
97 | | - price: this._price, |
98 | | - time: this._time, |
99 | | - isMaker: this.isMaker |
100 | | - }) |
101 | | - } |
| 103 | + // This method returns a JSON string representation of the order |
| 104 | + toJSON = (): string => JSON.stringify({ |
| 105 | + id: this._id, |
| 106 | + side: this._side, |
| 107 | + size: this._size.toNumber(), |
| 108 | + price: this._price, |
| 109 | + time: this._time, |
| 110 | + isMaker: this._isMaker |
| 111 | + }) |
102 | 112 |
|
103 | | - // returns an object with each property name and value |
104 | | - toObject = (): { |
105 | | - id: string |
106 | | - side: Side |
107 | | - size: number |
108 | | - price: number |
109 | | - time: number |
110 | | - isMaker: boolean |
111 | | - } => { |
112 | | - return { |
113 | | - id: this._id, |
114 | | - side: this._side, |
115 | | - size: this._size.toNumber(), |
116 | | - price: this._price, |
117 | | - time: this._time, |
118 | | - isMaker: this.isMaker |
119 | | - } |
120 | | - } |
| 113 | + // This method returns an object representation of the order |
| 114 | + toObject = (): IOrder => ({ |
| 115 | + id: this._id, |
| 116 | + side: this._side, |
| 117 | + size: this._size.toNumber(), |
| 118 | + price: this._price, |
| 119 | + time: this._time, |
| 120 | + isMaker: this._isMaker |
| 121 | + }) |
121 | 122 | } |
0 commit comments