tastyware / tastytrade

An unofficial Python SDK for Tastytrade!
MIT License
98 stars 33 forks source link

Complex orders #107

Closed Quenos closed 7 months ago

Quenos commented 7 months ago

Description

Add the possibility to create complex orders:

Also cancel channel has been added to the DXLinkStreamer

Related issue(s)

Fixes: #63

Pre-merge checklist

Please note that, in order to pass the tests, you'll need to set up your Tastytrade credentials as repository secrets on your local fork. Read more at CONTRIBUTING.md.

Graeme22 commented 7 months ago

Please note you can run tests locally with make test; also, you'll need to add your TT credentials as secrets to your repo fork (explained in CONTRIBUTING.md).

Quenos commented 7 months ago

@Graeme22 The tests now run locally, but 95% is not reached. I think this is mainly because streamer.py has a low coverage, but that was not touched.

Graeme22 commented 7 months ago

@Graeme22 The tests now run locally, but 95% is not reached. I think this is mainly because streamer.py has a low coverage, but that was not touched.

It's because you added new code, but no tests for it! If you're not comfortable writing tests, lmk and I'll do it.

Quenos commented 7 months ago

It seems impossible to test the complex orders.

  1. Testing in the certification environment is not possible
  2. Testing with a LIMIT order gives the error that it's not allowed E tastytrade.utils.TastytradeError: preflight_check_failure: One or more preflight checks failed E illegal_buy_and_sell_on_same_symbol: Cannot buy and sell against the same symbol.
  3. Using a MARKET order is possible, but only during market hours, and will buy the stock
  4. To test the OCO you need to have the stock
  5. I tested it with buying stock and it works. However, buying in automated testing is not ideal for obvious reasons
  6. I need to test cancelling orders, because that I might have overseen.
Graeme22 commented 7 months ago

It seems impossible to test the complex orders.

  1. Testing in the certification environment is not possible
  2. Testing with a LIMIT order gives the error that it's not allowed E tastytrade.utils.TastytradeError: preflight_check_failure: One or more preflight checks failed E illegal_buy_and_sell_on_same_symbol: Cannot buy and sell against the same symbol.
  3. Using a MARKET order is possible, but only during market hours, and will buy the stock
  4. To test the OCO you need to have the stock
  5. I tested it with buying stock and it works. However, buying in automated testing is not ideal for obvious reasons
  6. I need to test cancelling orders, because that I might have overseen.

I was able to test successfully in a certification account!

Graeme22 commented 7 months ago

Thanks for this, I went ahead and merged! For a OCO order, you create a NewComplexOrder and pass in two NewOrders to the orders argument; for an OTOCO order, it's the same but you also add another NewOrder as the trigger_order argument, this makes it pretty straightforward.

Appreciate the contributions!

Quenos commented 7 months ago

You're most welcome. Always fun to contribute to this kind of projects. Also good to know that it's running in the certification environment. Need to have a look where I went wrong.

kaidaniel82 commented 7 months ago

Hi Graeme,

i was trying several times using the certification account class. I was not able to place a simpel order. Could you pls provide a code snippet for this.

My API Sandbox account is up and running.

Graeme22 commented 7 months ago

Hi Graeme,

i was trying several times using the certification account class. I was not able to place a simpel order. Could you pls provide a code snippet for this.

My API Sandbox account is up and running.

Is the code example in #63 not working for you?

kaidaniel82 commented 7 months ago

The general usage of the certification class.

Graeme22 commented 7 months ago

The general usage of the certification class.

Just make a certification session, here's the docs on that: https://tastyworks-api.readthedocs.io/en/latest/sessions.html

kaidaniel82 commented 7 months ago

Its working as expected. I was running into an Issue because I never got filled due to using a realistic! market price on a symbol.

Sandbox Environment The base url for all sandbox api endpoints is api.cert.tastyworks.com The websocket url for account streamer updates is streamer.cert.tastyworks.com Orders in the sandbox environment all remain within the sandbox system. They never go to a real market. Orders statuses in the sandbox system are all determined by the order type and order price. The logic is as follows: Market orders will be Live and never fill. Day orders with a price <= $3 will fill immediately. Day orders with a price between >= $3 will be Live and never fill. You are logged in as xyz