Giter VIP home page Giter VIP logo

51bitquant / binance_grid_trader Goto Github PK

View Code? Open in Web Editor NEW
716.0 27.0 250.0 1007 KB

Binance_grid_trader is a grid strategy bot trading with Binance Spot and Binance Futures Exchange. you can use it to trade any pair in Binance Exchange. Binance_grid_trader是一个币安网格策略软件, 目前支持币安现货,USDT合约和币币合约。

License: MIT License

Python 100.00%
grid-strategy okex okex-api binance binance-api binance-exchange grid trading-strategies algo-trading algorithms

binance_grid_trader's Introduction

Binance Grid Trader

Binance_grid_trader is a grid strategy bot trading with Binance Spot and Binance Future Exchange. you can use it to trade any pair in Binance Exchange.

中文文档 Portuguese

Tutorial Video

how-to-use

First, download the codes. Then create a python virtual env, you can use the anaconda to create the env.

conda create -n trader python==3.7

then you have an env(trader), to use this env, you can use the following command to activate the env.

conda activate trader

Second, you need to use the pip to install the libraries.

pip install -r requirements.txt

the requirements.txt is in the project. It lists the libraries the project rely on.

After install the libraries, you can run the main.py, if you use the pycharm, you may need to configure your project's interpreter.

python main.py

Note: if you run the main.py, you will see the Window UI, if you want to run without ui, you can run the main_futures_script.py or main_spot_script.py, they are for the binance futures or spot exchange.

window picture

Config Binance Future Api and connect Binance Futures Api

Click the top-left Config Binance Api button, near the python button and select Connect Futures.

connect_future_usdt

  1. key: past your api key from binance exchange Api management here.

  2. secret: past your api secret from binance exchange Api management, and remember to edit your api restrictions to allow trade futures.

  3. futures_types: if you want to trade contracts settled in USDT or BUSD like BTCUSDT, BTCBUSD symbol, set it to USDT else set it to COIN.

  4. proxy_host and proxy_port, if you can connect to binance exchange, then leave it blank. If you can't connect directly to Binance exchange, you may need to config the proxy_host or proxy_port. If you have run vpn software, then set the proxy_host to 127.0.0.1 else you need to set the proxy_host to a remote server ip.

All your config api data will save in project directory gridtrader/connect_futures.json file.

NOTE: Remember every time you run the grid strategy, you need to connect the api your api First.To connect the binance api, Click the confirm button.

Config Binance Spot Api and connect Binance Spot Api

Click the top-left Config Binance Api button, near the python button and select Connect Spot.

connect_future_usdt

  1. key: past your api key from binance exchange Api management here.

  2. secret: past your api secret from binance exchange Api management, and remember to edit your api restrictions to allow trade futures.

  3. proxy_host and proxy_port, if you can connect to binance exchange, then leave it blank. If you can't connect directly to Binance exchange, you may need to config the proxy_host or proxy_port. If you have run vpn software, then set the proxy_host to 127.0.0.1 else you need to set the proxy_host to a remote server ip.

All your config api data will save in project directory gridtrader/connect_spot.json file.

NOTE: Remember every time you run the grid strategy, you need to connect the api your api First.To connect the binance api, Click the confirm button.

Add Futures Grid Strategy

window picture

If you want to run the grid strategy in Futures Market, you can add the FutureGridStrategy. The following is the parameters description for the strategy:
  1. strategy_name: set a name for the strategy.

  2. vt_symbol: the symbol you want to trade, like BTCUSDT, ETHBUSD ect. for Future, remember to use the uppercase. if you use the lower case, you will run in the Spot market.

  3. upper_price: the grid highest price, if you set the upper_price to 40000, that means if the market price is over 40000, the strategy won't place any order.

  4. bottom_price: the lowest price fo the strategy. If you set the bottom_price to 30000, if the price is under 30000, the strategy won't place any order.

  5. grid_number, the grid number for the strategy, if the upper_price is 40000, the bottom_price is 30000, if the grid_number is 100, the grid step(or the order price step) is (40000- 30000)/100 = 100

  6. order_volume: your order volume/quantity

  7. max_open_orders: the max open order in buy/sell side.

The strategy settings data will save in gridtrader/grid_strategy_setting.json, you can checkout and modify it.

And the gridtrader/grid_strategy_data.json file will save some variables in the strategy when runnning.

Add Spot Grid Strategy

window picture

If you want to run the grid strategy in Spot Market, you can add the SpotGridStrategy. The following is the parameters description for the strategy:

  1. strategy_name: set a name for the strategy.

  2. vt_symbol: the symbol you want to trade, like btcusdt, ethbusd ect. for spot market, remember to use the lowercase. if you use the lower case, you will run in the Spot market.

  3. upper_price: the grid highest price, if you set the upper_price to 40000, that means if the market price is over 40000, the strategy won't place any order.

  4. bottom_price: the lowest price fo the strategy. If you set the bottom_price to 30000, if the price is under 30000, the strategy won't place any order.

  5. grid_number, the grid number for the strategy, if the upper_price is 40000, the bottom_price is 30000, if the grid_number is 100, the grid step(or the order price step) is (40000- 30000)/100 = 100

  6. order_volume: your order volume/quantity

  7. invest_coin: if you want to trade btcusdt, then set to USDT, if you want to trade btcbusd, then set to BUSD, if you want to trade ethbtc, then set to btc.

  8. max_open_orders: the max open order in buy/sell side.

