Skip to content

Commit 769dedf

Browse files
authored
Merge pull request #488 from mw66/fix_order
fix: only del stop_price when trigger != "stop"; honor account_number in orders_url and option_orders_url
2 parents 10b3ed3 + bde74fa commit 769dedf

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

robin_stocks/robinhood/orders.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from robin_stocks.robinhood.urls import *
99

1010
@login_required
11-
def get_all_stock_orders(info=None):
11+
def get_all_stock_orders(info=None, account_number=None):
1212
"""Returns a list of all the orders that have been processed for the account.
1313
1414
:param info: Will filter the results to get a specific value.
@@ -17,13 +17,13 @@ def get_all_stock_orders(info=None):
1717
a list of strings is returned where the strings are the value of the key that matches info.
1818
1919
"""
20-
url = orders_url()
20+
url = orders_url(account_number=account_number)
2121
data = request_get(url, 'pagination')
2222
return(filter_data(data, info))
2323

2424

2525
@login_required
26-
def get_all_option_orders(info=None):
26+
def get_all_option_orders(info=None, account_number=None):
2727
"""Returns a list of all the option orders that have been processed for the account.
2828
2929
:param info: Will filter the results to get a specific value.
@@ -32,7 +32,7 @@ def get_all_option_orders(info=None):
3232
a list of strings is returned where the strings are the value of the key that matches info.
3333
3434
"""
35-
url = option_orders_url()
35+
url = option_orders_url(account_number=account_number)
3636
data = request_get(url, 'pagination')
3737
return(filter_data(data, info))
3838

@@ -242,13 +242,13 @@ def cancel_crypto_order(orderID):
242242

243243

244244
@login_required
245-
def cancel_all_stock_orders():
245+
def cancel_all_stock_orders(account_number=None):
246246
"""Cancels all stock orders.
247247
248248
:returns: The list of orders that were cancelled.
249249
250250
"""
251-
url = orders_url()
251+
url = orders_url(account_number=account_number)
252252
data = request_get(url, 'pagination')
253253

254254
data = [item for item in data if item['cancel'] is not None]
@@ -261,13 +261,13 @@ def cancel_all_stock_orders():
261261

262262

263263
@login_required
264-
def cancel_all_option_orders():
264+
def cancel_all_option_orders(account_number=None):
265265
"""Cancels all option orders.
266266
267267
:returns: Returns the order information for the orders that were cancelled.
268268
269269
"""
270-
url = option_orders_url()
270+
url = option_orders_url(account_number=account_number)
271271
data = request_get(url, 'pagination')
272272

273273
data = [item for item in data if item['cancel_url'] is not None]
@@ -768,7 +768,7 @@ def order_trailing_stop(symbol, quantity, side, trailAmount, trailType='percenta
768768
else:
769769
payload['trailing_peg'] = {'type': 'percentage', 'percentage': str(percentage)}
770770

771-
url = orders_url()
771+
url = orders_url(account_number=account_number)
772772
data = request_post(url, payload, json=True, jsonify_data=jsonify)
773773

774774
return (data)
@@ -856,7 +856,8 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe
856856
}
857857
# adjust market orders
858858
if orderType == 'market':
859-
del payload['stop_price']
859+
if trigger != "stop":
860+
del payload['stop_price']
860861
# if market_hours == 'regular_hours':
861862
# del payload['extended_hours']
862863

@@ -872,7 +873,7 @@ def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_numbe
872873
payload['type'] = 'limit'
873874
payload['quantity']=int(payload['quantity']) # round to integer instead of fractional
874875

875-
url = orders_url()
876+
url = orders_url(account_number=account_number)
876877
# print(payload)
877878
data = request_post(url, payload, jsonify_data=jsonify)
878879

@@ -1004,7 +1005,7 @@ def order_option_spread(direction, price, symbol, quantity, spread, account_numb
10041005
'ref_id': str(uuid4()),
10051006
}
10061007

1007-
url = option_orders_url()
1008+
url = option_orders_url(account_number=account_number)
10081009
data = request_post(url, payload, json=True, jsonify_data=jsonify)
10091010

10101011
return(data)
@@ -1067,7 +1068,7 @@ def order_buy_option_limit(positionEffect, creditOrDebit, price, symbol, quantit
10671068
'ref_id': str(uuid4()),
10681069
}
10691070

1070-
url = option_orders_url()
1071+
url = option_orders_url(account_number=account_number)
10711072
# print(payload)
10721073
data = request_post(url, payload, json=True, jsonify_data=jsonify)
10731074

@@ -1134,7 +1135,7 @@ def order_buy_option_stop_limit(positionEffect, creditOrDebit, limitPrice, stopP
11341135
'ref_id': str(uuid4()),
11351136
}
11361137

1137-
url = option_orders_url()
1138+
url = option_orders_url(account_number=account_number)
11381139
data = request_post(url, payload, json=True, jsonify_data=jsonify)
11391140

11401141
return(data)
@@ -1199,7 +1200,7 @@ def order_sell_option_stop_limit(positionEffect, creditOrDebit, limitPrice, stop
11991200
'ref_id': str(uuid4()),
12001201
}
12011202

1202-
url = option_orders_url()
1203+
url = option_orders_url(account_number=account_number)
12031204
data = request_post(url, payload, json=True, jsonify_data=jsonify)
12041205

12051206
return(data)
@@ -1262,7 +1263,7 @@ def order_sell_option_limit(positionEffect, creditOrDebit, price, symbol, quanti
12621263
'ref_id': str(uuid4()),
12631264
}
12641265

1265-
url = option_orders_url()
1266+
url = option_orders_url(account_number=account_number)
12661267
data = request_post(url, payload, json=True, jsonify_data=jsonify)
12671268

12681269
return(data)

0 commit comments

Comments
 (0)