Comments (9)
I don't think "legs" has to do with stop losses or anything. More likely (I'm guessing, but it makes much more sense to me) is it refers to the "legs" of a multi-option strategy, such as a spread or iron condor, etc.
If stop losses/limits etc are possible with options through the API, that's amazing and would be best. Barring that, a goal of mine is to write code to "fake" all my desired advanced orders ... things like trailing stops, bracket orders, stop losses on options, etc. Just fake it by listening to the quotes and triggering a buy or sell if it meets my conditions.
from algotrader.
Thanks for bringing this up! It's been a while since I worked on the options API, but I forgot to fully integrate the ability to add limit/stop orders. As of now, I think only limit orders are accepted by Robinhood when trading options, but I could be wrong.
It looks like I worked on this at one point, but I'll keep looking at this along with #10 to try and complete the options API.
from algotrader.
from algotrader.
Closing this for now as it seems like stop loss orders aren't possible through Robinhood as of now. If any new information is found regarding this I can take a second look.
from algotrader.
@aashidham
I'm trying to place option order using Python api (see jmfernandes/robin_stocks#7). Could you post an example payload? I'm trying to figure out what ref_id is.
Thanks!
from algotrader.
Happy to help as much as I can,
- Here is an example request:
https://github.com/Ladinn/algotrader/blob/8f1971ddff81fe62e7d1df9ebc62267a2486513c/objects/broker/robinhood/OptionOrder.js#L107 - Here is an example response:
Submitting a new option order returns the same response as fetching your past orders, so this will look similar to your new order requests. I'm assuming that id
and ref_id
are used to uniquely identify option orders within Robinhood's database, but I'm not sure where the difference between the two lies.
from algotrader.
@Ladinn
Thanks for your help. I tried to place an option order but was not successful. I'm new to javascript so I'm sure I did something wrong. Could you take a look at the code below and let me know what I'm doing wrong?
myUser.authenticate()
.then(() => {
// User was authenticated
// First, we'll get the instrument and tradable expiration dates for SPY.
Instrument.getBySymbol("SPY").then(ins => {
OptionInstrument.getExpirations(myUser, ins).then(option => {
// Next, we'll fetch an option chain for the upcoming expiration date.
OptionInstrument.getChain(myUser, ins, option[0], "put").then(optionChain => {
console.log(optionChain[4]);
// An array of OptionInstruments will be returned. See the example below.
// You'll then want to find the specific OptionInstrument that you want to trade.
// In this example, we'll buy using the first element in the array.
let order = new OptionOrder(null, myUser, optionChain[4], "credit", "gtc", "buy", "market", 1);
order.submit().then(res => {
// Order was submitted, the response will be parsed as a completed OptionOrder.
console.log("Order submitted");
console.log(res);
});
})
})
});
})
.catch(error => {
// Either the request failed, or Robinhood responded with an error.
// (Ex: you don't have internet access or your user credentials were incorrect)
})
I get the following error message
OptionInstrument {
url: 'https://api.robinhood.com',
tradability: 'tradable',
strikePrice: 260,
state: 'active',
type: 'put',
symbol: 'SPY',
minTicks: { cutoff_price: '0.00', below_tick: '0.01', above_tick: '0.01' },
instrumentURL: 'https://api.robinhood.com/options/instruments/487f72f2-b797-4016-8ff7-8dd172029808/',
ids:
{ chain: 'c277b118-58d9-4060-8dc5-a3b5898955cb',
option: '487f72f2-b797-4016-8ff7-8dd172029808' },
dates:
{ expiration: 2019-03-04T00:00:00.000Z,
created: 2019-01-25T03:08:09.376Z,
updated: 2019-01-25T03:08:09.376Z } }
(node:25477) UnhandledPromiseRejectionWarning: Error: Robinhood responded with code 500 | <h1>Server Error (500)</h1>
> Please report all unexpected errors on GitHub: https://git.io/vpYYL
at Function.handleResponse (/home/briansp/node_modules/algotrader/objects/broker/robinhood/Robinhood.js:23:11)
at Request.request.post [as _callback] (/home/briansp/node_modules/algotrader/objects/broker/robinhood/OptionOrder.js:98:22)
at Request.self.callback (/home/briansp/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/home/briansp/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/home/briansp/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
(node:25477) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25477) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Server error 500 is the same error message I'm getting from the python api. If I change "gtc" to "GTC" as shown in the example in readme, I get 400 error along with the following error message.
(node:25697) UnhandledPromiseRejectionWarning: Error: Robinhood responded with code 400.
{
"time_in_force": [
"\"GTC\" is not a valid choice."
]
}
Any ideas? I'd like to get the option order placement working using this API before trying to get the python API working. Any help would be appreciated.
Thanks!
from algotrader.
I'm getting the same error. Thanks for letting me know- it looks like they must have changed something since this was working when I last tested it.
Opening a new issue and troubleshooting this today.
from algotrader.
This worked for me. Everything is correct. All you have to do is dump string in the payload using: data=json.dumps(payload)
session.post("https://api.robinhood.com/options/orders/", data=json.dumps(payload), timeout=15)
My payload is:
payload = {"account" : account_url,
"direction" : "debit",
"time_in_force" : "gtc",
"legs" : [{'position_effect' : 'open', 'side' : 'buy', 'ratio_quantity' : 1, 'option': iurl}],
"type" : "limit",
"trigger" : "immediate",
"price" : float(price),
"quantity" : int(count),
"override_day_trade_checks" : False,
"override_dtbp_checks" : False,
'ref_id' : str(uuid.uuid4())}
from algotrader.
Related Issues (20)
- Open to a TypeScript conversion? HOT 1
- "request" package deprecation as of February 2020
- This version of Robinhood is no longer supported? HOT 1
- Is it possible to collect Metatrader data? HOT 1
- support for alphavantage too many requests error message HOT 1
- Issue with getHistoricals HOT 2
- Missing Auth in the Instrument.getFundamentals
- Support for fractional shares
- 3.0 release milestone HOT 1
- Robinhood Auth Issues HOT 1
- How are you connecting to rh? HOT 1
- IEX token HOT 1
- Portfoilo#getStockValue does not supply a user.
- binance exchange support
- XTB Broker
- Support for indian brokers
- Unable to complete downloading from Robinhood HOT 2
- Can't seem to sign in properly.
- Robinhood responded with code 401: unauthorized. { "detail": "Incorrect authentication credentials." }
- An alternative to this library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algotrader.