Coder Social home page Coder Social logo

szferguson / binance-trailing-stop-loss Goto Github PK

View Code? Open in Web Editor NEW
146.0 10.0 46.0 28 KB

Provides a dynamic stop-loss that automatically adjusts as the price increases or decreases (depending on mode specified)

License: GNU General Public License v3.0

Python 100.00%

binance-trailing-stop-loss's Introduction

Binance Trailing Stop-Loss

Provides a dynamic stop-loss that automatically adjusts as the price increases or decreases (depending on mode specified)

Installation

Clone the repository

git clone https://github.com/sf04/Binance-Trailing-Stop-Loss

Install required libraries

apt-get install python-pip -y
pip install ccxt

Configure API keys

Obtain an API key here

Then modify config.py and insert your API key and secret

Running

Usage

$ python main.py --help
usage: main.py [-h] --symbol SYMBOL --size SIZE --type TYPE
               [--interval INTERVAL]

optional arguments:
  -h, --help           show this help message and exit
  --symbol SYMBOL      Market Symbol (Ex: NEO/BTC - NEO/USDT)
  --size SIZE          How many satoshis (or USD) the stop loss should be
                       placed above or below current price
  --type TYPE          Specify whether the trailing stop loss should be in
                       buying or selling mode. (Ex: 'buy' or 'sell')
  --interval INTERVAL  How often the bot should check for price changes

Important note

If you are running in sell mode, it is assumed that you have already purchased the coins. If you are running in buy mode, it will use the total available balance in the base (USDT, BTC, etc). I will likely add an option later to specify investment ratio.

About the bot

Buy mode

If the buy option is set, the bot will initially place a stop-loss size satoshis (or USD) above the current market price. As the price goes lower, the stop-loss will get dragged with it, staying no higher than the size specified. Once the price crosses the stop-loss price, a buy order is executed.

Sell mode

If the sell option is set, the bot will initially place a stop-loss size satoshis (or USD) below the current market price. As the price goes higher, the stop-loss will get dragged with it, staying no lower than the size specified. Once the price crosses the stop-loss price, a sell order is executed.

Size

This is the amount in satoshis (or USD) you would like the stop-loss to be retained at. The difference between the current price and stop-loss will never be larger than this amount.

License

Released under GPLv3.

binance-trailing-stop-loss's People

Contributors

szferguson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

binance-trailing-stop-loss's Issues

2 features: Size in percentage and limit Price

Hello,

Thank you for your wonderful share !

I had 2 features request or perhaps it's always available in your app ?

1/ Is there a way to set the size in % ? We'll be abble to have for example trailing stop with 1%.

2/ Fix the limit price where the initial SL begin ? (I understood that your application take the current market price ?)

Thank you very much.

An exception has occurred

Hello

I am really new at using python
I added my keys to config.py file
I use "Spyder" to run the script main.py
I enter there needed argumets
and when I run main.py I get error:

usage: main.py [-h] KEY/USDT 0.000550 sell 5
main.py: error: the following arguments are required: KEY/USDT, 0.000550, sell, 5
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

Should I use somthing else instead of "Spyder"? Or what could it be that I do wrong to get it to work?

Thanx for comment.

getting this error !

Traceback (most recent call last):
File "main.py", line 21, in
main(options)
File "main.py", line 11, in main
task.run()
File "/root/Desktop/Binance-Trailing-Stop-Loss/trail.py", line 66, in run
self.update_stop()
File "/root/Desktop/Binance-Trailing-Stop-Loss/trail.py", line 36, in update_stop
amount = self.binance.get_balance(self.market.split("/")[0])
File "/root/Desktop/Binance-Trailing-Stop-Loss/binance.py", line 33, in get_balance
return float(self.ccxtClient.fetch_balance()[coin]['free'])
File "/usr/local/lib/python2.7/dist-packages/ccxt/binance.py", line 311, in fetch_balance
response = self.privateGetAccount(params)
File "/usr/local/lib/python2.7/dist-packages/ccxt/base/exchange.py", line 433, in inner
return entry(_self, **inner_kwargs)
File "/usr/local/lib/python2.7/dist-packages/ccxt/binance.py", line 1223, in request
response = self.fetch2(path, api, method, params, headers, body)
File "/usr/local/lib/python2.7/dist-packages/ccxt/base/exchange.py", line 458, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/usr/local/lib/python2.7/dist-packages/ccxt/base/exchange.py", line 551, in fetch
self.handle_errors(response.status_code, response.reason, url, method, headers, http_response, json_response)
File "/usr/local/lib/python2.7/dist-packages/ccxt/binance.py", line 1216, in handle_errors
raise exceptions[error](self.id + ' ' + body)
ccxt.base.errors.AuthenticationError: binance {"code":-1022,"msg":"Signature for this request is not valid."}

Didn't work for BTC/USD on stop loss: got InsufficientFunds

First off - thanks for writing this script - it was a good foundational script to learn off of.

I had an amount that was like 12.34567890 (not an actual amount, just showing that there's decimal 8 digits total).

When the stop loss triggered, I was presented with the InsufficientFunds error. I did a printout of the amount in the script, and it was the same as my actual balance. Unsure why the API call would not go through.

I did try it on XRP/USDT, and that worked (maybe because it's only 1 decimal digit).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.