From 605f9988157cccffe7d8a570ba587c0dc52b9db9 Mon Sep 17 00:00:00 2001 From: artin Date: Mon, 17 Jul 2023 16:31:14 +0000 Subject: [PATCH] moved sl. added trade check before order --- index.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 77669b7..e54dc9d 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ const client = new pg.Client({ client.connect() -const port = 5000 +const port = 3000 const host = "0.0.0.0" @@ -140,14 +140,15 @@ async function order(acct_id, api_key, instrument, quantity) { try { - let dist = "0.001" - let pdist = "0.001" + let dist = "0.0005" + let pdist = "0.0005" if (instrument.includes("JPY")) { - dist = "0.1" - pdist = "0.1" + dist = "0.05" + pdist = "0.05" } + data = { "order": { "trailingStopLossOnFill": { @@ -383,13 +384,17 @@ app.get('/trailingStop/:instrument', async (req, res) => { }) app.get('/tradesByInstrument/:instrument', async (req, res) => { res.header('Access-Control-Allow-Origin', '*') - res.json(await getTradesByInstrument(ACCT, APIKEY, req.params.instrument)) +r = {}; + for (account of Object.keys(accounts)) { + r[account] = await getTradesByInstrument(accounts[account]['ACCT'], accounts[account]['APIKEY'], req.params.instrument); + } + res.json(r); }) app.get('/order/:instrument/:quantity', async (req, res) => { r = {}; - /*td = await getTradesByInstrument(accounts['1']['ACCT'], accounts['1']['APIKEY'], req.params.instrument); + /*td = await getTradesByInstrument(accounts['2']['ACCT'], accounts['1']['APIKEY'], req.params.instrument); if (td) { if (td["initialUnits"] != req.params.quantity) { @@ -397,10 +402,10 @@ app.get('/order/:instrument/:quantity', async (req, res) => { if (req.params.instrument.includes("JPY")) { let dist = "0.5" } - await takeProfit(accounts['1']['ACCT'], accounts['1']['APIKEY'], td["id"], dist) + await takeProfit(accounts['2']['ACCT'], accounts['1']['APIKEY'], td["id"], dist) } } else { - response = await order(accounts['1']['ACCT'], accounts['1']['APIKEY'], req.params.instrument, req.params.quantity); + response = await order(accounts['2']['ACCT'], accounts['1']['APIKEY'], req.params.instrument, req.params.quantity); }*/ /*td = await getTradesByInstrument(accounts['2']['ACCT'], accounts['2']['APIKEY'], req.params.instrument); if (td) { @@ -418,6 +423,7 @@ app.get('/order/:instrument/:quantity', async (req, res) => { response = await order(accounts['2']['ACCT'], accounts['2']['APIKEY'], req.params.instrument, req.params.quantity); } */ for (account of Object.keys(accounts)) { + td = await getTradesByInstrument(accounts[account]['ACCT'], accounts[account]['APIKEY'], req.params.instrument); response = await order(accounts[account]['ACCT'], accounts[account]['APIKEY'], req.params.instrument, req.params.quantity); }