Skip to content

Commit 04fc121

Browse files
committed
Bug fix
1 parent 3782ade commit 04fc121

File tree

11 files changed

+109
-190
lines changed

11 files changed

+109
-190
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
},
1919
"typescript.enablePromptUseWorkspaceTsdk": true,
2020
"typescript.tsdk": "./node_modules/typescript/lib",
21-
"js/ts.implicitProjectConfig.target": "ESNext"
21+
"js/ts.implicitProjectConfig.target": "ESNext",
22+
"[xml]": {
23+
"editor.defaultFormatter": "redhat.vscode-xml"
24+
}
2225
}

src/app/components/Layout/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Flex, Link, Spinner } from "@chakra-ui/react";
2-
import React from "react";
2+
import React, { FunctionComponent } from "react";
33
import { useNavigation } from "react-router-dom";
44
import NavBar from "../../components/NavBar/NavBar";
55
import links from "../../links";
@@ -8,7 +8,7 @@ interface LayoutProps {
88
children: React.ReactNode;
99
}
1010

11-
const Layout: React.FunctionComponent<LayoutProps> = ({ children, ..._rest }): React.ReactNode => {
11+
const Layout: FunctionComponent<LayoutProps> = ({ children, ..._rest }): React.ReactNode => {
1212
const navigation = useNavigation();
1313
return (
1414
<>

src/app/components/Portfolio/Setting/SettingEdit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const SettingEdit: FunctionComponent<Props> = ({ ..._rest }): React.ReactNode =>
9898
CSP Delta:
9999
</Text>
100100
<Text w="200px">
101-
<Field name="ccDelta" type="number" />
101+
<Field name="cspDelta" type="number" />
102102
</Text>
103103
</Flex>
104104
<Flex justifyContent="center" gap="2">

src/app/components/Portfolio/Setting/SettingShow.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,13 @@ const SettingShow: FunctionComponent<SettingShowProps> = ({ ..._rest }): React.R
4040
{thisItem.lookupDays}
4141
</Text>
4242
</Flex>
43-
<Flex justifyContent="center" gap="2">
44-
<Text w="180px" as="b" textAlign="right">
45-
NAV Ratio:
46-
</Text>
47-
<Number textAlign="left" w="120px" value={thisItem.navRatio} isPercent color={"-"} />
48-
</Flex>
4943
<Flex justifyContent="center" gap="2">
5044
<Text w="180px" as="b" textAlign="right">
5145
Premium:
5246
</Text>
5347
<Number textAlign="left" w="120px" value={thisItem.minPremium} decimals={2} color={"-"} />
5448
</Flex>
49+
5550
<Flex justifyContent="center" gap="2">
5651
<Text w="180px" as="b" textAlign="right">
5752
CSP strat.:
@@ -60,6 +55,12 @@ const SettingShow: FunctionComponent<SettingShowProps> = ({ ..._rest }): React.R
6055
{cspStrategy2String(thisItem.cspStrategy)}
6156
</Text>
6257
</Flex>
58+
<Flex justifyContent="center" gap="2">
59+
<Text w="180px" as="b" textAlign="right">
60+
NAV Ratio:
61+
</Text>
62+
<Number textAlign="left" w="120px" value={thisItem.navRatio} isPercent color={"-"} />
63+
</Flex>
6364
<Flex justifyContent="center" gap="2">
6465
<Text w="180px" as="b" textAlign="right">
6566
CSP delta:
@@ -74,6 +75,7 @@ const SettingShow: FunctionComponent<SettingShowProps> = ({ ..._rest }): React.R
7475
{strategy2String(thisItem.rollPutStrategy)}
7576
</Text>
7677
</Flex>
78+
7779
<Flex justifyContent="center" gap="2">
7880
<Text w="180px" as="b" textAlign="right">
7981
Covered calls strat.:

src/app/components/Portfolio/Setting/SettingsTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const SettingsTable: FunctionComponent<Props> = ({ content, ..._rest }): React.R
3232
<Td>Prem.</Td>
3333
<Td>CSP strat.</Td>
3434
<Td>Ratio</Td>
35+
<Td>CSP delta</Td>
3536
<Td>CSP Roll</Td>
3637
<Td>CC strat.</Td>
3738
<Td>CC delta</Td>

src/bots/index.ts

Lines changed: 34 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,143 +1027,43 @@ export class ITradingBot extends EventEmitter {
10271027
theta?: number | null;
10281028
} = {};
10291029
marketData.forEach((tick, type: TickType) => {
1030-
if (tick.value)
1031-
if (type == IBApiTickType.LAST || type == IBApiTickType.DELAYED_LAST) {
1032-
dataset.price = (tick.value as number) > 0 ? tick.value : null;
1033-
} else if (type == IBApiTickType.BID || type == IBApiTickType.DELAYED_BID) {
1034-
dataset.bid = (tick.value as number) > 0 ? tick.value : null;
1035-
} else if (type == IBApiTickType.ASK || type == IBApiTickType.DELAYED_ASK) {
1036-
dataset.ask = (tick.value as number) > 0 ? tick.value : null;
1037-
} else if (type == IBApiTickType.CLOSE || type == IBApiTickType.DELAYED_CLOSE) {
1038-
dataset.previousClosePrice = (tick.value as number) > 0 ? tick.value : null;
1039-
} else if (
1040-
[
1041-
IBApiTickType.BID_SIZE,
1042-
IBApiTickType.ASK_SIZE,
1043-
IBApiTickType.LAST_SIZE,
1044-
IBApiTickType.OPEN,
1045-
IBApiTickType.HIGH,
1046-
IBApiTickType.LOW,
1047-
IBApiTickType.VOLUME,
1048-
IBApiTickType.HALTED,
1049-
IBApiTickType.DELAYED_BID_SIZE,
1050-
IBApiTickType.DELAYED_ASK_SIZE,
1051-
IBApiTickType.DELAYED_LAST_SIZE,
1052-
IBApiTickType.DELAYED_OPEN,
1053-
IBApiTickType.DELAYED_HIGH,
1054-
IBApiTickType.DELAYED_LOW,
1055-
IBApiTickType.DELAYED_VOLUME,
1056-
].includes(type as IBApiTickType)
1057-
) {
1058-
// siliently ignore
1059-
// console.log('silently ignored', type, tick);
1060-
} else if (type == IBApiNextTickType.OPTION_PV_DIVIDEND) {
1061-
optdataset.pvDividend = tick.value;
1062-
} else if (type == IBApiNextTickType.LAST_OPTION_PRICE || type == IBApiNextTickType.DELAYED_LAST_OPTION_PRICE) {
1063-
if (!dataset.price) {
1064-
dataset.price = (tick.value as number) > 0 ? tick.value : null;
1065-
}
1066-
} else if (type == IBApiNextTickType.LAST_OPTION_DELTA) {
1067-
if (tick.value) {
1068-
optdataset.delta = tick.value;
1069-
}
1070-
// console.log("delta (last):", optdataset.delta, tick.value);
1071-
} else if (type == IBApiNextTickType.LAST_OPTION_GAMMA) {
1072-
if (tick.value) {
1073-
optdataset.gamma = tick.value;
1074-
}
1075-
} else if (type == IBApiNextTickType.LAST_OPTION_VEGA) {
1076-
if (tick.value) {
1077-
optdataset.vega = tick.value;
1078-
}
1079-
} else if (type == IBApiNextTickType.LAST_OPTION_THETA) {
1080-
if (tick.value) {
1081-
optdataset.theta = tick.value;
1082-
}
1083-
} else if (type == IBApiNextTickType.LAST_OPTION_IV) {
1084-
if (tick.value) {
1085-
optdataset.impliedVolatility = tick.value;
1086-
}
1087-
// } else if (type == IBApiNextTickType.MODEL_OPTION_PRICE) {
1088-
// if (!dataset.price && (tick.value as number) > 0) {
1089-
// dataset.price = tick.value;
1090-
// }
1091-
} else if (type == IBApiNextTickType.MODEL_OPTION_IV) {
1092-
if (!optdataset.impliedVolatility && (tick.value as number) > 0) {
1093-
optdataset.impliedVolatility = tick.value;
1094-
}
1095-
} else if (type == IBApiNextTickType.MODEL_OPTION_DELTA) {
1096-
if (!optdataset.delta && tick.value) {
1097-
optdataset.delta = tick.value;
1098-
}
1099-
// console.log("delta (model):", optdataset.delta, tick.value);
1100-
} else if (type == IBApiNextTickType.MODEL_OPTION_GAMMA) {
1101-
if (!optdataset.gamma && tick.value) {
1102-
optdataset.gamma = tick.value;
1103-
}
1104-
} else if (type == IBApiNextTickType.MODEL_OPTION_VEGA) {
1105-
if (!optdataset.vega && tick.value) {
1106-
optdataset.vega = tick.value;
1107-
}
1108-
} else if (type == IBApiNextTickType.MODEL_OPTION_THETA) {
1109-
if (!optdataset.theta && tick.value) {
1110-
optdataset.theta = tick.value;
1111-
}
1112-
} else if (
1113-
[
1114-
// would it be interesting to use OPTION_UNDERLYING to update underlying?
1115-
IBApiNextTickType.OPTION_UNDERLYING,
1116-
IBApiNextTickType.BID_OPTION_IV,
1117-
IBApiNextTickType.BID_OPTION_PRICE,
1118-
IBApiNextTickType.BID_OPTION_DELTA,
1119-
IBApiNextTickType.BID_OPTION_GAMMA,
1120-
IBApiNextTickType.BID_OPTION_VEGA,
1121-
IBApiNextTickType.BID_OPTION_THETA,
1122-
IBApiNextTickType.ASK_OPTION_IV,
1123-
IBApiNextTickType.ASK_OPTION_PRICE,
1124-
IBApiNextTickType.ASK_OPTION_DELTA,
1125-
IBApiNextTickType.ASK_OPTION_GAMMA,
1126-
IBApiNextTickType.ASK_OPTION_VEGA,
1127-
IBApiNextTickType.ASK_OPTION_THETA,
1128-
IBApiNextTickType.MODEL_OPTION_PRICE, // ?
1129-
// Would be interesting to use delayed data if no live data available
1130-
IBApiNextTickType.DELAYED_BID_OPTION_IV,
1131-
IBApiNextTickType.DELAYED_BID_OPTION_PRICE,
1132-
IBApiNextTickType.DELAYED_BID_OPTION_DELTA,
1133-
IBApiNextTickType.DELAYED_BID_OPTION_GAMMA,
1134-
IBApiNextTickType.DELAYED_BID_OPTION_VEGA,
1135-
IBApiNextTickType.DELAYED_BID_OPTION_THETA,
1136-
IBApiNextTickType.DELAYED_ASK_OPTION_IV,
1137-
IBApiNextTickType.DELAYED_ASK_OPTION_PRICE,
1138-
IBApiNextTickType.DELAYED_ASK_OPTION_DELTA,
1139-
IBApiNextTickType.DELAYED_ASK_OPTION_GAMMA,
1140-
IBApiNextTickType.DELAYED_ASK_OPTION_VEGA,
1141-
IBApiNextTickType.DELAYED_ASK_OPTION_THETA,
1142-
IBApiNextTickType.DELAYED_LAST_OPTION_IV,
1143-
IBApiNextTickType.DELAYED_LAST_OPTION_DELTA,
1144-
IBApiNextTickType.DELAYED_LAST_OPTION_GAMMA,
1145-
IBApiNextTickType.DELAYED_LAST_OPTION_VEGA,
1146-
IBApiNextTickType.DELAYED_LAST_OPTION_THETA,
1147-
IBApiNextTickType.DELAYED_MODEL_OPTION_IV,
1148-
IBApiNextTickType.DELAYED_MODEL_OPTION_PRICE,
1149-
IBApiNextTickType.DELAYED_MODEL_OPTION_DELTA,
1150-
IBApiNextTickType.DELAYED_MODEL_OPTION_GAMMA,
1151-
IBApiNextTickType.DELAYED_MODEL_OPTION_VEGA,
1152-
IBApiNextTickType.DELAYED_MODEL_OPTION_THETA,
1153-
].includes(type as IBApiNextTickType)
1154-
) {
1155-
// siliently ignore
1156-
// console.log("silently ignored", type, tick);
1157-
} else {
1158-
console.log("ignored", type, tick);
1159-
}
1030+
// if (tick.value !== null)
1031+
if (type == IBApiTickType.LAST || type == IBApiTickType.DELAYED_LAST) {
1032+
dataset.price = tick.value;
1033+
} else if (type == IBApiTickType.BID || type == IBApiTickType.DELAYED_BID) {
1034+
dataset.bid = tick.value;
1035+
} else if (type == IBApiTickType.ASK || type == IBApiTickType.DELAYED_ASK) {
1036+
dataset.ask = tick.value;
1037+
} else if (type == IBApiTickType.CLOSE || type == IBApiTickType.DELAYED_CLOSE) {
1038+
// if (contract.secType == SecType.STK) console.log("CLOSE", tick.value);
1039+
if (tick.value !== null) dataset.previousClosePrice = tick.value;
1040+
} else if (type == IBApiNextTickType.OPTION_PV_DIVIDEND) {
1041+
optdataset.pvDividend = tick.value;
1042+
} else if (type == IBApiNextTickType.MODEL_OPTION_PRICE) {
1043+
dataset.price = tick.value;
1044+
} else if (type == IBApiNextTickType.MODEL_OPTION_DELTA) {
1045+
optdataset.delta = tick.value;
1046+
} else if (type == IBApiNextTickType.MODEL_OPTION_GAMMA) {
1047+
optdataset.gamma = tick.value;
1048+
} else if (type == IBApiNextTickType.MODEL_OPTION_VEGA) {
1049+
optdataset.vega = tick.value;
1050+
} else if (type == IBApiNextTickType.MODEL_OPTION_THETA) {
1051+
optdataset.theta = tick.value;
1052+
} else if (type == IBApiNextTickType.MODEL_OPTION_IV) {
1053+
optdataset.impliedVolatility = tick.value;
1054+
// } else if (type == IBApiNextTickType.MODEL_OPTION_PRICE) {
1055+
// if (!dataset.price && (tick.value as number) > 0) {
1056+
// dataset.price = tick.value;
1057+
// }
1058+
}
11601059
});
1060+
// if (contract.secType == SecType.STK) console.log("Updating", contract.symbol, dataset);
11611061
// GBP prices are in pences, fix it
11621062
if (contract.currency == "GBP" && contract.secType != SecType.CASH) {
1163-
if (dataset.ask) dataset.ask /= 100;
1164-
if (dataset.bid) dataset.bid /= 100;
1165-
if (dataset.price) dataset.price /= 100;
1166-
if (dataset.previousClosePrice) dataset.previousClosePrice /= 100;
1063+
if (dataset.ask !== null) dataset.ask /= 100;
1064+
if (dataset.bid !== null) dataset.bid /= 100;
1065+
if (dataset.price !== null) dataset.price /= 100;
1066+
if (dataset.previousClosePrice !== null) dataset.previousClosePrice /= 100;
11671067
}
11681068
let price: number | null = null;
11691069
if (dataset.ask && dataset.bid) price = (dataset.ask + dataset.bid) / 2;

0 commit comments

Comments
 (0)