Remove executor, add buy/sell to Alpaca, move capital allocation to Bot
Replace the Executor logging placeholder with real buy/sell methods on the Alpaca class that place market orders via createOrder and return the fill price. Strategies now receive their capital amount directly and place orders themselves. Bot accepts StrategyAllocation[] to decouple capital allocation from strategy definition. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,15 @@ export interface AlpacaQuote {
|
||||
BidPrice: number;
|
||||
}
|
||||
|
||||
export interface AlpacaOrder {
|
||||
id: string;
|
||||
symbol: string;
|
||||
filled_avg_price: string;
|
||||
filled_qty: string;
|
||||
side: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface AlpacaTrade {
|
||||
p: number; // price
|
||||
s: number; // size
|
||||
@@ -49,6 +58,13 @@ export interface AlpacaClient {
|
||||
getClock(): Promise<AlpacaClock>;
|
||||
getLatestQuote(symbol: string): Promise<AlpacaQuote>;
|
||||
getLatestTrades(symbols: string[]): Promise<Map<string, AlpacaTrade>>;
|
||||
createOrder(order: {
|
||||
symbol: string;
|
||||
notional: number;
|
||||
side: 'buy' | 'sell';
|
||||
type: string;
|
||||
time_in_force: string;
|
||||
}): Promise<AlpacaOrder>;
|
||||
}
|
||||
|
||||
export class Alpaca {
|
||||
@@ -98,5 +114,26 @@ export class Alpaca {
|
||||
public async getLatestTrades(symbols: string[]) {
|
||||
return this.alpaca.getLatestTrades(symbols);
|
||||
}
|
||||
|
||||
|
||||
public async buy(symbol: string, dollarAmount: number): Promise<number> {
|
||||
const order = await this.alpaca.createOrder({
|
||||
symbol,
|
||||
notional: dollarAmount,
|
||||
side: 'buy',
|
||||
type: 'market',
|
||||
time_in_force: 'day',
|
||||
});
|
||||
return parseFloat(order.filled_avg_price);
|
||||
}
|
||||
|
||||
public async sell(symbol: string, dollarAmount: number): Promise<number> {
|
||||
const order = await this.alpaca.createOrder({
|
||||
symbol,
|
||||
notional: dollarAmount,
|
||||
side: 'sell',
|
||||
type: 'market',
|
||||
time_in_force: 'day',
|
||||
});
|
||||
return parseFloat(order.filled_avg_price);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user