Bitcoin Forum
May 04, 2024, 12:35:47 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: goxtool bot: stop loss (optionally trailing stop)  (Read 5119 times)
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 22, 2013, 06:38:38 PM
Last edit: April 24, 2013, 07:00:18 PM by prof7bit
 #1

Many have asked for it, here is my first attempt:
https://gist.github.com/prof7bit/5437131
(please test and report bugs, will update the code if needed)

STOP_PRICE is the price at which you want to sell (value is in USD or EUR or any other Fiat), if the value is negative it will enable trailing stop mode and it is interpreted as a price difference (enter for example -12.5 here if you want to trail the stop $12.50 below the highest price (highest since strategy (re)loaded).

STOP_VOLUME is the value in BTC to sell when the stop is triggered. It will trigger only once, after it has been triggered you need to reload strategy ("l" key)

as usual: newest version of goxtool is needed, save as _stoploss.py and start gotool with

./goxtool --strategy=_stoploss.py --protocol=websocket --use-http

Messages will be visible in goxtool.log, use tail and grep to follow them in realtime.

Also the usual disclaimer applies: read and understand the code before running it (otherwise don't run it) and since you have read and understood what it will do in every detail before you decided to run it I cannot be held responsible for anything that results from your decisions.


1714782947
Hero Member
*
Offline Offline

Posts: 1714782947

View Profile Personal Message (Offline)

Ignore
1714782947
Reply with quote  #2

1714782947
Report to moderator
"I'm sure that in 20 years there will either be very large transaction volume or no volume." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
c0inbuster
Member
**
Offline Offline

Activity: 105
Merit: 10



View Profile WWW
April 22, 2013, 08:13:26 PM
Last edit: April 22, 2013, 08:54:08 PM by c0inbuster
 #2

Thanks for your SL / TS strategy.

But I think it will fail when doing this

BTCUSD price is 100
You set SL to 90 and run goxtool
Price falls to 89 so your strategy will sell 0.01
you reboot your computer (I reboot my Raspberry daily)
Price is still 89
goxtool automatically start (this will be my default settings)
You will sell again 0.01 !!!
I think you should store data in a file !

The problem is with flag self.already_executed
it shouldn't be in your strategy code... but in a file (ini, json, yaml...)

when initializing strategy if already_executed is true, send a debug
message to warm user that SL is disable.

I did something similar with Metatrader 4 (using MQL code)
it was a Stop Loss / Trailing Stop / Take Profit on trader side (stealth SL).
I wasn't using a file to store data but "global variables"
http://docs.mql4.com/globals

see for a Metatrader EA for Stealth SL
http://iticsoftware.com/expert-advisor-virtual-stoploss
(it's quite similar to mine but they are storing data, neither in a file,
neither a "global variable" (in MQL4 term) but on a textbox on chart

and a critism of this concept
http://www.onestepremoved.com/stealth-stop-and-take-profit/



I also have a little comment about "BTC" string...
maybe it could be a good idea to hide this.
gox.cur1 instead will be better as MtGox was supposed to also support LTC.
I will also replace gox.currency by gox.cur2

an other comment about "1E8"
In my mind this kind of constant should be in the strategy...
8 is number of digits of symbol BTCUSD or BTCEUR


moreover according to
https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)
I also wont if  int(STOP_VOLUME * 1e8) shouldn't be replaced by
long(round(STOP_VOLUME * 1e8))

Download free softwares! - crypto mining profit calculator - crypto triangular arbitrage tools - crypto stocks tools...
https://sites.google.com/site/working4coins/
dutt
Member
**
Offline Offline

Activity: 135
Merit: 10



View Profile WWW
April 24, 2013, 06:15:54 AM
 #3

Just what I was looking for, thanks.

prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 24, 2013, 06:59:53 PM
 #4

Update regarding streaming api reliability and new server:

Since the reliability of the servers and the different available protocols changes almost daily I need to update my recommendation for how to start goxtool to have the highest reliability, especially for a stop loss this is important. I'm also going to update it in post #1.

Since yesterday the new websocket server went online at mtgox which turns out to work great (much better than socketio) the most reliable way to run the stoploss bot (or any other strategy) without dangerous disconnects is now the following:
Code:
./goxtool.py --protocol=websocket --use-http --strategy=_stoploss.py
And also as usual keep goxtool up to date, git pull at least once a day.

supert
Full Member
***
Offline Offline

Activity: 160
Merit: 100



View Profile
April 26, 2013, 12:07:55 PM
 #5

Code:
./goxtool.py --protocol=websocket --use-http

Is this the use_plain_old_websocket=True in the ini file or something else?

Can this be put in the ini file?
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 26, 2013, 12:15:33 PM
 #6

Code:
./goxtool.py --protocol=websocket --use-http

Is this the use_plain_old_websocket=True in the ini file or something else?

Can this be put in the ini file?

Yes, this is the same option. I admit that the name of this option is slightly confusing, it was added before the command line options were added and at one time there even existed a 3rd protocol that was not selecable via ini file at all, eventually I will clean up this mess and make it more intuitive but that has low priority for now.

wilfried
Sr. Member
****
Offline Offline

Activity: 288
Merit: 250


ManualMiner


View Profile
April 27, 2013, 10:00:14 AM
 #7

hy, i just started goxtool first time, is there a main thread for goxtool?
btw i use centos 6.4, for whom it interests, this howto works perfectly to get the
minimum required python version 2.7 onto centos without ruining your os:
http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
also you need to pip install pccryptp
Thx for goxtools, already love it Smiley
dwolfman
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile WWW
April 30, 2013, 12:45:57 PM
 #8

How long does this need to run before it does anything?  Haven't seen it make a trade after just a few minutes running.

Wanna send coins my way? 1BY2rZduB9j8Exa4158QXPFJoJ2NWU1NGf or just scan the QR code in my avatar.  :-)
dwolfman
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile WWW
April 30, 2013, 01:30:17 PM
 #9

Never mind, re-read the source code and figured it out.

No trades actually happen until the price hits the trigger.  For some reason I thought this would create a trade that would wait for the price to get there, like the rebalancer does.

Wanna send coins my way? 1BY2rZduB9j8Exa4158QXPFJoJ2NWU1NGf or just scan the QR code in my avatar.  :-)
prof7bit (OP)
Hero Member
*****
Offline Offline

