Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed May 11, 2024
1 parent 4de7085 commit 0a386de
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 467 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@typescript-eslint/no-non-null-assertion": "off", // behavior mismatch between TSlint and TScompiler. I make a valid usage of non null assertions
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "off", // behavior mismatch between TSlint and TScompiler. giving too many useless errors
"@typescript-eslint/no-unnecessary-type-assertion": "off", // I allow unnecessary type assertions
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/no-unsafe-assignment": "off", // off for the moment because we have too many warnings
"@typescript-eslint/no-unsafe-call": "error",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "yarn" # caches the yarn cache folder not node_modules

- name: Prepare
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.1
node-version: 20.12.2
cache: "yarn" # caches the yarn cache folder not node_modules

- name: Prepare
Expand Down
52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,45 @@
"@chakra-ui/system": "^2.6.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@stoqey/ib": "stoqey/ib#bae47e65685f6b752e424450966e4e9df715830c",
"@tanstack/react-table": "^8.15.3",
"@stoqey/ib": "stoqey/ib#ce245005089569ba2f6cc20bec9862693f4b7952",
"@tanstack/react-table": "^8.16.0",
"chakra-react-select": "^4.7.6",
"chart.js": "^4.4.2",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"fast-xml-parser": "^4.3.6",
"formik": "^2.4.5",
"framer-motion": "^11.0.24",
"formik": "^2.4.6",
"framer-motion": "^11.1.9",
"json-stringify-safe": "^5.0.1",
"react": "^18.2.0",
"react": "^18.3.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1",
"reflect-metadata": "^0.2.2",
"sequelize": "^6.37.2",
"sequelize": "^6.37.3",
"sequelize-typescript": "^2.1.6",
"sqlite3": "^5.1.7",
"winston": "^3.13.0",
"yahoo-finance2": "^2.11.0"
"yahoo-finance2": "^2.11.2"
},
"devDependencies": {
"@babel/core": "^7.24.3",
"@babel/core": "^7.24.5",
"@chakra-ui/storybook-addon": "^5.1.0",
"@storybook/addon-actions": "^8.0.5",
"@storybook/addon-essentials": "^8.0.5",
"@storybook/addon-links": "^8.0.5",
"@storybook/cli": "^8.0.5",
"@storybook/components": "^8.0.5",
"@storybook/react": "^8.0.5",
"@storybook/react-vite": "^8.0.5",
"@storybook/addon-actions": "^8.0.10",
"@storybook/addon-essentials": "^8.0.10",
"@storybook/addon-links": "^8.0.10",
"@storybook/cli": "^8.0.10",
"@storybook/components": "^8.0.10",
"@storybook/react": "^8.0.10",
"@storybook/react-vite": "^8.0.10",
"@storybook/testing-library": "^0.2.2",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/json-stringify-safe": "^5.0.3",
"@types/node": "^20.12.2",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.23",
"@types/node": "^20.12.11",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@types/validator": "^13.11.9",
"@typescript-eslint/eslint-plugin": "^7.4.0",
Expand All @@ -91,21 +91,21 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-storybook": "^0.8.0",
"http-proxy-middleware": "^2.0.6",
"http-proxy-middleware": "^3.0.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"patch-package": "^8.0.0",
"prettier": "^3.2.5",
"rxjs": "^7.8.1",
"storybook": "^8.0.5",
"stylelint": "^16.3.1",
"storybook": "^8.0.10",
"stylelint": "^16.5.0",
"stylelint-config-standard": "^36.0.0",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.3",
"vite": "^5.2.7",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"webpack": "^5.91.0"
},
"engines": {
"node": "^20.11.1"
"node": "^20.12.2"
}
}
10 changes: 3 additions & 7 deletions src/bots/account.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class AccountUpdateBot extends ITradingBot {

private createAndUpdateLegs(order: IbOpenOrder, transaction: Transaction): Promise<IbOpenOrder> {
if (order.contract.secType == SecType.BAG) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return order.contract.comboLegs!.reduce(
(p, leg) =>
p.then(() =>
Expand All @@ -100,17 +99,14 @@ export class AccountUpdateBot extends ITradingBot {
// portfolioId: this.portfolio.id,
// contract_id: contract.id,
actionType: order.order.action == leg.action ? OrderAction.BUY : OrderAction.SELL,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
totalQty: order.order.totalQuantity! * leg.ratio!,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
cashQty: order.order.cashQty ? order.order.cashQty * leg.ratio! : undefined,
lmtPrice: undefined,
auxPrice: undefined,
status: order.orderState.status!,
remainingQty: order.orderStatus
? order.orderStatus.remaining! * leg.ratio! // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion
: order.order.totalQuantity! * leg.ratio!, // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion

? order.orderStatus.remaining! * leg.ratio!
: order.order.totalQuantity! * leg.ratio!,
orderId: order.orderId,
clientId: order.order.clientId!,
};
Expand Down Expand Up @@ -228,7 +224,7 @@ export class AccountUpdateBot extends ITradingBot {
const defaults = {
portfolio_id: this.portfolio.id,
quantity: pos.pos,
cost: pos.avgCost! * pos.pos, // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion
cost: pos.avgCost! * pos.pos,
};
return this.findOrCreateContract(pos.contract).then((contract): Promise<Position | undefined> => {
if (defaults.quantity) {
Expand Down
8 changes: 4 additions & 4 deletions src/bots/cc.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SellCoveredCallsBot extends ITradingBot {
parameter !== null &&
parameter.ccStrategy > 0 &&
// RULE : stock price is higher than previous close
parameter.underlying.livePrice > parameter.underlying.previousClosePrice
parameter.underlying.livePrice > parameter.underlying.previousClosePrice!
) {
this.printObject(parameter);
// RULE defensive : strike > cours (OTM) & strike > position avg price
Expand All @@ -61,7 +61,7 @@ export class SellCoveredCallsBot extends ITradingBot {
lastTradeDate: { [Op.gt]: new Date() },
callOrPut: "C",
delta: {
[Op.lt]: 1 - this.portfolio.ccWinRatio, // RULE : delta < 0.25
[Op.lt]: 1 - this.portfolio.ccWinRatio!, // RULE : delta < 0.25
},
},
include: [
Expand All @@ -87,7 +87,7 @@ export class SellCoveredCallsBot extends ITradingBot {
for (const option of options) {
// const expiry: Date = new Date(option.lastTradeDate);
const diffDays = Math.ceil((option.expiryDate.getTime() - Date.now()) / (1000 * 3600 * 24));
option["yield"] = (option.contract.bid / option.strike / diffDays) * 360;
option["yield"] = (option.contract.bid! / option.strike / diffDays) * 360;
// option.stock.contract = await Contract.findByPk(option.stock.id);
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion,@typescript-eslint/no-non-null-assertion
Expand All @@ -104,7 +104,7 @@ export class SellCoveredCallsBot extends ITradingBot {
ITradingBot.CcOrder(
OrderAction.SELL,
Math.floor(free_for_this_symbol / option.multiplier),
option.contract.ask,
option.contract.ask!,
),
)
.then((orderId: number) => {
Expand Down
10 changes: 5 additions & 5 deletions src/bots/csp.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class SellCashSecuredPutBot extends ITradingBot {
);
// RULE 7: stock price is lower than previous close
const options =
parameter.underlying.livePrice > parameter.underlying.previousClosePrice
parameter.underlying.livePrice > parameter.underlying.previousClosePrice!
? []
: await OptionContract.findAll({
where: {
Expand All @@ -112,7 +112,7 @@ export class SellCashSecuredPutBot extends ITradingBot {
lastTradeDate: { [Op.gt]: new Date() },
callOrPut: OptionType.Put,
delta: {
[Op.gt]: this.portfolio.cspWinRatio - 1, // RULE 3: delta >= -0.2
[Op.gt]: this.portfolio.cspWinRatio! - 1, // RULE 3: delta >= -0.2
},
},
include: [
Expand Down Expand Up @@ -149,7 +149,7 @@ export class SellCashSecuredPutBot extends ITradingBot {
(await this.getTotalBalanceInBase()) +
(await this.getContractPositionValueInBase(this.portfolio.benchmark)) +
(await this.getOptionShortPositionsValueInBase(this.portfolio.benchmark.id, OptionType.Call));
const max_for_all_symbols = invest_base * this.portfolio.putRatio - total_engaged;
const max_for_all_symbols = invest_base * this.portfolio.putRatio! - total_engaged;
console.log(
"max_for_all_symbols:",
max_for_all_symbols,
Expand All @@ -166,11 +166,11 @@ export class SellCashSecuredPutBot extends ITradingBot {
const stock = await StockContract.findByPk(option.stock.id);
if (option.strike * option.multiplier * this.base_rates[option.contract.currency] < max_for_all_symbols) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion,@typescript-eslint/no-non-null-assertion
if (option.impliedVolatility > stock!.historicalVolatility) {
if (option.impliedVolatility! > stock!.historicalVolatility!) {
// RULE 1: implied volatility > historical volatility
// const expiry: Date = new Date(option.lastTradeDate);
const diffDays = Math.ceil((option.expiryDate.getTime() - Date.now()) / (1000 * 3600 * 24));
option["yield"] = (option.contract.bid / option.strike / diffDays) * 360;
option["yield"] = (option.contract.bid! / option.strike / diffDays) * 360;
// option.stock.contract = await Contract.findByPk(option.stock.id);
filtered_options.push(option);
}
Expand Down
8 changes: 4 additions & 4 deletions src/bots/importer.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class ImporterBot extends ITradingBot {
multiplier: '20',
strike: '14780',
expiry: '2023-06-09',
tradeID: '556404027',
tradeID: '55644027',
putCall: 'C',
reportDate: '2023-06-12',
principalAdjustFactor: '',
Expand Down Expand Up @@ -545,7 +545,7 @@ export class ImporterBot extends ITradingBot {
fxRateToBase: '1',
assetCategory: '',
symbol: '',
description: 'DISBURSEMENT INITIATED BY Ronan-Yann Lorin',
description: 'DISBURSEMENT INITIATED BY ***',
conid: '',
securityID: '',
securityIDType: '',
Expand All @@ -567,11 +567,11 @@ export class ImporterBot extends ITradingBot {
commodityType: '',
dateTime: '2023-06-14',
settleDate: '2023-06-14',
amount: '-11914.7',
amount: '-1114.7',
type: 'Deposits/Withdrawals',
tradeID: '',
code: '',
transactionID: '1934082449',
transactionID: '193402449',
reportDate: '2023-06-14',
clientReference: '',
levelOfDetail: 'DETAIL'
Expand Down
Loading

0 comments on commit 0a386de

Please sign in to comment.