Skip to content

Instantly share code, notes, and snippets.

@arshpreetsingh
Created May 18, 2017 08:13
Show Gist options
  • Save arshpreetsingh/64ab0e2ec661107b4ba27ab27fdf530b to your computer and use it in GitHub Desktop.
Save arshpreetsingh/64ab0e2ec661107b4ba27ab27fdf530b to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# required imports
import requests
class TradeClient(object):
""" Client for tradidng through WebAPI
"""
def __init__(self,PROTOCOL,HOST,PORT):
self.PROTOCOL=PROTOCOL
self.HOST=HOST
self.PORT=PORT
self.URL = "{0:s}://{1:s}:{2:s}/".format(PROTOCOL,HOST,PORT)
def place_order(self,buysell,exchange,dispname,qty,price,dqty,stoploss,order_type,ordterm,account,des,Rquid,rms):
"""sending order to exchange"""
make_url = (self.URL+"/orderentry/buysell={0:s}/exch={1:s}/dispname={2:s}/qty={3:s}/price={4:s}/dqty={5:s}/stoploss={6:s}/ordtype={7:s}/ordterm={8:s}/account={9:s}/des={10:s}/rqid={11:s}/rms={12:s}").format(buysell,exchange,dispname,qty,price,dqty,stoploss,order_type,ordterm,account,des,Rquid,rms)
try:
response = request.post(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def order_status(self,oid):
""" Returns current status(Executed/Pending) of the order"""
make_url = self.URL+"/orderstatus/oid={0:s}".format(oid)
try:
response = request.post(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def update_order(self,oid,qty,price,dqty,order_type=""):
""" Order Modification"""
make_url = self.URL+"/modifyorder/oid={0:s}/qty={1:s}/price={2:s}/dqty={3:s}/ordtype={4:s}".format(oid,qty,price,dqty,ordtype)
try:
response = request.post(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def cancel_order(self,oid):
""" cancel order using order-id"""
make_url = self.URL+"/cancelorder/oid={0:s}".format(oid)
try:
response = request.post(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def track_orders(self,oid):
"""returns tradebook details"""
make_url = self.URL+"/tradebook/oid={0:s}".format(oid)
try:
response = request.post(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def get_rms():
""" returns rms product list"""
make_url = self.URL+"/rmsproducts/"
try:
response = resquest.get(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def scrip_inform():
""" returns script information"""
make_url = self.URL+"/scripinfo/dispname=tnpleq"
try:
response = resquest.get(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def subscr_inform():
""" subscribe script information"""
make_url = self.URL+"/scripinfo/dispname=tnpleq"
try:
response = resquest.get(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
def live_quote(self):
""" returns live quotes"""
make_url = self.URL+"/getquote/dispname=idfceq"
try:
response = resquest.get(make_url)
except requests.exceptions.RequestException as e:
print e
sys.exit(1)
return response
if __name__=='__main__':
t=TradeClient("http","127.0.0.1","8181")
print t
print t.URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment