@adaptic/utils 0.0.992 → 0.0.993

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/test.js CHANGED
@@ -7999,226 +7999,6 @@ function testScalpingDefaultsLockedIn() {
7999
7999
  log(`Scalping defaults locked in (${expectations.length} fields verified). Full policy:`);
8000
8000
  console.log(JSON.stringify(policy, null, 2));
8001
8001
  }
8002
- // async function testCreateEquitiesTrade() {
8003
- // try {
8004
- // log('Starting createEquitiesTrade test...');
8005
- // // Create credentials using environment variables
8006
- // const credentials: AlpacaCredentials = {
8007
- // accountName: 'test',
8008
- // apiKey: process.env.ALPACA_API_KEY || '',
8009
- // apiSecret: process.env.ALPACA_SECRET_KEY || '',
8010
- // type: 'PAPER',
8011
- // orderType: 'market',
8012
- // engine: 'quant'
8013
- // };
8014
- // if (!credentials.apiKey || !credentials.apiSecret) {
8015
- // throw new Error('ALPACA_API_KEY and ALPACA_SECRET_KEY environment variables must be set');
8016
- // }
8017
- // // Create a new instance of the trading API
8018
- // const alpacaAPI = createAlpacaTradingAPI(credentials);
8019
- // // Get current account details
8020
- // const accountDetails = await alpacaAPI.getAccountDetails();
8021
- // log(`Account equity: $${parseFloat(accountDetails.equity).toFixed(2)}`);
8022
- // log(`Buying power: $${parseFloat(accountDetails.buying_power).toFixed(2)}`);
8023
- // const testSymbols = ['AAPL', 'MSFT', 'GOOGL', 'TSLA', 'NVDA', 'META', 'AMZN']; // Multiple symbols to avoid wash trade detection
8024
- // const referencePrice = 150.00; // Mock reference price for testing
8025
- // log('=== Testing createEquitiesTrade function ===');
8026
- // // Test 1: Simple market order (long position)
8027
- // log('\n1. Testing simple market order (long)...');
8028
- // try {
8029
- // const order1 = await alpacaAPI.createEquitiesTrade(
8030
- // { symbol: testSymbols[0], qty: 1, side: 'buy' }
8031
- // );
8032
- // log(`✅ Created simple market buy order: ${order1.id}`);
8033
- // } catch (error) {
8034
- // log(`❌ Failed to create simple market order: ${error}`);
8035
- // }
8036
- // // Test 2: Simple market order (short position)
8037
- // log('\n2. Testing simple market order (short)...');
8038
- // try {
8039
- // const order2 = await alpacaAPI.createEquitiesTrade(
8040
- // { symbol: testSymbols[1], qty: 1, side: 'sell' }
8041
- // );
8042
- // log(`✅ Created simple market sell order: ${order2.id}`);
8043
- // } catch (error) {
8044
- // log(`❌ Failed to create simple market sell order: ${error}`);
8045
- // }
8046
- // // Test 3: Limit order with percentage-based stop loss (long)
8047
- // log('\n3. Testing limit order with percentage-based stop loss (long)...');
8048
- // try {
8049
- // const order3 = await alpacaAPI.createEquitiesTrade(
8050
- // { symbol: testSymbols[2], qty: 1, side: 'buy', referencePrice },
8051
- // {
8052
- // type: 'limit',
8053
- // limitPrice: 149.50,
8054
- // useStopLoss: true,
8055
- // stopPercent100: 3.0 // 3% stop loss
8056
- // }
8057
- // );
8058
- // log(`✅ Created limit buy order with stop loss: ${order3.id}`);
8059
- // } catch (error) {
8060
- // log(`❌ Failed to create limit order with stop loss: ${error}`);
8061
- // }
8062
- // // Test 4: Limit order with percentage-based take profit (short)
8063
- // log('\n4. Testing limit order with percentage-based take profit (short)...');
8064
- // try {
8065
- // const order4 = await alpacaAPI.createEquitiesTrade(
8066
- // { symbol: testSymbols[3], qty: 1, side: 'sell', referencePrice },
8067
- // {
8068
- // type: 'limit',
8069
- // limitPrice: 150.50,
8070
- // useTakeProfit: true,
8071
- // takeProfitPercent100: 2.5 // 2.5% take profit
8072
- // }
8073
- // );
8074
- // log(`✅ Created limit sell order with take profit: ${order4.id}`);
8075
- // } catch (error) {
8076
- // log(`❌ Failed to create limit order with take profit: ${error}`);
8077
- // }
8078
- // // Test 5: Bracket order with both stop loss and take profit (long)
8079
- // log('\n5. Testing bracket order with both stop loss and take profit (long)...');
8080
- // try {
8081
- // const order5 = await alpacaAPI.createEquitiesTrade(
8082
- // { symbol: testSymbols[4], qty: 1, side: 'buy', referencePrice },
8083
- // {
8084
- // type: 'limit',
8085
- // limitPrice: 149.00,
8086
- // useStopLoss: true,
8087
- // stopPercent100: 4.0, // 4% stop loss
8088
- // useTakeProfit: true,
8089
- // takeProfitPercent100: 6.0 // 6% take profit
8090
- // }
8091
- // );
8092
- // log(`✅ Created bracket order (long): ${order5.id}`);
8093
- // } catch (error) {
8094
- // log(`❌ Failed to create bracket order: ${error}`);
8095
- // }
8096
- // // Test 6: Bracket order with fixed prices (short)
8097
- // log('\n6. Testing bracket order with fixed prices (short)...');
8098
- // try {
8099
- // const order6 = await alpacaAPI.createEquitiesTrade(
8100
- // { symbol: testSymbols[5], qty: 1, side: 'sell' },
8101
- // {
8102
- // type: 'limit',
8103
- // limitPrice: 151.00,
8104
- // useStopLoss: true,
8105
- // stopPrice: 155.00, // Fixed stop price
8106
- // useTakeProfit: true,
8107
- // takeProfitPrice: 145.00 // Fixed take profit price
8108
- // }
8109
- // );
8110
- // log(`✅ Created bracket order with fixed prices (short): ${order6.id}`);
8111
- // } catch (error) {
8112
- // log(`❌ Failed to create bracket order with fixed prices: ${error}`);
8113
- // }
8114
- // // Test 7: Extended hours limit order
8115
- // log('\n7. Testing extended hours limit order...');
8116
- // try {
8117
- // const order7 = await alpacaAPI.createEquitiesTrade(
8118
- // { symbol: testSymbols[6], qty: 1, side: 'buy' },
8119
- // {
8120
- // type: 'limit',
8121
- // limitPrice: 148.00,
8122
- // extendedHours: true
8123
- // }
8124
- // );
8125
- // log(`✅ Created extended hours limit order: ${order7.id}`);
8126
- // } catch (error) {
8127
- // log(`❌ Failed to create extended hours order: ${error}`);
8128
- // }
8129
- // // Test 8: Error condition - market order with extended hours (should fail)
8130
- // log('\n8. Testing error condition - market order with extended hours (should fail)...');
8131
- // try {
8132
- // await alpacaAPI.createEquitiesTrade(
8133
- // { symbol: testSymbols[0], qty: 1, side: 'buy' },
8134
- // {
8135
- // type: 'market',
8136
- // extendedHours: true // This should trigger an error
8137
- // }
8138
- // );
8139
- // log(`❌ Unexpected success - should have failed!`);
8140
- // } catch (error) {
8141
- // log(`✅ Correctly caught error: ${error instanceof Error ? error.message : error}`);
8142
- // }
8143
- // // Test 9: Error condition - missing referencePrice for percentage (should fail)
8144
- // log('\n9. Testing error condition - missing referencePrice for percentage (should fail)...');
8145
- // try {
8146
- // await alpacaAPI.createEquitiesTrade(
8147
- // { symbol: testSymbols[0], qty: 1, side: 'buy' }, // No referencePrice
8148
- // {
8149
- // useStopLoss: true,
8150
- // stopPercent100: 3.0 // Requires referencePrice
8151
- // }
8152
- // );
8153
- // log(`❌ Unexpected success - should have failed!`);
8154
- // } catch (error) {
8155
- // log(`✅ Correctly caught error: ${error instanceof Error ? error.message : error}`);
8156
- // }
8157
- // // Wait a moment for all orders to process
8158
- // await new Promise(resolve => setTimeout(resolve, 2000));
8159
- // // Get all orders to see what was created
8160
- // log('\n=== Checking created orders ===');
8161
- // const orders = await alpacaAPI.getOrders({ status: 'open', limit: 20 });
8162
- // log(`Found ${orders.length} open orders`);
8163
- // orders.forEach((order, index) => {
8164
- // log(`Order ${index + 1}: ${order.order_class} ${order.type} ${order.side} ${order.qty} ${order.symbol} @ $${order.limit_price || 'market'}`);
8165
- // if (order.legs && order.legs.length > 0) {
8166
- // log(` Stop Loss: $${order.legs.find(leg => leg.type === 'stop')?.stop_price || 'N/A'}`);
8167
- // log(` Take Profit: $${order.legs.find(leg => leg.type === 'limit')?.limit_price || 'N/A'}`);
8168
- // }
8169
- // });
8170
- // // Cancel all orders to clean up
8171
- // log('\n=== Cleaning up - canceling all orders ===');
8172
- // await alpacaAPI.cancelAllOrders();
8173
- // log('✅ All orders canceled');
8174
- // log('\n=== Test completed successfully! ===');
8175
- // } catch (error) {
8176
- // log(`❌ Error in createEquitiesTrade test: ${error instanceof Error ? error.message : 'Unknown error'}`);
8177
- // process.exit(1);
8178
- // }
8179
- // }
8180
- // async function testAlpacaWebSocket() {
8181
- // try {
8182
- // log('Starting Alpaca WebSocket test...');
8183
- // // Create credentials using environment variables
8184
- // const credentials: AlpacaCredentials = {
8185
- // accountName: 'test',
8186
- // apiKey: process.env.ALPACA_API_KEY || '',
8187
- // apiSecret: process.env.ALPACA_SECRET_KEY || '',
8188
- // type: 'PAPER',
8189
- // orderType: 'market',
8190
- // engine: 'quant'
8191
- // };
8192
- // if (!credentials.apiKey || !credentials.apiSecret) {
8193
- // throw new Error('ALPACA_API_KEY and ALPACA_SECRET_KEY environment variables must be set');
8194
- // }
8195
- // // Create a new instance of the trading API
8196
- // const alpacaAPI = createAlpacaTradingAPI(credentials); // type AlpacaCredentials
8197
- // // Set up trade update callback
8198
- // alpacaAPI.onTradeUpdate((update: TradeUpdate) => {
8199
- // log(`Received trade update: event ${update.event} for an order to ${update.order.side} ${update.order.qty} of ${update.order.symbol}`);
8200
- // });
8201
- // // Connect to WebSocket
8202
- // alpacaAPI.connectWebsocket(); // necessary to connect to the WebSocket
8203
- // // create an order
8204
- // const order = await alpacaAPI.createMarketOrder('AAPL', 1, 'buy', 'buy_to_open');
8205
- // // cancel the order
8206
- // await alpacaAPI.cancelAllOrders();
8207
- // // Keep the process running
8208
- // log('WebSocket connected and listening for trade updates...');
8209
- // log('Press Ctrl+C to exit');
8210
- // // Keep the process running
8211
- // await new Promise(() => {});
8212
- // } catch (error) {
8213
- // log(`Error in WebSocket test: ${error instanceof Error ? error.message : 'Unknown error'}`);
8214
- // process.exit(1);
8215
- // }
8216
- // }
8217
- // // Run the test
8218
- // testAlpacaWebSocket();
8219
- // Run the createEquitiesTrade test
8220
- //testCreateEquitiesTrade();
8221
- // testing retrieving pre-market data (just 9:00am to 9:30am on 1 july 2025 for SPY) using the market data api
8222
8002
  async function testPreMarketData() {
8223
8003
  try {
8224
8004
  log("Starting pre-market data test for SPY (9:00am-9:30am, July 1, 2025)...");