Best option for me buy call and
const axios = require('axios');
const API_KEY = 'your-api-key';
const API_SECRET = 'your-api-secret';
const buyStock = async (symbol, qty) => {
try {
const response = await axios.post('https://paper-api.alpaca.markets/v2/orders', {
symbol: symbol,
qty: qty,
side: 'buy',
type: 'market',
time_in_force: 'gtc'
}, {
headers: {
'APCA_API_KEY_ID': API_KEY,
'APCA_API_SECRET_KEY': API_SECRET,
'Content-Type': 'application/json'
}
});
console.log('Buy Order Response:', response.data);
} catch (error) {
console.error('Error buying stock:', error);
}
};
const sellStock = async (symbol, qty) => {
try {
const response = await axios.post('https://paper-api.alpaca.markets/v2/orders', {
symbol: symbol,
qty: qty,
side: 'sell',
type: 'market',
time_in_force: 'gtc'
}, {
headers: {
'APCA_API_KEY_ID': API_KEY,
'APCA_API_SECRET_KEY': API_SECRET,
'Content-Type': 'application/json'
}
});
console.log('Sell Order Response:', response.data);
} catch (error) {
console.error('Error selling stock:', error);
}
};
टिप्पणियाँ
एक टिप्पणी भेजें