finished initial backtest / engine
This commit is contained in:
parent
55b4ca78c9
commit
c106a719e8
18 changed files with 1571 additions and 180 deletions
|
|
@ -74,7 +74,10 @@ export abstract class BaseStrategy extends EventEmitter {
|
|||
|
||||
// Market data handling
|
||||
async onMarketData(data: MarketData): Promise<void> {
|
||||
if (!this.isActive) return;
|
||||
if (!this.isActive) {
|
||||
logger.info(`[BaseStrategy] Strategy ${this.config.id} received market data but is not active`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Update any indicators or state
|
||||
|
|
@ -210,20 +213,27 @@ export abstract class BaseStrategy extends EventEmitter {
|
|||
// Check if we already have a position
|
||||
const currentPosition = this.getPosition(signal.symbol);
|
||||
|
||||
// Use quantity from signal metadata if provided
|
||||
const quantity = signal.metadata?.quantity || this.calculatePositionSize(signal);
|
||||
|
||||
logger.info(`[BaseStrategy] Converting signal to order: ${signal.type} ${quantity} ${signal.symbol}, current position: ${currentPosition}`);
|
||||
|
||||
// Simple logic - can be overridden by specific strategies
|
||||
if (signal.type === 'buy' && currentPosition <= 0) {
|
||||
if (signal.type === 'buy') {
|
||||
// Allow buying to open long or close short
|
||||
return {
|
||||
symbol: signal.symbol,
|
||||
side: 'buy',
|
||||
quantity: this.calculatePositionSize(signal),
|
||||
quantity: quantity,
|
||||
orderType: 'market',
|
||||
timeInForce: 'DAY'
|
||||
};
|
||||
} else if (signal.type === 'sell' && currentPosition >= 0) {
|
||||
} else if (signal.type === 'sell') {
|
||||
// Allow selling to close long or open short
|
||||
return {
|
||||
symbol: signal.symbol,
|
||||
side: 'sell',
|
||||
quantity: this.calculatePositionSize(signal),
|
||||
quantity: quantity,
|
||||
orderType: 'market',
|
||||
timeInForce: 'DAY'
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue