def get_positions(self):
        temp_header = Setting()
        self.Headers = temp_header.headers()
        self.POSITIONS_URL = "{}/v2/positions".format(self.BASE_URL)

        r = requests.get(self.POSITIONS_URL, headers=self.Headers)
        return json.loads(r.content)
	def create_order_withmargin(self,symbol,qty,side,type,time_in_force,limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None, trail_price=None, trail_percent=None):
		temp_header=Setting()
		self.Headers=temp_header.headers()
		self.ORDERS_URL="{}/v2/orders".format(self.BASE_URL)
		data={
		"symbol":symbol,
		"qty":qty,
		"side":side,
		"type":type,
		"time_in_force":time_in_force,
		"limit_price":limit_price,
		"stop_price":stop_price, 
		"client_order_id":client_order_id,
		"order_class":order_class, 
		"take_profit":take_profit, 
		"stop_loss":stop_loss, 
		"trail_price":trail_price, 
		"trail_percent":trail_percent
		}
		r=requests.post(self.ORDERS_URL,json=data,headers=self.Headers)
		return json.loads(r.content)

# x=Transaction(userid="1234userid")
# y=x.create_order_withoutmargin("AAPL",1,"buy","market","gtc")
# print(y)
 def get_account(self):
     temp_header = Setting()
     self.Headers = temp_header.headers()
     ACCOUNT_URL = "{}/v2/account".format(self.BASE_URL)
     r = requests.get(ACCOUNT_URL, headers=self.Headers)
     return json.loads(r.content)
     print(r.content)
	def create_order_withoutmargin(self,symbol,qty,side,type,time_in_force,limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None, trail_price=None, trail_percent=None):
		ch_buy=self.check_buy(qty,symbol)
		# print(ch_buy)
		# return ch_buy
		if(ch_buy):
			temp_header=Setting()
			self.Headers=temp_header.headers()
			self.ORDERS_URL="{}/v1/orders".format(self.BASE_URL)
			data={
			"symbol":symbol,
			"qty":qty,
			"side":side,
			"type":type,
			"time_in_force":time_in_force,
			"limit_price":limit_price,
			"stop_price":stop_price, 
			"client_order_id":client_order_id,
			"order_class":order_class, 
			"take_profit":take_profit, 
			"stop_loss":stop_loss, 
			"trail_price":trail_price, 
			"trail_percent":trail_percent
			}
			try:
				r=requests.post(self.ORDERS_URL,json=data,headers=self.Headers)
				return json.loads(r.content)
			except:
				return "invalid parameters"
		else:
			return "Current equity is less than the order placed"
Exemplo n.º 5
0
 def bought_sell_orders(self,query,limit=None):
     self.ORDERS_URL="{}/v2/orders?status=all".format(self.BASE_URL,limit)
     temp_header=Setting()
     self.Headers=temp_header.headers()
     r=requests.get(self.ORDERS_URL,headers=self.Headers)
     bought = json.loads(r.content)
     # print(bought,"bought")
     self.temp_list = []
     
     
     for values in bought:
         if(values['side']==query and values['status']=='filled'):
             self.temp_dict = {}
             polygonDetails = self.polygonAssetDetails(values["symbol"])
             alpacaDetails = self.alpacaAssetDetails(values["symbol"])
             self.temp_dict["symbol"] = values["symbol"]
             self.temp_dict["symbolimage"] = polygonDetails["logo"]
             self.temp_dict["qty"] = values["qty"]
             self.temp_dict['filled_avg_price'] = values['filled_avg_price']
             self.temp_dict['side'] = values['side']
             self.temp_dict['name'] = alpacaDetails['assets']['name']
             self.temp_dict['exchange'] = alpacaDetails['assets']['exchange']
             
             # print(alpacaDetails)
             self.temp_list.append(self.temp_dict)
     if limit==None:
         return self.temp_list
         
     elif (limit==0):
         return self.temp_list[0]
     
     else:
         return self.temp_list[0:limit]
Exemplo n.º 6
0
 def get_orders(self,limit=None):
     self.ORDERS_URL="{}/v2/orders".format(self.BASE_URL)
     temp_header=Setting()
     self.Headers=temp_header.headers()
     r = requests.get(self.ORDERS_URL,headers=self.Headers)
     pending = json.loads(r.content)
     self.temp_list = []
     # print(pending)
     for values in pending:
         self.temp_dict = {}
         self.temp_dict["symbol"] = values["symbol"]
         polygonDetails = self.polygonAssetDetails(values["symbol"])
         alpacaDetails = self.alpacaAssetDetails(values["symbol"])
         self.temp_dict["symbolimage"] = polygonDetails["logo"]
         self.temp_dict["qty"] = values["qty"]
         self.temp_dict["id"] = values["id"]
         self.temp_dict['filled_avg_price'] = values['filled_avg_price']
         self.temp_dict['side'] = values['side']
         self.temp_dict['name'] = alpacaDetails['assets']['name']
         self.temp_dict['exchange'] = alpacaDetails['assets']['exchange']
         
         # print(alpacaDetails)
         self.temp_list.append(self.temp_dict)
     if(limit!=None):
         return self.temp_list[0:limit]
     else:
         return self.temp_list
Exemplo n.º 7
0
    def specific_get_position(self, ticker):
        self.POSITIONS_URL = "{}/v2/positions/{}".format(self.BASE_URL, ticker)
        temp_header = Setting()
        self.Headers = temp_header.headers()
        r = requests.get(self.POSITIONS_URL, headers=self.Headers)
        return json.loads(r.content)


# x=Positions_data(userid="1234userid")

# y=x.specific_get_position("AAPL")
# print(y)
    def get_account_activites(self):
        temp_header = Setting()
        self.Headers = temp_header.headers()
        ACCOUNT_URL = "{}/v2/account/activities".format(self.BASE_URL)
        r = requests.get(ACCOUNT_URL, headers=self.Headers)
        return json.loads(r.content)
        print(r.content)


# x = AccountData(userid="1234userid")
# y=x.get_account()
# x.get_account_activites()
# print(y['equity'])
    def get_positions_ticker(self, tickername):
        self.tickername = tickername
        temp_header = Setting()
        self.Headers = temp_header.headers()
        self.POSITIONS_URL = "{}/v2/positions/{}".format(
            self.BASE_URL, self.tickername)

        r = requests.get(self.POSITIONS_URL, headers=self.Headers)
        return json.loads(r.content)


# x=Stocks_value(userid="1234userid")
# y=x.get_positions_ticker(tickername="AAPL")
# print(y)
    def list_details(self):
        temp_header = Setting()
        self.Headers = temp_header.headers()
        ASSET_URL = "{}/v2/assets/{}".format(self.BASE_URL, self.tickername)
        r = requests.get(ASSET_URL, headers=self.Headers)
        data1 = json.loads(r.content)
        # return json.loads(r.content)
        Clock_URL = "{}/v2/clock".format(self.BASE_URL)
        r1 = requests.get(Clock_URL, headers=self.Headers)
        data2 = json.loads(r1.content)
        self.temp_dict["assets"] = data1
        self.temp_dict["clock"] = data2
        # print(r1.content)
        return self.temp_dict


# x = AlpacaAssetDetails("AAPL")
# y = x.list_details()
# print(y)
Exemplo n.º 11
0
 def specific_get_order(self,orderid):
     self.ORDERS_URL="{}/v2/orders/{}".format(self.BASE_URL,orderid)
     temp_header=Setting()
     self.Headers=temp_header.headers()
     r=requests.get(self.ORDERS_URL,headers=self.Headers)
     return json.loads(r.content)