jmfernandes / robin_stocks

This is a library to use with Robinhood Financial App. It currently supports trading crypto-currencies, options, and stocks. In addition, it can be used to get real time ticker information, assess the performance of your portfolio, and can also get tax documents, total dividends paid, and more. More info at
http://www.robin-stocks.com
MIT License
1.74k stars 468 forks source link

crypto orders skewed cost basis #176

Open kotdadabong opened 4 years ago

kotdadabong commented 4 years ago

on app i can buy at 47 and the cost basis is 47. in code, i buy at 47 and cost basis is 47.22. i can sell and do again on app and same deal, its correct on app, wrong if done via code. i check the order and the expense is correct and the executed price is what it should be, but cost basis is out of range somehow. i can even make a trade in idle and see the wrong numbers show on my phone. not sure whats going on but someone should be aware of it i suppose

solarplex commented 4 years ago

Are you using order_buy_crypto_by_quantity or order_buy_crypto_by_price?

Actually looks like for both it uses Round_Price which looks to round the price to either 2, 4 or 6 decimal places while Robinhood allows 8 decimal places for bitcoin shares.

I'm wondering if that's the case.

kotdadabong commented 4 years ago

i entered exactly this in python3 idle environment in the terminal just to weed out my bad code:

import robin-stocks as r r.login() reciept=r.orders.buy_crypto_limit('LTC',.212,47,'gtc') print(reciept)

it will say ive paid 47 for my portion (not total price, the rate is 47) on the reciept, and the amount spent will be correct. its not cheating money or anything. the math is correct.

however when going into the details of the now currently held position, the avg price will be arbitrarily higher than what it really is. the test case told me my avg rate was 47.22 but my order confirmation said differently. once you check the details page against the info contained in it is where the math turns up wrong. ill check the other ways to buy here in a sec and let you know.

tldr: app works flawlessly. code makes trade flawlessly but presents inaccurate information about the position held, despite the transaction history being correct. the inaccuracy is verifiable in the app. checking other 2 methods now

kotdadabong commented 4 years ago

and now for some reason im unable to replicate the issue. ill see what i can come up with. i went step by step screenshotting but it worked as it should so perhaps it is something about the rounding like you said. especially when after looking at my code, the limit buy has a few rounds in the arguments as well. ill try simplifying the code and see if i can better pinpoint the issue Screenshot from 2020-10-09 20-29-25

kotdadabong commented 4 years ago

ok i thought i was crazy but im not. heres the screenshot. i used crypto limit order, and for good measure i simplified the arguments before passing them into the fxn but to no avail. as seen, the avg cost is over 49$ although the last order placed says 48.85. the quantities match up, thats the only order on the books. if done in their app, no issues. but in using code, its not cheating me out of anything, just presenting false data and even passing it into THEIR system

kotdadabong commented 4 years ago

2020-10-09-223121_1824x984_scrot