Python stock devloper multiclient integration (login order placement )
client_dict={}
def get_client_detail():
global client_dict
try:
csv_path = 'clientdetails.csv'
df = pd.read_csv(csv_path)
df.columns = df.columns.str.strip()
for index, row in df.iterrows():
# Create a nested dictionary for each symbol
symbol_dict = {
'Title': row['Title'],
'Value': row['Value'],
'QtyMultiplier': row['QtyMultiplier'],
'autotrader': None,
}
client_dict[row['Title']] = symbol_dict
# print("client_dict: ", client_dict)
except Exception as e:
print("Error happened in fetching symbol", str(e))
get_client_detail()
def stock_dev_login_multiclient(client_dict):
for value, daram in client_dict.items():
Title = daram['Title']
if isinstance(Title, str):
daram['autotrader']=Stockdeveloper.login(daram['Value'])
print("client_dict: ",client_dict)
stock_dev_login_multiclient(client_dict)
def stockdev_multiclient_orderplacement_sell(basesymbol,client_dict,timestamp,symbol,direction,Stoploss,Target,qty,price, side):
Orderqty=None
for value, daram in client_dict.items():
Title = daram['Title']
if isinstance(Title, str):
Orderqty=qty*daram['QtyMultiplier']
res=Stockdeveloper.regular_order(autotrader=daram["autotrader"],account=daram['Title'], segment="NSE", symbol=symbol,
direction=direction
, orderType="LIMIT", productType='DELIVERY', qty=Orderqty,
price=price)
print(res)
orderlog = (
f"{timestamp} Sell Order executed {side} side {symbol} @ {price},stoploss= {Stoploss}, "
f"target= {Target} : Account = {daram['Title']} ")
print(orderlog)
write_to_order_logs(orderlog)
def stockdev_multiclient_orderplacement_buy(basesymbol,client_dict,timestamp,symbol,direction,Stoploss,Target,qty,price, side):
Orderqty=None
for value, daram in client_dict.items():
Title = daram['Title']
if isinstance(Title, str):
Orderqty=qty*daram['QtyMultiplier']
res=Stockdeveloper.regular_order(autotrader=daram["autotrader"],account=daram['Title'], segment="NSE", symbol=symbol,
direction=direction
, orderType="LIMIT", productType='DELIVERY', qty=Orderqty,
price=price)
print(res)
orderlog = (
f"{timestamp} Buy Order executed {side} side {symbol} @ {price},stoploss= {Stoploss}, "
f"target= {Target} : Account = {daram['Title']} ")
print(orderlog)
write_to_order_logs(orderlog)
def stockdev_multiclient_orderplacement_exit(basesymbol,client_dict,timestamp,symbol,direction,Stoploss,Target,qty,price,log):
Orderqty = None
for value, daram in client_dict.items():
Title = daram['Title']
if isinstance(Title, str):
Orderqty=qty*daram['QtyMultiplier']
Stockdeveloper.regular_order(autotrader=daram["autotrader"],account=daram['Title'], segment="NSE", symbol=symbol,
direction=direction
, orderType="MARKET", productType='DELIVERY', qty=Orderqty,
price=price)
orderlog = (
f"{timestamp} {log} {symbol} @ {price} "
f"target= {Target} : Account = {daram['Title']} ")
print(orderlog)
write_to_order_logs(orderlog)
Comments
Post a Comment