Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colocation option when buying #27

Merged
merged 18 commits into from
Oct 15, 2024
13 changes: 13 additions & 0 deletions src/lib/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface SfBuyOptions {
start?: string;
yes?: boolean;
quote?: boolean;
colocate?: Array<string>;
}

export function registerBuy(program: Command) {
Expand All @@ -56,6 +57,12 @@ export function registerBuy(program: Command) {
"Specify the start date. Can be a date, relative time like '+1d', or the string 'NOW'",
)
.option("-y, --yes", "Automatically confirm the order")
.option(
"-colo, --colocate <contracts_to_colocate_with>",
"Colocate with existing contracts",
(value) => value.split(","),
[],
)
.option("--quote", "Only provide a quote for the order")
.action(buyOrderAction);
}
Expand All @@ -76,6 +83,8 @@ async function buyOrderAction(options: SfBuyOptions) {
return logAndQuit(`Invalid duration: ${options.duration}`);
}

const colocateWithContractIds = options.colocate ? options.colocate : [];

// default to 1 node if not specified
const accelerators = options.accelerators ? Number(options.accelerators) : 1;

Expand Down Expand Up @@ -233,6 +242,7 @@ async function buyOrderAction(options: SfBuyOptions) {
endsAt: endDate,
confirmWithUser,
quoteOnly: isQuoteOnly,
colocate_with: colocateWithContractIds,
});
const confirmed = await confirm({
message: confirmationMessage,
Expand All @@ -254,6 +264,7 @@ async function buyOrderAction(options: SfBuyOptions) {
endsAt: endDate,
confirmWithUser,
quoteOnly: isQuoteOnly,
colocate_with: colocateWithContractIds,
});

const order = await waitForOrderToNotBePending(res.id);
Expand Down Expand Up @@ -366,6 +377,7 @@ type BuyOptions = {
durationSeconds: number;
confirmWithUser: boolean;
quoteOnly: boolean;
colocate_with: Array<string>;
};
export async function placeBuyOrder(
options: Omit<BuyOptions, "durationSeconds">,
Expand All @@ -383,6 +395,7 @@ export async function placeBuyOrder(
: roundStartDate(options.startsAt).toISOString(),
end_at: options.endsAt.toISOString(),
price: options.priceCents,
colocate_with: options.colocate_with,
},
});

Expand Down
Loading