Skip to content

Commit

Permalink
updated placeorder brokerorderid fix and placesmartorder openposition…
Browse files Browse the repository at this point in the history
… fix for 5paisa
  • Loading branch information
marketcalls committed Feb 14, 2025
1 parent 1e9b181 commit fbb8e2c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions broker/fivepaisa/api/order_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ def get_holdings(auth):

def get_open_position(tradingsymbol, exchange, Exch,ExchType , producttype,auth):
#Convert Trading Symbol from OpenAlgo Format to Broker Format Before Search in OpenPosition
token = int(get_token(tradingsymbol, exchange)) # Convert token to integer
tradingsymbol = get_br_symbol(tradingsymbol,exchange)
positions_data = get_positions(auth)
print("Token : ",token)
print("Product Type : ",producttype)
print(positions_data)



net_qty = '0'

if positions_data and positions_data.get('body'):
for position in positions_data['body']['NetPositionDetail']:
if position.get('ScripName').upper() == tradingsymbol and position.get('Exch') == Exch and position.get('ExchType') == ExchType and position.get('OrderFor') == producttype:

if position.get('ScripCode') == token and position.get('Exch') == Exch and position.get('ExchType') == ExchType and position.get('OrderFor') == producttype:
net_qty = position.get('NetQty', '0')
break # Assuming you need the first match

Expand Down Expand Up @@ -101,7 +106,7 @@ def place_order_api(data,auth):
response_data = json.loads(res.read().decode("utf-8"))
print(response_data)
if response_data['head']['statusDescription'] == "Success":
orderid = response_data['body']['ExchOrderID']
orderid = response_data['body']['BrokerOrderID']
else:
orderid = None
return res, response_data, orderid
Expand Down Expand Up @@ -323,7 +328,7 @@ def modify_order(data,auth):
response = print(f'The response is {data}')

if data['body']['Message'] == "Success" or data['body']['Message'] == "SUCCESS":
return {"status": "success", "orderid": data["body"]["ExchOrderID"]}, 200
return {"status": "success", "orderid": data["body"]["BrokerOrderID"]}, 200
else:
return {"status": "error", "message": data.get('body', {}).get('Message', 'Failed to Modify order')}, res.status

Expand Down Expand Up @@ -357,4 +362,3 @@ def cancel_all_orders_api(data,auth):
failed_cancellations.append(orderid)

return canceled_orders, failed_cancellations

0 comments on commit fbb8e2c

Please sign in to comment.