Skip to content

Commit

Permalink
Merge pull request #75 from VladKochetov007/dev
Browse files Browse the repository at this point in the history
v6.0.0: QuickTradeGraph
  • Loading branch information
VladKochetov007 authored Jul 9, 2021
2 parents 4a5e12a + 6dfa2ee commit 8f6cefb
Show file tree
Hide file tree
Showing 12 changed files with 694 additions and 334 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class My_trader(qtr.Trader):


a = My_trader('MSFT/USD', df=yf.download('MSFT', start='2019-01-01'))
a.set_pyplot()
a.connect_graph()
a.set_client(brokers.TradingClient(ccxt.ftx()))
a.strategy_sell_and_hold()
a.backtest()
Expand Down Expand Up @@ -142,7 +142,7 @@ client = brokers.TradingClient(ccxt.binance())
df = client.get_data_historical('BTC/USDT', '15m', 1000)
trader = qtr.ExampleStrategies('BTC/USDT', df=df, interval='15m')
trader.set_client(client)
trader.set_pyplot(height=731, width=1440, row_heights=[10, 5, 2])
trader.connect_graph(height=731, width=1440, row_heights=[10, 5, 2])
trader.strategy_2_sma(55, 21)
trader.backtest(deposit=1000, commission=0.075, bet=qtr.utils.np.inf) # backtest on one pair
```
Expand All @@ -169,6 +169,7 @@ Use the strategy on real moneys. YES, IT'S FULLY AUTOMATED!
import datetime
from quick_trade.trading_sys import ExampleStrategies
from quick_trade.brokers import TradingClient
from quick_trade.plots import QuickTradeGraph, make_figure
import ccxt

ticker = 'MATIC/USDT'
Expand Down Expand Up @@ -199,7 +200,9 @@ trader = MyTrade(ticker=ticker,
interval='1m',
df=client.get_data_historical(ticker, limit=10),
trading_on_client=True)
trader.set_pyplot()
fig = make_figure()
graph = QuickTradeGraph(figure=fig)
trader.connect_graph(graph)
trader.set_client(client)

while True:
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [trading_sys](docs/quick_trade/trading_sys.md)
- [utils](docs/quick_trade/utils.md)
- [plots](docs/quick_trade/plots.md)
- [quick_trade_tuner](docs/quick_trade/quick_trade_tuner/README.md)

- [core](docs/quick_trade/quick_trade_tuner/core.md)
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/quick_trade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ To create a strategy, you will need to generate values for:

?> Lengths of all these variables are equal to the length of the dataframe with the prices of the traded currency.

If your strategy does not provide for the use of anything from this list, quick_trade provides methods for setting
default values (as if the trader and tester would not use them).
If your strategy does not provide for the use of anything from this list, quick_trade provides methods for setting default values (as if the trader and tester would not use them).

If your strategy does not generate stop loss or take profit, there is the
[`Trader.set_open_stop_and_take`](https://vladkochetov007.github.io/quick_trade/#/docs/quick_trade/trading_sys?id=set_open_stop_and_take)
Expand Down
39 changes: 39 additions & 0 deletions docs/docs/quick_trade/plots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# plots

File for creating quick-trade charts.

## make_figure

Method for creating standard figure for plotly.

| param | type | description |
| :---: | :---: | :---: |
| height | Union\[int, float] | Plotly plot height |
| width | Union\[int, float] | Plotly plot width |
| template | str | template from https://plotly.com/python/templates/ |
| row_heights | list | The ratio of the heights of the symbol data, deposit and the deposit change. |
|returns|`plotly.graph_objs.Figure`| standard plotly figure for quick-trade |

!> The number of columns must be 1, and the number of rows must be 3.

## QuickTradeGraph

### connect_trader

### show

### plot_line

### plot_candlestick

### plot_deposit

### plot_returns

### plot_SL_TP_OPN

### plot_trade_triangles

### log_y

### plot_area
90 changes: 47 additions & 43 deletions docs/docs/quick_trade/trading_sys.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ trader.inverse_strategy()

### backtest

A method with the functionality of testing a strategy on historical data. For it to work, you need to use a strategy
that will assign values to `self.returns`,` self._stop_losses`, `self._take_profits` and `self._credit_leverages`.
A method with the functionality of testing a strategy on historical data. For it to work, you need to use a strategy that will assign values to `self.returns`,` self._stop_losses`, `self._take_profits`
and `self._credit_leverages`.

| param | type | description |
| :---: | :---: | :---: |
Expand All @@ -120,11 +120,10 @@ that will assign values to `self.returns`,` self._stop_losses`, `self._take_prof
| show | bool | Show testing schedule. Includes candles, deposit, `.diff()` of deposit and other.|
| returns | `pd.DataFrame` | Dataframe with information about the deposit, strategy signals, `.diff()` of deposit, stop loss, take profit, opening prices, average growth of deposit, and dataframe series. |