Activity: 938
Merit: 500


https://youengine.io/


View Profile WWW
April 30, 2013, 04:50:42 PM
 #10

For some reason I thought this would create a trade that would wait for the price to get there, like the rebalancer does.

Yes, its just a simple stoploss ;-) And it doesn't even have a user interface, the text editor is basically your user interface to this strategy, you edit the constants at the top of the file, save the file and then in goxtool press "l" to reload. Then you have a sell stop at the specified price, waiting there as long as its running and you can sleep well, knowing it will sell immediately once it reaches the stop price.

I'm personally not using any stop oders at the moment myself but a a lot of people have asked for such a thing so I quickly implemented one. The code also serves as a simple example for using the strategy feature of goxtool. A more advanced version of this stop strategy could be made to allow defining multiple stops in both directions (buy or sell) and also persist its state to disk so it would not accidentally fire twice after a restart.

DonBit
Member
**
Offline Offline

Activity: 69
Merit: 10



View Profile
May 01, 2013, 08:52:40 PM
Last edit: May 18, 2013, 05:17:53 AM by DonBit
 #11

Keep it up the good work prof7bit! Donating 0.1 BTC, see goxtool's main thread.

I made some changes to this bot (new changes updated on 05/18/2013).
This fork is now located at https://gist.github.com/dkgeorge/5603198

  • Added start gain
  • Added ability to set or change stop loss/start gain orders during runtime. No need to edit files or reload strategy (very useful)! (press s to open stop loss dialog or press g to open start gain dialog)
  • Added autofilling full wallet amount for stop loss (BTC wallet) and start gain (FIAT wallet). Select 0 for volumes to use full wallet amount
  • For easier start gain, volume setting is in FIAT, not BTC (for start gain only)
  • Automatically selects to stop loss when there is at least 0.01 BTC in wallet (minimum Mt. Gox amount for trading) and only selects start gain when BTC wallet is empty and FIAT is filled with any amount
  • Actively informs in goxtools's debug dialog, stop loss or start gain enablement and order filling status. Great to remind you when the bot is enabled and how was the order filled
  • NEW!  Informs Mt.Gox charged fee for Stop loss/Start gain filled order

Note: This fork removed trailing stop feature from the original code






These are just some features that were in my needs that I wanted to share. This is my first attempt to deal with bots, so please feel free for any comments or suggestion.
Use it wisely and enjoy Grin

-DonBit

1DonBitkTdvCtt8ZC5UDdBh3c1axrvXHbP
Aido
Sr. Member
****
Offline Offline

Activity: 248
Merit: 250


1. Collect underpants 2. ? 3. Profit


View Profile
May 21, 2013, 10:39:51 PM
 #12

Hi,

  • Added autofilling full wallet amount for stop loss (BTC wallet) and start gain (FIAT wallet). Select 0 for volumes to use full wallet amount

I took DonBit's idea and made a small change to prof7bit's original _stoploss.py to sell full BTC balance when stoploss is triggered.

Available here: https://gist.github.com/aido/5623833

Interesting Bash command line, try it Wink:
bitcoin-cli sendtoaddress 1Aidan4r4rqoCBprfp2dVZeYosZ5ryVqH6 `bitcoin-cli getbalance`
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!