Bitcoin Forum

Economy => Speculation => Topic started by: M4v3R on January 12, 2012, 10:43:11 PM



Title: Bitcoinica Helper (userscript)
Post by: M4v3R on January 12, 2012, 10:43:11 PM
I've made a small userscript that enhances my Bitcoinica experience, I thought that I could share it with others. I already covered it in a other topic (https://bitcointalk.org/index.php?topic=56797.0), but now that I've added more functionality to it, I think it deserves it's own topic.

What it does:

- Adds the "zhoutonging price" (lowest price your position can handle before it gets liquidated) directly to the UI:

http://dl.dropbox.com/u/1127246/Screenshots/xft5.png

- Adds exchange value to your BTC and USD values when you hover your mouse over these:

http://dl.dropbox.com/u/1127246/Screenshots/d-s-.png

- Enables all quick pick buttons, regardless of your balance. This is for quick picking a value to partly liquidate your position.

How to get it:

The script currently works in Firefox and Google Chrome.

Download this userscript: http://dl.dropbox.com/u/1127246/bitcoinica.user.js (http://dl.dropbox.com/u/1127246/bitcoinica.user.js) (current version: 1.2.2)
- Firefox: When you click on the link, a popup will appear. Wait for "Install" button to activate and click on it. Note: if the popup doesn't appear, it means you don't have Greasemonkey extension installed. You need to install it first to use this script.
- Google Chrome: Drag it onto your browser's window, then accept the installation.
Refresh Bitcoinica tab if necessary.

Happy trading!


Title: Re: Bitcoinica Helper (userscript)
Post by: Mushoz on January 12, 2012, 10:53:39 PM
Source looks safe, and those screenshots are great! Thanks for creating this!


Title: Re: Bitcoinica Helper (userscript)
Post by: Eveofwar on January 12, 2012, 11:19:56 PM
Any way to get this working on Firefox 3.6.25 ?  =]

EDIT: Download and install https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ and then right click the link and click "View User Script Source", a bar at the top of the next tab/window should give the option to install it into Greasemonkey :D

EDIT2:  Script installed, but doesn't seem to change the layout on Bitcoinica for me at all :/


Title: Re: Bitcoinica Helper (userscript)
Post by: rebuilder on January 12, 2012, 11:25:49 PM
Is the limit order working as it's supposed to? Right now the sell price on bitcoinica is around 6.60, and if I place a limit order to sell with 0.40 in the add/substract box, I'd expect to see a sell order for 7 USD, but actually it places an order to sell at 6.2...

edit: it works as I'd expect it to if you input a negative value. Useful, but potentially dangerous IMO, since it seems counterintuitive to me. Still, very nice script, thanks!


Title: Re: Bitcoinica Helper (userscript)
Post by: zhoutong on January 13, 2012, 03:56:30 AM
Is the limit order working as it's supposed to? Right now the sell price on bitcoinica is around 6.60, and if I place a limit order to sell with 0.40 in the add/substract box, I'd expect to see a sell order for 7 USD, but actually it places an order to sell at 6.2...

edit: it works as I'd expect it to if you input a negative value. Useful, but potentially dangerous IMO, since it seems counterintuitive to me. Still, very nice script, thanks!

It's intuitive to me. This feature is designed for price protection, so if you enter 0.4, it means you can tolerate max slippage of 0.4. Then you'd sell at 6.2 as limit order.


