Open ddsaif opened 2 weeks ago
Started working on the same.
I tried to work on the code and the response which, I am receiving right now is this
{
"message": "Error updating ladder",
"error": {
"name": "SequelizeDatabaseError",
"parent": {
"code": "ER_BAD_FIELD_ERROR",
"errno": 1054,
"sqlState": "42S22",
"sqlMessage": "Unknown column 'id' in 'field list'",
"sql": "INSERT INTO ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
"parameters": [
"BUY",
"OPEN",
"721",
788,
true,
"NaN",
"SIMULATION",
12,
0,
0,
0,
"BSE",
9418,
"TCS",
"'Buy&Sell'",
"2024-11-06 05:29:28",
"2024-11-06 05:29:28"
]
},
"original": {
"code": "ER_BAD_FIELD_ERROR",
"errno": 1054,
"sqlState": "42S22",
"sqlMessage": "Unknown column 'id' in 'field list'",
"sql": "INSERT INTO ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
"parameters": [
"BUY",
"OPEN",
"721",
788,
true,
"NaN",
"SIMULATION",
12,
0,
0,
0,
"BSE",
9418,
"TCS",
"'Buy&Sell'",
"2024-11-06 05:29:28",
"2024-11-06 05:29:28"
]
},
"sql": "INSERT INTO ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
"parameters": [
"BUY",
"OPEN",
"721",
788,
true,
"NaN",
"SIMULATION",
12,
0,
0,
0,
"BSE",
9418,
"TCS",
"'Buy&Sell'",
"2024-11-06 05:29:28",
"2024-11-06 05:29:28"
]
}
}
I have not mentioned id anywhere in the code. Not able to understand from where its taking the field id
keep updating your code as well so i can review it.
okay, I will push the code
what is logging in console
PS C:\Users\HP\Desktop\ladder> node server.js
Server is running on http://localhost:3000
Database synced
ladder details here ---- Ladder {
dataValues: {
lad_id: 1283,
lad_user_id: 721,
lad_position_id: 788,
lad_ticker: 'TCS',
lad_name: 1,
lad_status: 'ACTIVE',
lad_ticker_id: 9418,
lad_exchange: 'BSE',
lad_trading_mode: 'SIMULATION',
lad_cash_allocated: 995000,
lad_cash_gain: '-837271.73',
lad_cash_left: 995000,
lad_last_trade_price: 0,
lad_last_trade_order_price: '3420.94',
lad_minimum_price: 0,
lad_extra_cash_generated: '4568.02',
lad_realized_profit: '2199.42',
lad_initial_buy_quantity: 133,
lad_default_buy_sell_quantity: 3,
lad_target_price: 10000,
lad_num_of_steps_above: 44,
lad_num_of_steps_below: 0,
lad_cash_needed: '155636.54',
lad_recent_trade_id: 2584,
createdAt: '03-11-2024 17:40',
updatedAt: '03-11-2024 17:45',
lad_deleted: false,
lad_initial_buy_price: 5000,
lad_current_quantity: 175,
lad_definition_id: 1389,
lad_initial_buy_executed: true,
lad_step_size: '112.79',
lad_extra_cash_left: 0,
lad_reinvest_extra_cash: false,
lad_unsold_stock_cash_gain: '-839471.15',
target_price_multiplier: 2,
continue_trading_after_hitting_target_price: true,
lad_recent_order_id: ''
},
_previousDataValues: {
lad_id: 1283,
lad_user_id: 721,
lad_position_id: 788,
lad_ticker: 'TCS',
lad_name: 1,
lad_status: 'ACTIVE',
lad_ticker_id: 9418,
lad_exchange: 'BSE',
lad_trading_mode: 'SIMULATION',
lad_cash_allocated: 995000,
lad_cash_gain: '-837271.73',
lad_cash_left: 995000,
lad_last_trade_price: 0,
lad_last_trade_order_price: '3420.94',
lad_minimum_price: 0,
lad_extra_cash_generated: '4568.02',
lad_realized_profit: '2199.42',
lad_initial_buy_quantity: 133,
lad_default_buy_sell_quantity: 3,
lad_target_price: 10000,
lad_num_of_steps_above: 44,
lad_num_of_steps_below: 0,
lad_cash_needed: '155636.54',
lad_recent_trade_id: 2584,
createdAt: '03-11-2024 17:40',
updatedAt: '03-11-2024 17:45',
lad_deleted: false,
lad_initial_buy_price: 5000,
lad_current_quantity: 175,
lad_definition_id: 1389,
lad_initial_buy_executed: true,
lad_step_size: '112.79',
lad_extra_cash_left: 0,
lad_reinvest_extra_cash: false,
lad_unsold_stock_cash_gain: '-839471.15',
target_price_multiplier: 2,
continue_trading_after_hitting_target_price: true,
lad_recent_order_id: ''
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [
'lad_id',
'lad_user_id',
'lad_position_id',
'lad_ticker',
'lad_name',
'lad_status',
'lad_ticker_id',
'lad_exchange',
'lad_trading_mode',
'lad_cash_allocated',
'lad_cash_gain',
'lad_cash_left',
'lad_last_trade_price',
'lad_last_trade_order_price',
'lad_minimum_price',
'lad_extra_cash_generated',
'lad_realized_profit',
'lad_initial_buy_quantity',
'lad_default_buy_sell_quantity',
'lad_target_price',
'lad_num_of_steps_above',
'lad_num_of_steps_below',
'lad_cash_needed',
'lad_recent_trade_id',
'createdAt',
'updatedAt',
'lad_deleted',
'lad_initial_buy_price',
'lad_current_quantity',
'lad_definition_id',
'lad_initial_buy_executed',
'lad_step_size',
'lad_extra_cash_left',
'lad_reinvest_extra_cash',
'lad_unsold_stock_cash_gain',
'target_price_multiplier',
'continue_trading_after_hitting_target_price',
'lad_recent_order_id'
]
},
isNewRecord: false
}
Error updating ladder: Error
at Query.run (C:\Users\HP\Desktop\ladder\node_modules\sequelize\lib\dialects\mysql\query.js:52:25)
at C:\Users\HP\Desktop\ladder\node_modules\sequelize\lib\sequelize.js:315:28
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async MySQLQueryInterface.insert (C:\Users\HP\Desktop\ladder\node_modules\sequelize\lib\dialects\abstract\query-interface.js:308:21)
at async Order.save (C:\Users\HP\Desktop\ladder\node_modules\sequelize\lib\model.js:2490:35)
at async Order.create (C:\Users\HP\Desktop\ladder\node_modules\sequelize\lib\model.js:1362:12)
at async withdrawOrAddFundsToLadder (C:\Users\HP\Desktop\ladder\controller\addSubstractController.js:98:13) {
name: 'SequelizeDatabaseError',
parent: Error: Unknown column 'id' in 'field list'
at Packet.asError (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\packets\packet.js:738:17)
at Prepare.execute (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);',
parameters: [
'BUY', 'OPEN',
'721', 788,
true, 'NaN',
'SIMULATION', 12,
0, 0,
0, 'BSE',
9418, 'TCS',
"'Buy&Sell'", '2024-11-06 05:47:39',
'2024-11-06 05:47:39'
]
},
original: Error: Unknown column 'id' in 'field list'
at Packet.asError (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\packets\packet.js:738:17)
at Prepare.execute (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (C:\Users\HP\Desktop\ladder\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);',
parameters: [
'BUY', 'OPEN',
'721', 788,
true, 'NaN',
'SIMULATION', 12,
0, 0,
0, 'BSE',
9418, 'TCS',
"'Buy&Sell'", '2024-11-06 05:47:39',
'2024-11-06 05:47:39'
]
},
sql: 'INSERT INTO ordersnewtable_1
(id
,order_type
,order_status
,order_user_id
,order_position_id
,order_automated
,order_open_price
,order_trading_mode
,order_units
,order_closed_units
,order_cash_gain
,order_realized_profit
,order_exchange
,order_ticker_id
,order_stock_name
,order_follow_up
,createdAt
,updatedAt
) VALUES (DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);',
parameters: [
'BUY', 'OPEN',
'721', 788,
true, 'NaN',
'SIMULATION', 12,
0, 0,
0, 'BSE',
9418, 'TCS',
"'Buy&Sell'", '2024-11-06 05:47:39',
'2024-11-06 05:47:39'
]
}
check your order table is properly available in your database or not
I have resolve the issue the response which i am getting is this { "message": "Ladder updated successfully.", "ladder": { "lad_id": 1283, "lad_user_id": 721, "lad_position_id": 788, "lad_ticker": "TCS", "lad_name": 1, "lad_status": "ACTIVE", "lad_ticker_id": 9418, "lad_exchange": "BSE", "lad_trading_mode": "SIMULATION", "lad_cash_allocated": 995000, "lad_cash_gain": "-837271.73", "lad_cash_left": 995000, "lad_last_trade_price": 0, "lad_last_trade_order_price": "3420.94", "lad_minimum_price": 0, "lad_extra_cash_generated": "4568.02", "lad_realized_profit": "2199.42", "lad_initial_buy_quantity": 133, "lad_default_buy_sell_quantity": 3, "lad_target_price": 10000, "lad_num_of_steps_above": 44, "lad_num_of_steps_below": 0, "lad_cash_needed": "155636.54", "lad_recent_trade_id": 2584, "createdAt": "03-11-2024 17:40", "updatedAt": "03-11-2024 17:45", "lad_deleted": false, "lad_initial_buy_price": 5000, "lad_current_quantity": 175, "lad_definition_id": 1389, "lad_initial_buy_executed": true, "lad_step_size": "112.79", "lad_extra_cash_left": 0, "lad_reinvest_extra_cash": false, "lad_unsold_stock_cash_gain": "-839471.15", "target_price_multiplier": 2, "continue_trading_after_hitting_target_price": true, "lad_recent_order_id": "" } }
Please, Check the response and do let me know weather it is correct or not...
I have updated the code as well.
send request body as well
This is the request body, I am using
{
"lad_id": 1283,
"new_stocks_to_buy": 14,
"new_cash_needed": 123.23,
"new_order_size": 12,
"new_step_size":213
}
send the table on whatsapp as csv
Okay
Nothing is updated in ladder table and there are no order created in the orderTable as well
in ladder table cash needed, order size and step size should be updated for that ladder
And 2 orders should be created in the order table for that ladder id of that user
okay..I will try to make it
Explain to me what does the function do or what are we trying to do here? (It is important for us that we know that we are on the right track, so we know we are building correct thing and don't need to redo things)
Actually, I have discussed this thing with pervez sir yesterday, I want to know the overview of the project. Like what are we doing and on what part i am working on. So he told me to ask you this things. Whenever you are free can you arrange a call on Google meet to make me understand all this things.
Now the orders are getting created. But as you said the orders are wrong can you please check the code in your machine once. Its getting difficult for me can you please do it and make me understand that. I will push the code please check it.
start fresh, make only orders buy or sell with the order size as units and save it in database and nothing else
I have added new file as TestwithdrawOrAddFundsToLadder. Once check will that logic works
const sequelize = require('../config/database'); const Ladder = require('../model/ladderModel'); const dd_orders = require('../model/orderModel');
const withdrawOrAddFundsToLadder = async (req, res) => { const transaction = await sequelize.transaction(); try { const lad_user_id = req.params.id; const { lad_id, new_cash_allocated, new_cash_needed, new_order_size, new_step_size, order_type } = req.body;
if (!lad_id || !lad_user_id) {
return res.status(400).json({ message: "lad_id and lad_user_id are required." });
}
const ladder = await Ladder.findOne({ where: { lad_id, lad_user_id } });
if (!ladder) {
return res.status(404).json({ message: "Ladder not found for the specified user." });
}
ladder.cash_needed = new_cash_needed;
ladder.order_size = new_order_size;
ladder.step_size = new_step_size;
await ladder.save({ transaction });
const currentPrice = ladder.currentPrice;
if (!ladder.lad_position_id) {
return res.status(400).json({ message: "Ladder position ID cannot be null." });
}
const orderData = {
order_type: order_type === "SELL" ? "SELL" : "BUY",
order_status: "OPEN",
order_user_id: lad_user_id,
order_position_id: ladder.lad_position_id,
order_automated: true,
order_open_price: order_type === "SELL" ? currentPrice + ladder.step_size : currentPrice - ladder.step_size,
order_trading_mode: ladder.lad_trading_mode,
order_units: new_order_size,
order_closed_units: 0,
order_cash_gain: 0,
order_realized_profit: 0,
order_exchange: ladder.lad_exchange,
order_ticker_id: ladder.lad_ticker_id,
order_stock_name: ladder.lad_ticker,
order_follow_up: "Buy&Sell",
};
await dd_orders.create(orderData, { transaction });
await transaction.commit();
res.status(200).json({ message: "Order created successfully", ladder });
} catch (error) {
await transaction.rollback();
console.error("Error updating ladder and creating order:", error);
res.status(500).json({ message: "Error updating ladder and creating order", error });
}
};
module.exports = { withdrawOrAddFundsToLadder, };
please checkout this
start fresh, make only orders buy or sell with the order size as units and save it in database and nothing else
try console.log the currentPrice
its getting Current Price: undefined
What will be my today's task?
Work on yesterday's task complete it ASAP.