I need some assistance with this project.
This project is to automate trading signals from webhooks and onto Tradovate using emulated button clicks. Here’s what it’s supposed to do:
•run js app
•chrome opens, logs in to Tradovate acct
•prints “Awaiting…”, “Node.js server started on port 5000.”
•listens for webhook (using insomnia to emulate)
•POST send JSON to forwarding URL from insomnia, 200 OK
if “order_action” = “buy”, click buy
if “order_action” = “sell”, click sell
Ngrok is running at HTTP 5000 in the background.
Here’s where I’m stuck: The buys and sells are not hitting. No other error messages are made.
I feel the problem may be the following line
app.post( '/', async function( req, res )
I have very little practice with Puppeteer so I’d appreciate any help I can get. Let me know if you have any questions. Thanks!
Here is the code:
import puppeteer from 'puppeteer';
import express from 'express';
const app = express();
app.use( express.json() );
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch(
{headless: false}
);
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://trader.tradovate.com/welcome');
// Set screen size
await page.setViewport({width: 1080, height: 1024});
// Type into search box
await page.type('#name-input', 'XXXXX');
await page.type('#password-input', 'XXXXX');
const login = '.MuiButtonBase-root.MuiButton-root';
//const login = '#onboarding-view-div > div.MuiContainer-root.onboarding-content.main-container.MuiContainer-maxWidthLg > div > div.mb-60 > div > div:nth-child(1) > div > form > button';
await page.waitForSelector(login);
await page.click(login);
//await page.keyboard.press('Enter');
await page.waitForNavigation({
waitUntil: "networkidle0",
})
await page.click("#tm_options > div:nth-child(2) > div > div:nth-child(2) > button");
console.log( 'Awaiting...' )
app.post( '/', async function( req, res ) {
if (req.body.strategy.order_action == 'buy')
{
await page.click("#content > div > div.app-modules > div > div.gm-scroll-view > div > div > div > div:nth-child(1) > div:nth-child(1) > div.lm_items > div > div > div > div.module.chart.chart-wrapper > div.header > div > div > div.gm-scroll-view > div:nth-child(6) > div:nth-child(2) > div:nth-child(1) > div")
await page.click("#none > div.popover-content > div.btn-group-justified.btn-group > div:nth-child(1) > div")
console.log('Buy initiated!')
}
else if (req.body.strategy.order_action == 'sell')
{
await page.click("#content > div > div.app-modules > div > div.gm-scroll-view > div > div > div > div:nth-child(1) > div:nth-child(1) > div.lm_items > div > div > div > div.module.chart.chart-wrapper > div.header > div > div > div.gm-scroll-view > div:nth-child(6) > div:nth-child(2) > div:nth-child(2) > div")
await page.click( "#none > div.popover-content > div.btn-group-justified.btn-group > div:nth-child(1) > div" )
console.log('Sell initiated!')
}
res.sendStatus( 200 );
} );
app.listen( 5000, () => console.log( 'Node.js server started on port 5000.' ) );
})();