Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Dec 25, 2024
1 parent af1e968 commit 97b29fc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/routers/balances.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ router.get("/id/:balanceId(\\d+)", (req, res): void => {
currency: balance.currency,
baseRate,
availCurrencies,
portfolio_id: portfolioId,
};
return result;
} else {
Expand Down
44 changes: 24 additions & 20 deletions src/routers/positions.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export const preparePositions = async (portfolio: Portfolio): Promise<(PositionE
openDate: item.createdAt.getTime(),
quantity: item.quantity,
contract: {
id: item.contract.id,
secType: item.contract.secType,
symbol: item.contract.symbol,
name: item.contract.name,
...item.contract,
// id: item.contract.id,
// secType: item.contract.secType,
// symbol: item.contract.symbol,
// name: item.contract.name,
// currency: item.contract.currency,
multiplier: 1,
currency: item.contract.currency,
price: getPrice(item.contract) || undefined,
expiration: undefined,
},
Expand Down Expand Up @@ -94,12 +95,13 @@ export const preparePositions = async (portfolio: Portfolio): Promise<(PositionE
openDate: item.createdAt.getTime(),
quantity: item.quantity,
contract: {
id: item.contract.id,
secType: item.contract.secType,
symbol: item.contract.symbol,
name: item.contract.name,
...item.contract,
// id: item.contract.id,
// secType: item.contract.secType,
// symbol: item.contract.symbol,
// name: item.contract.name,
// currency: item.contract.currency,
multiplier: option.multiplier,
currency: item.contract.currency,
price: getPrice(item.contract) || undefined,
expiration: undefined,
},
Expand Down Expand Up @@ -153,12 +155,13 @@ export const preparePositions = async (portfolio: Portfolio): Promise<(PositionE
openDate: item.createdAt.getTime(),
quantity: item.quantity,
contract: {
id: item.contract.id,
secType: item.contract.secType,
symbol: item.contract.symbol,
name: item.contract.name,
...item.contract,
// id: item.contract.id,
// secType: item.contract.secType,
// symbol: item.contract.symbol,
// name: item.contract.name,
// currency: item.contract.currency,
multiplier: future.multiplier,
currency: item.contract.currency,
price: getPrice(item.contract) || undefined,
expiration: future.lastTradeDate,
},
Expand Down Expand Up @@ -187,12 +190,13 @@ export const preparePositions = async (portfolio: Portfolio): Promise<(PositionE
openDate: item.createdAt.getTime(),
quantity: item.quantity,
contract: {
id: item.contract.id,
secType: item.contract.secType,
symbol: item.contract.symbol,
name: item.contract.name,
...item.contract,
// id: item.contract.id,
// secType: item.contract.secType,
// symbol: item.contract.symbol,
// name: item.contract.name,
// currency: item.contract.currency,
multiplier: 1,
currency: item.contract.currency,
price: getPrice(item.contract) || undefined,
expiration: undefined,
},
Expand Down
1 change: 1 addition & 0 deletions src/routers/positions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type PositionEntry = Omit<
> & {
contract: ContractEntry & {
// Fields added by router
multiplier: number;
expiration: string | undefined; // format?
};
// Fields added by router
Expand Down
38 changes: 12 additions & 26 deletions src/routers/statements.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,18 @@ export const statementModelToStatementEntry = async (item: Statement): Promise<S
],
}).then((thisStatement) => {
const option: StatementUnderlyingOption = {
id: thisStatement!.option.id,
secType: thisStatement!.contract.secType,
symbol: thisStatement!.contract.symbol,
currency: item.currency,
name: thisStatement!.contract.name,
price: thisStatement!.contract.price,
// underlying: {
// id: thisStatement!.option.stock.id,
// secType: thisStatement!.option.stock.secType,
// symbol: thisStatement!.option.stock.symbol,
// currency: thisStatement!.option.stock.currency,
// name: thisStatement!.option.stock.name,
// price: thisStatement!.option.stock.price,
// },
// underlying: {
// id: item.stock.id,
// secType: item.stock.secType,
// symbol: item.stock.symbol,
// currency: item.stock.currency,
// name: item.stock.name,
// price: item.stock.price,
// },
strike: thisStatement!.option.strike,
lastTradeDate: thisStatement!.option.lastTradeDate,
callOrPut: thisStatement!.option.callOrPut,
multiplier: thisStatement!.option.multiplier,
...thisStatement!.contract,
...thisStatement!.option,
// id: thisStatement!.option.id,
// secType: thisStatement!.contract.secType,
// symbol: thisStatement!.contract.symbol,
// currency: item.currency,
// name: thisStatement!.contract.name,
// price: thisStatement!.contract.price,
// strike: thisStatement!.option.strike,
// lastTradeDate: thisStatement!.option.lastTradeDate,
// callOrPut: thisStatement!.option.callOrPut,
// multiplier: thisStatement!.option.multiplier,
};
return {
statementType: StatementTypes.OptionStatement,
Expand Down
31 changes: 25 additions & 6 deletions src/routers/trades.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ export const tradeModelToTradeEntry = async (
}
const trade_entry: TradeEntry = {
id: thisTrade.id,
portfolioId: thisTrade.portfolio_id,
portfolio_id: thisTrade.portfolio_id,
symbol_id: thisTrade.underlying.id,
underlying: thisTrade.underlying,
currency: thisTrade.currency,
openingDate: thisTrade.openingDate.getTime(),
Expand All @@ -213,7 +214,7 @@ export const tradeModelToTradeEntry = async (
expectedDuration: thisTrade.expectedDuration,
strategy: thisTrade.strategy,
risk: thisTrade.risk,
pnl: thisTrade.PnL,
PnL: thisTrade.PnL,
unrlzdPnl: thisTrade.expiryPnl || undefined,
pnlInBase: thisTrade.pnlInBase,
apy,
Expand Down Expand Up @@ -282,9 +283,23 @@ export const addFakeTrades = (theSynthesys: OpenTradesWithPositions): TradeEntry
}
});
const duration = (Date.now() - openingDate) / 1000 / 3600 / 24;
theSynthesys.trades.push({
const entry: TradeEntry = {
id,
underlying: { id: -1, symbol: underlying, secType: ContractType.Stock, currency },
underlying: {
id: -1,
symbol: underlying,
secType: ContractType.Stock,
currency,
name: "virtual",
conId: 0,
exchange: "virtual",
price: 0,
bid: 0,
ask: 0,
previousClosePrice: 0,
fiftyTwoWeekLow: 0,
fiftyTwoWeekHigh: 0,
},
currency,
openingDate,
status: TradeStatus.open,
Expand All @@ -294,15 +309,19 @@ export const addFakeTrades = (theSynthesys: OpenTradesWithPositions): TradeEntry
expectedDuration,
strategy: TradeStrategy.undefined,
risk: undefined,
pnl: undefined,
PnL: undefined,
unrlzdPnl: undefined,
pnlInBase: undefined,
apy: undefined,
comment: undefined,
statements: undefined,
virtuals: undefined,
positions,
} as TradeEntry);
// unused?
portfolio_id: 0,
symbol_id: 0,
};
theSynthesys.trades.push(entry);
}
return theSynthesys.trades;
};
Expand Down

0 comments on commit 97b29fc

Please sign in to comment.