?> The commission does not reduce the trade itself, but decreases the deposit, but if the deposit becomes less than the
desired trade, deal is immediately reduced to the level of the deposit.
?> The commission does not reduce the trade itself, but decreases the deposit, but if the deposit becomes less than the desired trade, deal is immediately reduced to the level of the deposit.

```python
trader.set_pyplot()
trader.connect_graph()

# At this point, you need to use the strategy

Expand All @@ -150,8 +149,7 @@ A method for testing a strategy on several symbols.
| show | bool | Show testing schedule. Includes candles, deposit, `.diff()` of deposit and other.|
| returns | `pd.DataFrame` | Dataframe with information about the deposit, average growth of deposit and `.diff()` of deposit. |

!> Each pair is tested separately and then the results are summarized. Because of this, the strategies do not use the
total deposit in such a test.
!> Each pair is tested separately and then the results are summarized. Because of this, the strategies do not use the total deposit in such a test.

```python
import numpy as np
Expand Down Expand Up @@ -180,33 +178,42 @@ winrate: 49.9921984709003%

![image](https://github.com/VladKochetov007/quick_trade/blob/master/img/multi_backtest.png?raw=true)

### set_pyplot
### connect_graph

The method sets the plotly figure for graphs

| param | type | description |
| :---: | :---: | :---: |
| height | Union\[int, float] | Plotly plot height |
| width | Union\[int, float] | Plotly plot width |
| template | str | template from https://plotly.com/python/templates/ |
| row_heights | list | The ratio of the heights of the symbol data, deposit and the deposit change. |
| subplot_kwargs | named arguments | named arguments for [`plotly.subplots.make_subplots`](https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/subplots.py#L45) |
| graph | `plots.QuickTradeGraph` | QuickTradeGraph figure |

```python
from quick_trade.plots import QuickTradeGraph, make_figure

figure = make_figure()
graph = QuickTradeGraph(figure=figure)
```

```python
trader.connect_graph(graph)
```

or

```python
graph.connect_trader(trader=trader)
```

### strategy_collider

This method allows you to combine two strategies into one; it takes the lists of strategy predictions, and the combining
mode as input values.
This method allows you to combine two strategies into one; it takes the lists of strategy predictions, and the combining mode as input values.

Available modes:

- `minimalist`: If both predictions are short, then the result of the collider will be short. If both are long, then
long. If the predictions do not match - exit
- `minimalist`: If both predictions are short, then the result of the collider will be short. If both are long, then long. If the predictions do not match - exit

- `maximalist`: If both predictions are short, then the result of the collider will be short. If both are long, then
long. If the predictions do not match - result of the last merge.
- `maximalist`: If both predictions are short, then the result of the collider will be short. If both are long, then long. If the predictions do not match - result of the last merge.

- `super`: If an element of one of the predictions has changed, but the other not, the result is equal to the one that
has changed. If they changed at the same time - exit.
- `super`: If an element of one of the predictions has changed, but the other not, the result is equal to the one that has changed. If they changed at the same time - exit.

| param | type | description |
| :---: | :---: | :---: |
Expand All @@ -225,15 +232,14 @@ trader.strategy_collider(trader.strategy_2_sma(50, 20),

[`strategy_collider`](#strategy_collider) for multiple strategies

?> First, the first two strategies are combined, and then the result of the previous join is combined with subsequent
strategies.
?> First, the first two strategies are combined, and then the result of the previous join is combined with subsequent strategies.

```python
trader.strategy_collider(trader.strategy_2_sma(50, 20),
trader.strategy_2_sma(20, 10),
trader.strategy_parabolic_SAR(),
trader.strategy_macd()
mode = 'maximalist')
trader.strategy_macd(),
mode='maximalist')
```

### get_trading_predict
Expand All @@ -260,34 +266,24 @@ This method is needed to get the result of the strategy and open an order on the

### get_support_resistance

## ExampleStrategies

Class with examples of strategies, inherited from the [`Trader`](#Trader) class

### \_window_

### find_pip_bar

### find_DBLHC_DBHLC

### find_TBH_TBL

### find_PPR

### strategy_diff

The strategy issues its verdict based on the last change to the dataframe. If you give the entry the closing price of
candles, then if the candle is green - long, if red - short
The strategy issues its verdict based on the last change to the dataframe. If you give the entry the closing price of candles, then if the candle is green - long, if red - short

| param | type | description |
| :---: | :---: | :---: |
| frame_to_diff | pd.Series | series of dataframe |
| returns | `utils.PREDICT_TYPE_LIST` | returns |

## ExampleStrategies

Class with examples of strategies, inherited from the [`Trader`](#Trader) class

### \_window_

### strategy_rsi

When the RSI is greater than the `maximum`, and the current value is less than the previous one, short. It's the same
with long (but with `minimum`).
When the RSI is greater than the `maximum`, and the current value is less than the previous one, short. It's the same with long (but with `minimum`).

If the value has crossed the border with mid` - exit

Expand Down Expand Up @@ -353,4 +349,12 @@ Bollinger bands strategy (not breakout)
| **bollinger_kwargs | named arguments | named arguments for `ta.volatility.BollingerBands` |
| returns | `utils.PREDICT_TYPE_LIST` | returns |

### find_pip_bar

### find_DBLHC_DBHLC

### find_TBH_TBL

### find_PPR

...
12 changes: 4 additions & 8 deletions docs/docs/quick_trade/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ Out[8]: [1, 1, 1, -1, -1, -1, -1, 1, 0, 0]

## get_window

A function for getting a list of lists, each of which has n elements. These lists will be "data windows" with an offset
of 1.
A function for getting a list of lists, each of which has n elements. These lists will be "data windows" with an offset of 1.

| param | type | description |
| :---: | :---: | :---: |
Expand Down Expand Up @@ -168,8 +167,7 @@ Function for calculating [Compound interest](https://investmentu.com/simple-inte

## get_coef_sec

Function for converting timeframe to profit ratio and sleep time
for [`realtime_trading`](https://vladkochetov007.github.io/quick_trade/#/docs/quick_trade/trading_sys?id=realtime_trading)
Function for converting timeframe to profit ratio and sleep time for [`realtime_trading`](https://vladkochetov007.github.io/quick_trade/#/docs/quick_trade/trading_sys?id=realtime_trading)

| param | type | description |
| :---: | :---: | :---: |
Expand All @@ -189,8 +187,7 @@ Out[16]: (105120, 300)

## wait_success

Decorator. If a traceback was received during the execution of the function, then the action is repeated
after `utils.WAIT_SUCCESS_SLEEP` seconds.
Decorator. If a traceback was received during the execution of the function, then the action is repeated after `utils.WAIT_SUCCESS_SLEEP` seconds.

The main purpose is to avoid ConnectionError when trading in real time.
[see this page](https://stackoverflow.com/questions/27333671/how-to-solve-the-10054-error)
Expand All @@ -216,8 +213,7 @@ Function for calculating the coefficient of exponential growth of a deposit when

## assert_logger

Decorator. If AssertionError was called, then first the error is written to the log with the "critical" level, and then
the program stops.
Decorator. If AssertionError was called, then first the error is written to the log with the "critical" level, and then the program stops.

## get_diff

Expand Down
2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@





</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
Expand Down
6 changes: 4 additions & 2 deletions quick_trade/brokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def order_create(self,
ticker: str = 'None',
quantity: float = 0.0):
self._update_balances()
utils.logger.info('quantity: %f, side: %s, ticker: %s', quantity, side, ticker)
utils.logger.info('quantity: %f, side: %s, ticker: %s', quantity, side,
ticker)
if side == 'Buy':
self.client.create_market_buy_order(symbol=ticker, amount=quantity)
elif side == 'Sell':
Expand Down Expand Up @@ -67,7 +68,8 @@ def get_data_historical(self,
interval,
limit=limit)
data = DataFrame(frames,
columns=['time', 'Open', 'High', 'Low', 'Close', 'Volume'])
columns=['time', 'Open', 'High', 'Low', 'Close',
'Volume'])
return data.astype(float)

def exit_last_order(self):
Expand Down
Loading

0 comments on commit 8f6cefb

Please sign in to comment.