The strategy settings data will save in gridtrader/grid_strategy_setting.json, you can checkout and modify it.

And the gridtrader/grid_strategy_data.json file will save some variables in the strategy when runnning.

Start Your Grid Strategy

window picture

If you want to start the grid strategy, you need to:

  1. Init your strategy: Click the Init Button

  2. Start your strategy: Click the Start Button.

If you want to stop the strategy, click the Stop button, or even click edit button to edit the strategy's parameters.

If you have a lot of strategies to start in batch, you can click Init All Strategies and Start All Strategies.

using script

If want to run the code in Linux system or just don't want to use the UI, you can use the script. If you want to trade in spot market, checkout the main_spot_script.py. If you want to trade in the future market, checkout the main_futures_script.py

But before run the script, you need to edit the gridtrader/grid_strategy_setting.json file, then config your strategy setting.

contact

wechat: bitquant51

discord: 51bitquant#8078

IF you have any question, please feel free to contact me in discord. If you don't have a binance account, I'm happy you can use the following link to register the account: Binance referral LINK, and you will get 20% commission rebate.

disclaimer

I don't guarantee that this bot can make profit from market, use it at your risk. Don't put your real money into the market before you read the codes. Use at your own risk.

binance_grid_trader's People

Contributors

49bitquant avatar 51bitquant avatar ricardospinoza 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

binance_grid_trader's Issues

Error 400 on binance_future

没有买单,根据盘口下买单: None, 时间: 2021-05-25 05:40:20.990356
请求没有成功: 400, 继续尝试请求

Backtesting and profit trailing support

Hi
Just discovered this piece of software. I was wondering if it is possible to do backtesting before deploying the bot and if it supports profit trailing.

Nice work

But COINM not connecting.. is it work?

2022-05-29 03:01:26,242 INFO: dotusd_perpetual: Could Not Find The Symbol:dotusd_perpetual.BINANCE, Please Connect the Api First.

im tried to connect a lot of times

new functions: 增加功能

New functions:

  1. add the proxy host and port, 增加了代理主机和端口

if you want to use it locally and encounter connection timeout, you can config the proxy host and port at config.json, the default value is None.
如果你想再本地电脑运行,经常遇到连接错误或者网络请求错误,你可以在config.json文件配置上你的代理主机和端口, 默认是没有配置的。

Filter failure: PRICE_FILTER

error

bid_price: 17984.08, ask_price: 17984.09
buy orders: []

sell orders: []
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400
{'code': -1013, 'msg': 'Filter failure: PRICE_FILTER'} 400

config

"platform": "binance_future",
"symbol": "BTCUSDT",
"api_key": "....",
"secret": "...",
"gap_percent": 0.020,
"quantity": 20,
"min_price": 0.001,
"min_qty": 0.01,
"max_orders": 10
}

error

{
"platform": "binance_spot",
"symbol": "XLMETH",
"api_key": "",
"api_secret": "",
"gap_percent": 0.01,
"quantity": 1,
"min_price": 0.01,
"min_qty": 0.01,
"max_orders": 1,
"proxy_host": "",
"proxy_port": 0
}

{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400
{'code': -1013, 'msg': 'Invalid price.'} 400

I always get lost in values

poloniex

can you add poloniex exchange?

Missing gatewayModule

no gatewayModule error when trying to use the binance grid stuff. I couldn't find it anywhere either
image
grid

Error Code -2011 Unknown Order Sent

Hello I used the same config as the sample:

{
"platform": "binance_spot",
"symbol": "ETHUSDT",
"gap_percent": 0.005,
"quantity": 0.001,
"max_orders": 1,
"proxy_host": "",
"proxy_port": 0
}

To test functionality, but I get message saying {'code': -2011, 'msg': 'Unknown order sent.'} 400.

Subscribe Market Data Failed,Symbol Not Found...

Hi, this error occured after init:
futures_02: Subscribe Market Data Failed,Symbol Not Found btcbusd.BINANCE
spot_sucesso: Subscribe Market Data Failed,Symbol Not Found BTCBUSD.BINANCE

how to resolved?

Size of spread on buy and sell

Can u make strategy which dynamicly resize orders-spread if candle resizing.

so. if candles at the moment goes bigger - makes spread bigger etc

Other Exchanges

Hi,
Can this be edited to run on other exchanges? i.e. Kucoin etc. Thanks

spot_grid_strategy.py

Hi Great Work,
I have two questions about.

36 # the strategy will stop when the price break the upper/bottom price, if you set the close_position when stop True,
37 # it will automatically close your position.

Where can I find this config setting close_position ?
Is it true that the upper limit will be ignored and future buy's will be submitted ?

Kind Regards.

Closed because...
Learned Python and made the changes myself in the code.

什么时候会买入?

bid_price: 0.058734, ask_price: 0.058919
buy orders: []

sell orders: []
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
{'code': -1013, 'msg': 'Invalid quantity.'} 400
bid_price: 0.058918, ask_price: 0.058997

Invalid API key

I have created a testing account on Binance and I am getting this message

error {'code': -2015, 'msg': 'Invalid API-key, IP, or permissions for action.'} 401.
Does it mean that the programme can only be used with 'real' account or has Binance change their requirements? Anyone tested it recently.

Thanks in advance

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.