bugfixing
This commit is contained in:
parent
3e80d07274
commit
2e5ee52e5b
@ -43,30 +43,36 @@
|
||||
|
||||
let optionQuery = $page.url.searchParams.get("query") || "";
|
||||
|
||||
try {
|
||||
function setDefault() {
|
||||
selectedOptionType = "Call";
|
||||
optionData = data?.getData[selectedOptionType];
|
||||
selectedDate = Object.keys(optionData)[0];
|
||||
strikeList = [...optionData[selectedDate]] || [];
|
||||
if (!strikeList.includes(selectedStrike)) {
|
||||
selectedStrike = strikeList.reduce(
|
||||
(closest, strike) =>
|
||||
Math.abs(strike - currentStockPrice) <
|
||||
Math.abs(closest - currentStockPrice)
|
||||
? strike
|
||||
: closest,
|
||||
strikeList[0],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (optionQuery?.length > 0) {
|
||||
try {
|
||||
const parsedData = parseOptionSymbol(optionQuery);
|
||||
selectedOptionType = parsedData?.optionType;
|
||||
optionData = data?.getData[selectedOptionType];
|
||||
selectedDate = parsedData?.dateExpiration;
|
||||
strikeList = optionData[selectedDate] || [];
|
||||
selectedStrike = parsedData?.strikePrice;
|
||||
} else {
|
||||
}
|
||||
} catch (e) {
|
||||
selectedOptionType = "Call";
|
||||
optionData = data?.getData[selectedOptionType];
|
||||
|
||||
selectedDate = Object?.keys(optionData)[0];
|
||||
strikeList = [...optionData[selectedDate]] || [];
|
||||
if (!strikeList?.includes(selectedStrike)) {
|
||||
selectedStrike = strikeList.reduce((closest, strike) => {
|
||||
return Math.abs(strike - currentStockPrice) <
|
||||
Math.abs(closest - currentStockPrice)
|
||||
? strike
|
||||
: closest;
|
||||
}, strikeList[0]);
|
||||
setDefault();
|
||||
}
|
||||
} else {
|
||||
setDefault();
|
||||
}
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
import { Combobox } from "bits-ui";
|
||||
import InfoModal from "$lib/components/InfoModal.svelte";
|
||||
import Link from "lucide-svelte/icons/square-arrow-out-up-right";
|
||||
import Trash from "lucide-svelte/icons/trash";
|
||||
import { toast } from "svelte-sonner";
|
||||
|
||||
import { mode } from "mode-watcher";
|
||||
import highcharts from "$lib/highcharts.ts";
|
||||
@ -134,6 +136,7 @@
|
||||
}
|
||||
|
||||
await loadData("default");
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
// PAYOFF CALCULATION FUNCTIONS
|
||||
@ -568,8 +571,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// USER INTERACTION FUNCTIONS
|
||||
|
||||
async function handleAddOptionLeg() {
|
||||
if (userStrategy.length === 0) {
|
||||
userStrategy = [
|
||||
@ -590,6 +591,23 @@
|
||||
shouldUpdate = true;
|
||||
}
|
||||
|
||||
function handleDeleteOptionLeg(index) {
|
||||
if (userStrategy?.length === 1) {
|
||||
toast.error("At least one option leg is required!", {
|
||||
style: `border-radius: 5px; background: #fff; color: #000; border-color: ${$mode === "light" ? "#F9FAFB" : "#4B5563"}; font-size: 15px;`,
|
||||
});
|
||||
} else {
|
||||
userStrategy = [
|
||||
...userStrategy.slice(0, index),
|
||||
...userStrategy.slice(index + 1),
|
||||
];
|
||||
if (userStrategy?.length === 0) {
|
||||
changeStrategy(prebuiltStrategy?.at(0));
|
||||
}
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleOptionType() {
|
||||
selectedOptionType = selectedOptionType === "Call" ? "Put" : "Call";
|
||||
await loadData("optionType");
|
||||
@ -1044,18 +1062,30 @@
|
||||
/>
|
||||
</td>
|
||||
<td class="px-4 whitespace-nowrap">
|
||||
<div
|
||||
class="flex flex-row items-center m-auto text-center justify-center"
|
||||
>
|
||||
<a
|
||||
class="inline-block"
|
||||
href={`/${["stocks", "stock"]?.includes(assetType) ? "stocks" : assetType === "etf" ? "etf" : "index"}/${selectedTicker}/options/contract-lookup?query=${optionSymbol}`}
|
||||
class="option-leg-link-to-contract"
|
||||
>
|
||||
<Link
|
||||
class="w-4 h-4 text-gray-800 dark:text-gray-100"
|
||||
class="w-4 h-4 text-gray-800 dark:text-gray-100 mt-0.5"
|
||||
/>
|
||||
</a>
|
||||
<label
|
||||
on:click={() => handleDeleteOptionLeg(index)}
|
||||
class="ml-3 inline-block cursor-pointer"
|
||||
>
|
||||
<Trash
|
||||
class="w-4 h-4 text-gray-800 dark:text-gray-100"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
|
||||
<!--
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => handleAddOptionLeg()}
|
||||
@ -1075,6 +1105,7 @@
|
||||
</svg>
|
||||
Add Option Leg
|
||||
</button>
|
||||
-->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user