Title: Re: Bitcoinica Helper (userscript)
Post by: Maged on January 13, 2012, 05:22:49 AM
any plans to port to firefox?
Change line 14 from:
window.unsafeWindow || (
to:
unsafeWindow.jQuery || (

That appears to work on both browsers, so it should be patched into the main distribution of this.


Title: Re: Bitcoinica Helper (userscript)
Post by: Eveofwar on January 13, 2012, 05:25:40 AM
any plans to port to firefox?
Change line 14 from:
window.unsafeWindow || (
to:
unsafeWindow.jQuery || (

That appears to work on both browsers, so it should be patched into the main distribution of this.

Thanks for this Maged !

M4v3R  -- Let us know when you make these changes happen; I'll re-check Bitcoinica.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 13, 2012, 06:43:15 AM
Is the limit order working as it's supposed to? Right now the sell price on bitcoinica is around 6.60, and if I place a limit order to sell with 0.40 in the add/substract box, I'd expect to see a sell order for 7 USD, but actually it places an order to sell at 6.2...

edit: it works as I'd expect it to if you input a negative value. Useful, but potentially dangerous IMO, since it seems counterintuitive to me. Still, very nice script, thanks!

It's intuitive to me. This feature is designed for price protection, so if you enter 0.4, it means you can tolerate max slippage of 0.4. Then you'd sell at 6.2 as limit order.

That's exactly what I've meant.

any plans to port to firefox?
Change line 14 from:
window.unsafeWindow || (
to:
unsafeWindow.jQuery || (

That appears to work on both browsers, so it should be patched into the main distribution of this.

Thanks for this! I've applied the patch to my script and updated the first post.


Title: Re: Bitcoinica Helper (userscript)
Post by: RandyMarsh on January 13, 2012, 09:54:58 PM
Any reason why this moght not be working?

Im using chrome and just installed, chrome says its enabled but im not getting the changes to bitcoinica.  ???


Title: Re: Bitcoinica Helper (userscript)
Post by: proudhon on January 13, 2012, 10:01:45 PM
Any reason why this moght not be working?

Im using chrome and just installed, chrome says its enabled but im not getting the changes to bitcoinica.  ???

For whatever reason it works on my MacBook but not on my Hackintosh.  Both are running updated versions of Chrome.


Title: Re: Bitcoinica Helper (userscript)
Post by: rebuilder on January 13, 2012, 10:07:55 PM

It's intuitive to me. This feature is designed for price protection, so if you enter 0.4, it means you can tolerate max slippage of 0.4. Then you'd sell at 6.2 as limit order.

OK. I guess I think about it differently. I use limit orders to catch price fluctuations, to sell higher than the current price or to buy lower, and stops to trigger sells or buys if the price goes beyond a given point. That's where my confusion came from. Either way, as long as it's clear how it works, it's a good tool.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 13, 2012, 11:08:04 PM
As I've said, that's my first take on Greasemonkey scripts. I have some issues with function scope, I'll try to deal with them later.


Title: Re: Bitcoinica Helper (userscript)
Post by: Jessi on January 14, 2012, 04:39:41 AM
As I've said, that's my first take on Greasemonkey scripts. I have some issues with function scope, I'll try to deal with them later.
Does not work for me in actual version of chrome. Whatīs wrong?


Title: Re: Bitcoinica Helper (userscript)
Post by: notme on January 14, 2012, 04:42:23 AM
As I've said, that's my first take on Greasemonkey scripts. I have some issues with function scope, I'll try to deal with them later.
Does not work for me in actual version of chrome. Whatīs wrong?

Works fine for me in Chrome.


Title: Re: Bitcoinica Helper (userscript)
Post by: byronbb on January 14, 2012, 07:20:00 AM
As I've said, that's my first take on Greasemonkey scripts. I have some issues with function scope, I'll try to deal with them later.
Does not work for me in actual version of chrome. Whatīs wrong?

Doesn't work for me either. Windows 7 64bit chrome 16.xxxxxxxxxx


Title: Re: Bitcoinica Helper (userscript)
Post by: notme on January 14, 2012, 07:22:33 AM
Correction... a previous version worked... Before I upgraded I just had the min price, but now that's gone too.  Chromium on Linux 64.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 14, 2012, 07:59:08 AM
Ok, I think I've fixed the problem. Everyone please uninstall the extension first and then install it again (link remains unchanged). Should work now.


Title: Re: Bitcoinica Helper (userscript)
Post by: notme on January 14, 2012, 08:02:12 AM
Ok, I think I've fixed the problem. Everyone please uninstall the extension first and then install it again (link remains unchanged). Should work now.

Working.  Thanks!


Title: Re: Bitcoinica Helper (userscript)
Post by: byronbb on January 14, 2012, 08:40:00 AM
Thanks a lot works now.


Title: Re: Bitcoinica Helper (userscript)
Post by: Jessi on January 14, 2012, 02:54:07 PM
Ok, I think I've fixed the problem. Everyone please uninstall the extension first and then install it again (link remains unchanged). Should work now.
Yes, now itīs working for me, too! :) Thank you for your good work!!


Title: Re: Bitcoinica Helper (userscript)
Post by: proudhon on January 14, 2012, 03:03:22 PM
Working for me too on both my machines.  Though, yesterday to test it out I took a small long position that I was pretty sure would get zhoutonged.  Your helper told me the zhoutong price was around 6.39, but my position held until the low 30s.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 14, 2012, 03:39:49 PM
I'm using the calculations posted by zhoutong, so I think they're correct.

There's a small bug in the code though that may affect the result of calculations a bit - it takes only first two digits from the bid/ask price (it's because in the code they are split up to make the rest of digits gray). On small positions this could show up as a visible difference, and you just saw it.

I've fixed that error and pushed a new version. Remember to uninstall the old one, because you can end up with two different versions running at the same time.

EDIT: It's not that easy to actually test that. I've created a 10:1 leveraged 9.5 BTC position (having 1 BTC on account) and here's the result:

http://dl.dropbox.com/u/1127246/Screenshots/7n2k.png

I should've shorted, because I don't think we'll hit 6.2 again :D


Title: Re: Bitcoinica Helper (userscript)
Post by: Zotia on January 16, 2012, 03:30:10 PM
I have a small feature request.  I would like to be able to click on the quantity buttons even if I don't have enough money to buy.  I want this because:
-Sometimes I want to sell using those buttons.
-Sometimes I want to buy more BTC after the price goes up.

Needing to refresh the page or enter the number manually is rather annoying (when those buttons are already there but just grayed out).




I'm using the calculations posted by zhoutong, so I think they're correct

I found your problem.


This:
Code:
			// Long
if (amount > 0)
min_price = Math.round((ask - ((net_value - maintenance)/(amount + btc))) * 100) / 100;

// Short
else
min_price = Math.round((bid - ((net_value - maintenance)/(amount - btc))) * 100) / 100;

Should be this:
Code:
			// Long
if (amount > 0)
min_price = Math.round((bid - ((net_value - maintenance)/(amount + btc))) * 100) / 100;

// Short
else
min_price = Math.round((ask - ((net_value - maintenance)/(amount - btc))) * 100) / 100;

(Notice the change to "bid" and "ask").


It seems to fix it.


To test it to see if it was accurate, I changed it like this:


Code:
			// Long
if (amount > 0)
min_price = (bid - ((net_value - maintenance)/(amount + btc));

// Short
else
min_price = (ask - ((net_value - maintenance)/(amount - btc));
(Notice the removal of "Math.round").


This allowed me to have it display all of the digits it uses.

I tested it for a 10:1 account:

-Manually doing the calculation resulted in 6.665561463414634146341463414635
-Using the test script resulted in 6.665561463414635

So it's accurate to 15 digits.  (By accurate, I mean it yields the same result as doing it manually).



Now that it works correctly, I wanted it to show 4 digits instead of 2, so I changed it like this.

Code:
			// Long
if (amount > 0)
min_price = Math.round((bid - ((net_value - maintenance)/(amount + btc))) * 10000) / 10000;

// Short
else
min_price = Math.round((ask - ((net_value - maintenance)/(amount - btc))) * 10000) / 10000;

(Notice the change from "100" to "10000").




With this change, it will now display the correct minimum price to 4 digits.




PS: Thank you for making this script.  ;D


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 16, 2012, 04:02:17 PM
Wow, thanks for the correction :). I've incorporated the changes into the script. I've also added a function to enable all "quick pick" buttons.


Title: Re: Bitcoinica Helper (userscript)
Post by: Zotia on January 16, 2012, 05:59:09 PM
Wow, thanks for the correction :). I've incorporated the changes into the script. I've also added a function to enable all "quick pick" buttons.

Wow, that was quick!


Thank you!  ;D


Title: Re: Bitcoinica Helper (userscript)
Post by: Maged on January 16, 2012, 07:15:52 PM
Wow, thanks for the correction :). I've incorporated the changes into the script. I've also added a function to enable all "quick pick" buttons.
You forgot to bump the version number in the OP. Don't worry, I did it for you.

Oh, and if you ever need any help on this, I'd be happy to assist you.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 16, 2012, 09:12:30 PM
You forgot to bump the version number in the OP. Don't worry, I did it for you.

Oh, and if you ever need any help on this, I'd be happy to assist you.

Thanks! This is nice about Bitcoin community, everybody tries to help to get better Bitcoin ecosystem :).


Title: Re: Bitcoinica Helper (userscript)
Post by: Zotia on January 18, 2012, 02:26:00 AM
I found another bug.


Sometimes, the BTC/USD prices are updated separately from the panel on the right.  When this happens, the "net value" is based upon a BTC/USD price that was updated at a different time.  This means that the "Min price" will be changed.   The "Min price" should never change.


It actually had a significant effect on the "Min price" today, due to the volatility.  At one point, the value was inaccurate off by over 0.10 BTC/USD.



I'm not sure how this could be fixed.


Title: Re: Bitcoinica Helper (userscript)
Post by: cypherdoc on January 18, 2012, 02:29:02 AM
I found another bug.


Sometimes, the BTC/USD prices are updated separately from the panel on the right.  When this happens, the "net value" is based upon a BTC/USD price that was updated at a different time.  This means that the "Min price" will be changed.   The "Min price" should never change.


It actually had a significant effect on the "Min price" today, due to the volatility.  At one point, the value was inaccurate off by over 0.10 BTC/USD.



I'm not sure how this could be fixed.

wonderful.


Title: Re: Bitcoinica Helper (userscript)
Post by: MelMan2002 on January 18, 2012, 11:20:07 PM
Nice script!


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 23, 2012, 09:28:44 PM
New version of the script

Added feature: shows you how much BTC are your dollars worth and vice-versa, when you hover your mouse over these values:

http://dl.dropbox.com/u/1127246/Screenshots/d-s-.png

Please post some more suggestions how we could improve Bitcoinica and I'll see what I can do :).


Title: Re: Bitcoinica Helper (userscript)
Post by: stochastic on January 23, 2012, 09:35:42 PM
New version of the script

Added feature: shows you how much BTC are your dollars worth and vice-versa, when you hover your mouse over these values:

http://dl.dropbox.com/u/1127246/Screenshots/d-s-.png

Sweet.  Could you add a function calculate the user's current margin call rate?


Title: Re: Bitcoinica Helper (userscript)
Post by: vokain on January 24, 2012, 02:21:33 AM
someone check the code if it doesn't track our positions, anddd donation link/adderss? This is very useful, and I know some appreciative donations would probably incentivize you for improvements too :)


Title: Re: Bitcoinica Helper (userscript)
Post by: Maged on January 24, 2012, 03:31:48 AM
someone check the code if it doesn't track our positions
Done. Version 1.2.0 is completely safe, as of this message.

@M4v3R: You can get rid of line 12-20. Mootools makes unsafeWindow obsolete. I'm glad to see that you moved away from unsafeWindow, though.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on January 24, 2012, 06:55:59 AM
@Maged: Yeah, the code for unsafeWindow is obsolete now. I've also changed "addMootools" function to just "addScript", because it wasn't loading Mootools (I wanted to do that in the first place, but I've changed my mind), just adding the script to main page body. Thanks for the suggestion.


Title: Re: Bitcoinica Helper (userscript)
Post by: elux on February 13, 2012, 10:58:23 AM
Did bitcoinica swaps break the script? I got wrong data and had to disable it.


Title: Re: Bitcoinica Helper (userscript)
Post by: legitnick on February 13, 2012, 11:04:10 AM
Did bitcoinica swaps break the script? I got wrong data and had to disable it.
Yeah my base price is 5.40 and it says my liquidation price is at 5.9 on my long position.


Title: Re: Bitcoinica Helper (userscript)
Post by: waspoza on February 13, 2012, 11:08:25 AM
Did bitcoinica swaps break the script? I got wrong data and had to disable it.

Yup, looks broken to me.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on February 13, 2012, 11:20:47 AM
Yeah, I guess it could break the script if they've changed HTML on the site. I'll look at this later today.


Title: Re: Bitcoinica Helper (userscript)
Post by: MelMan2002 on February 14, 2012, 02:09:08 AM
A quick fix for those interested (not sure if it is complete):
Change line 75 from:
net_value = USER_ParseCurrency(account_data[13].innerHTML);
to:
net_value = USER_ParseCurrency(account_data[15].innerHTML);

and Change line 76 from:
maintenance = USER_ParseCurrency(account_data[15].innerHTML);
to:
maintenance = USER_ParseCurrency(account_data[17].innerHTML);


Title: Re: Bitcoinica Helper (userscript)
Post by: waspoza on February 14, 2012, 09:23:01 AM
A quick fix for those interested (not sure if it is complete):
Change line 75 from:
net_value = USER_ParseCurrency(account_data[13].innerHTML);
to:
net_value = USER_ParseCurrency(account_data[15].innerHTML);

and Change line 76 from:
maintenance = USER_ParseCurrency(account_data[15].innerHTML);
to:
maintenance = USER_ParseCurrency(account_data[17].innerHTML);

Works for me. Thanks!


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on February 14, 2012, 09:31:16 AM
Yeah, that's basically what's needed for script to be fixed. I didn't had access to my desktop computer so I couldn't update the script, but you can do it yourself this way.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on February 18, 2012, 11:34:18 PM
I've updated the script to v1.2.2. Changes:

- Fixed liquidation price (which was broke by swap addition on Bitcoinica)
- Fixed re-enabling amount buttons
- Removed LIMIT order option (it's now directly available on the UI, just click on the crosshair)


Title: Re: Bitcoinica Helper (userscript)
Post by: notme on February 18, 2012, 11:43:30 PM
I've updated the script to v1.2.2. Changes:

- Fixed liquidation price (which was broke by swap addition on Bitcoinica)
- Fixed re-enabling amount buttons
- Removed LIMIT order option (it's now directly available on the UI, just click on the crosshair)

Chrome is giving me "could not read source file".  Same error even after downloading it and opening it from the HD.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on February 18, 2012, 11:55:15 PM
Weird :-\. Works for me, tried just a moment ago.


Title: Re: Bitcoinica Helper (userscript)
Post by: notme on February 19, 2012, 12:23:39 AM
http://tech.shantanugoel.com/2011/09/19/chrome-scriptextension-installation-error-could-not-read-source-file.html

Basically, I had a bitcoinica.user.js in my downloads folder that needed deleted.


Title: Re: Bitcoinica Helper (userscript)
Post by: Mageant on February 25, 2012, 12:33:35 PM
It's a very nice script, thank you.

It doesn't seem to work properly when you have more than one position:
http://mysticora.com/bilder/bitcoinica_helper_with%202_positions.jpg


Title: Re: Bitcoinica Helper (userscript)
Post by: Mushoz on February 25, 2012, 02:14:18 PM
It's a very nice script, thank you.

It doesn't seem to work properly when you have more than one position:
http://mysticora.com/bilder/bitcoinica_helper_with%202_positions.jpg

Multiple positions are possible? How? If I place any orders when I already have an open position, they get added/subtracted to the old position.


Title: Re: Bitcoinica Helper (userscript)
Post by: Mageant on February 25, 2012, 03:07:21 PM
Multiple positions are possible? How? If I place any orders when I already have an open position, they get added/subtracted to the old position.

It only happened to me by "accident", apparently when multiple standing orders were executed within a very short time.


Title: Re: Bitcoinica Helper (userscript)
Post by: M4v3R on February 25, 2012, 03:58:38 PM
Multiple positions are possible? How? If I place any orders when I already have an open position, they get added/subtracted to the old position.

It only happened to me by "accident", apparently when multiple standing orders were executed within a very short time.

This never happened to me before, but should be easy to fix.


Title: Re: Bitcoinica Helper (userscript)
Post by: Otoh on February 26, 2012, 07:49:25 PM
just upgraded to the new improved swaps version, it's great, many thanks :)