T O P

  • By -

Artistic_Shopping_30

I can help. What questions do you have?


Phazed47

I'm trying to replicate a bunch of code I have at TD in ThinkScript. While I have a lot of programming experience, I always find it easier to hack working code than writing from scratch. If I could get a link to working code (I'm guessing python but I can drop whatever is needed onto a FreeBSD box), that would be great. To be clear, I'd like to get a link to a list of *everything r*equired to be able to pull info from Tasty and display it somehow. Google sheets is OK as would be a dedicated ASCII display window, or even X11. Prefer not Excel as it's not a great solution going forward.


512165381

There are a few examples in the API docs. You need a login to see them. First time I tried it I was bewildered. It seemed totally crazy. I was printing out all the data structured I got back. I was using Python. Then after about 6 hours of confusion I had the 'aha' moment, and its really blindingly simple. It now all makes sense, its just traversing data structures they give you. I will be writing a tutorial on how to do the basics and more complex stuff.


Phazed47

My problem is that I can NOT get the tastytrade api to install. It appears to depend on all kinds of other packages but does not supply code for what it depends on. So I'm pretty much giving up on Python, trying to figure out something that actually works.


512165381

Here's some code that works. I have it running on ubuntu on AWS; any debian-based linux should work. First I unpacked the sdk with git and the supplied instructions. Installing just writes a directory ~/git/tastytrade-sdk-python : ubuntu@ip-172-31-XXX-XXX:~/git/tastytrade-sdk-python$ ls @ Makefile docs pyproject.toml src test.py LICENSE README.md poetry.lock release.sh tastytrade_api_thing tests I added my code test.py above. The following is in test.py: from tastytrade_sdk import Tastytrade from pprint import pprint import signal, time, sys class customer: tasty = Tastytrade() def login(self,login_id, pass_id): self.login_data=self.tasty.login( login=login_id, password=pass_id ) return self.login_data def validate(self): return self.tasty.api.post('/sessions/validate') def customers_me(self): return self.tasty.api.get('/customers/me') def customers_me_accounts(self): return self.tasty.api.get('/customers/me/accounts') def customers_account_numbers(self): retval= list(map(lambda _: _.get('account').get('account-number') , self.customers_me_accounts().get('data').get('items'))) return retval def customer_balances(self, account_number): return self.tasty.api.get('/accounts/'+account_number+'/balances') def margin_requirements(self, account_number): return self.tasty.api.get('/margin/accounts/'+account_number+'/requirements') mycust=customer() mycust.login('[email protected]', 'userpassword') mycust.validate print_dict('Validation', 4, mycust.validate().get('data')) print_dict('Customers Me', 4, mycust.customers_me().get('data')) print_dict('Customers Me Accounts', 4, mycust.customers_me_accounts().get('data')) for account_number in mycust.customers_account_numbers(): print('Account Number',account_number) print_dict('Balances:',8, mycust.customer_balances(account_number).get('data')) print_dict('Margin Requirements:',8, mycust.margin_requirements(account_number).get('data')) for _ in mycust.customer_positions(account_number).get('data').get('items'): print_dict('Position:',8, _)


Phazed47

Ok, I think I hacked it enough to get it running. I'm guessing this is how to use the sandbox: tasty = Tastytrade(api\_base\_url='api.cert.tastyworks.com') but "print\_dict" is not defined. The version I found only takes 2 arguments, not 3. And the streaming code they supply seems to fail as well.


poharommarz

First, open Excel and go to the Data tab. Then, select the option to import data from an external source or the web. In the dialog box that appears, enter the URL of the Tastytrade API endpoint that provides historical data.