Skip to content

Commit caca9ad

Browse files
committed
Updated .pre-commit-config.yaml
1 parent 3eaf949 commit caca9ad

18 files changed

+111
-346
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
minimum_pre_commit_version: 1.15.2
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v2.1.0
5+
rev: v4.1.0
66
hooks:
77
- id: check-merge-conflict # Check for files that contain merge conflict strings.
88
- id: trailing-whitespace # Trims trailing whitespace.
@@ -22,26 +22,26 @@ repos:
2222
files: ^supported_coin_list$
2323

2424
- repo: https://github.com/asottile/pyupgrade
25-
rev: v2.10.0
25+
rev: v2.29.1
2626
hooks:
2727
- id: pyupgrade
2828
name: Rewrite Code to be Py3.6+
2929
args: [--py36-plus]
3030

3131
- repo: https://github.com/pycqa/isort
32-
rev: 5.6.3
32+
rev: 5.11.5
3333
hooks:
3434
- id: isort
3535
args: [--profile, black, --line-length, '120']
3636

3737
- repo: https://github.com/psf/black
38-
rev: 20.8b1
38+
rev: 23.3.0
3939
hooks:
4040
- id: black
4141
args: [-l, '120']
4242

4343
- repo: https://github.com/asottile/blacken-docs
44-
rev: v1.7.0
44+
rev: v1.11.0
4545
hooks:
4646
- id: blacken-docs
4747
args: [--skip-errors]
@@ -56,7 +56,7 @@ repos:
5656
args: [requirements.txt, dev-requirements.txt]
5757

5858
- repo: https://github.com/pre-commit/mirrors-pylint
59-
rev: v2.4.4
59+
rev: v3.0.0a5
6060
hooks:
6161
- id: pylint
6262
name: PyLint

.pre-commit-hooks/sort-coins-file.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
def sort():
1010
in_contents = SUPPORTED_COIN_LIST.read_text()
1111
out_contents = ""
12-
out_contents += "\n".join(
13-
sorted([line.upper() for line in in_contents.splitlines()])
14-
)
12+
out_contents += "\n".join(sorted(line.upper() for line in in_contents.splitlines()))
1513
out_contents += "\n"
1614
if in_contents != out_contents:
1715
SUPPORTED_COIN_LIST.write_text(out_contents)

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extension-pkg-whitelist=
77

88
# Specify a score threshold to be exceeded before program exits with error.
9-
fail-under=10.0
9+
fail-under=6.0
1010

1111
# Add files or directories to the blacklist. They should be base names, not
1212
# paths.

backtest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@
1414
print("TIME:", manager.datetime)
1515
print("BALANCES:", manager.balances)
1616
print("BTC VALUE:", btc_value, f"({btc_diff}%)")
17-
print(
18-
f"{manager.config.BRIDGE.symbol} VALUE:", bridge_value, f"({bridge_diff}%)"
19-
)
17+
print(f"{manager.config.BRIDGE.symbol} VALUE:", bridge_value, f"({bridge_diff}%)")
2018
print("------")

binance_trade_bot/api_server.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def filter_period(query, model): # pylint: disable=inconsistent-return-statemen
5050
def value_history(coin: str = None):
5151
session: Session
5252
with db.db_session() as session:
53-
query = session.query(CoinValue).order_by(
54-
CoinValue.coin_id.asc(), CoinValue.datetime.asc()
55-
)
53+
query = session.query(CoinValue).order_by(CoinValue.coin_id.asc(), CoinValue.datetime.asc())
5654

5755
query = filter_period(query, CoinValue)
5856

@@ -61,12 +59,7 @@ def value_history(coin: str = None):
6159
return jsonify([entry.info() for entry in values])
6260

6361
coin_values = groupby(query.all(), key=lambda cv: cv.coin)
64-
return jsonify(
65-
{
66-
coin.symbol: [entry.info() for entry in history]
67-
for coin, history in coin_values
68-
}
69-
)
62+
return jsonify({coin.symbol: [entry.info() for entry in history] for coin, history in coin_values})
7063

7164

7265
@app.route("/api/total_value_history")
@@ -82,9 +75,7 @@ def total_value_history():
8275
query = filter_period(query, CoinValue)
8376

8477
total_values: List[Tuple[datetime, float, float]] = query.all()
85-
return jsonify(
86-
[{"datetime": tv[0], "btc": tv[1], "usd": tv[2]} for tv in total_values]
87-
)
78+
return jsonify([{"datetime": tv[0], "btc": tv[1], "usd": tv[2]} for tv in total_values])
8879

8980

9081
@app.route("/api/trade_history")
@@ -142,9 +133,7 @@ def coins():
142133
with db.db_session() as session:
143134
_current_coin = session.merge(db.get_current_coin())
144135
_coins: List[Coin] = session.query(Coin).all()
145-
return jsonify(
146-
[{**coin.info(), "is_current": coin == _current_coin} for coin in _coins]
147-
)
136+
return jsonify([{**coin.info(), "is_current": coin == _current_coin} for coin in _coins])
148137

149138

150139
@app.route("/api/pairs")

binance_trade_bot/auto_trader.py

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def transaction_through_bridge(self, pair: Pair):
3232
"""
3333
can_sell = False
3434
balance = self.manager.get_currency_balance(pair.from_coin.symbol)
35-
from_coin_price = self.manager.get_ticker_price(
36-
pair.from_coin + self.config.BRIDGE
37-
)
35+
from_coin_price = self.manager.get_ticker_price(pair.from_coin + self.config.BRIDGE)
3836

3937
if balance and balance * from_coin_price > self.manager.get_min_notional(
4038
pair.from_coin.symbol, self.config.BRIDGE.symbol
@@ -43,10 +41,7 @@ def transaction_through_bridge(self, pair: Pair):
4341
else:
4442
self.logger.info("Skipping sell")
4543

46-
if (
47-
can_sell
48-
and self.manager.sell_alt(pair.from_coin, self.config.BRIDGE) is None
49-
):
44+
if can_sell and self.manager.sell_alt(pair.from_coin, self.config.BRIDGE) is None:
5045
self.logger.info("Couldn't sell, going back to scouting mode...")
5146
return None
5247

@@ -65,26 +60,16 @@ def update_trade_threshold(self, coin: Coin, coin_price: float):
6560
"""
6661

6762
if coin_price is None:
68-
self.logger.info(
69-
"Skipping update... current coin {} not found".format(
70-
coin + self.config.BRIDGE
71-
)
72-
)
63+
self.logger.info(f"Skipping update... current coin {coin + self.config.BRIDGE} not found")
7364
return
7465

7566
session: Session
7667
with self.db.db_session() as session:
7768
for pair in session.query(Pair).filter(Pair.to_coin == coin):
78-
from_coin_price = self.manager.get_ticker_price(
79-
pair.from_coin + self.config.BRIDGE
80-
)
69+
from_coin_price = self.manager.get_ticker_price(pair.from_coin + self.config.BRIDGE)
8170

8271
if from_coin_price is None:
83-
self.logger.info(
84-
"Skipping update for coin {} not found".format(
85-
pair.from_coin + self.config.BRIDGE
86-
)
87-
)
72+
self.logger.info(f"Skipping update for coin {pair.from_coin + self.config.BRIDGE} not found")
8873
continue
8974

9075
pair.ratio = from_coin_price / coin_price
@@ -100,26 +85,14 @@ def initialize_trade_thresholds(self):
10085
continue
10186
self.logger.info(f"Initializing {pair.from_coin} vs {pair.to_coin}")
10287

103-
from_coin_price = self.manager.get_ticker_price(
104-
pair.from_coin + self.config.BRIDGE
105-
)
88+
from_coin_price = self.manager.get_ticker_price(pair.from_coin + self.config.BRIDGE)
10689
if from_coin_price is None:
107-
self.logger.info(
108-
"Skipping initializing {}, symbol not found".format(
109-
pair.from_coin + self.config.BRIDGE
110-
)
111-
)
90+
self.logger.info(f"Skipping initializing {pair.from_coin + self.config.BRIDGE}, symbol not found")
11291
continue
11392

114-
to_coin_price = self.manager.get_ticker_price(
115-
pair.to_coin + self.config.BRIDGE
116-
)
93+
to_coin_price = self.manager.get_ticker_price(pair.to_coin + self.config.BRIDGE)
11794
if to_coin_price is None:
118-
self.logger.info(
119-
"Skipping initializing {}, symbol not found".format(
120-
pair.to_coin + self.config.BRIDGE
121-
)
122-
)
95+
self.logger.info(f"Skipping initializing {pair.to_coin + self.config.BRIDGE}, symbol not found")
12396
continue
12497

12598
pair.ratio = from_coin_price / to_coin_price
@@ -137,16 +110,10 @@ def _get_ratios(self, coin: Coin, coin_price):
137110
ratio_dict: Dict[Pair, float] = {}
138111

139112
for pair in self.db.get_pairs_from(coin):
140-
optional_coin_price = self.manager.get_ticker_price(
141-
pair.to_coin + self.config.BRIDGE
142-
)
113+
optional_coin_price = self.manager.get_ticker_price(pair.to_coin + self.config.BRIDGE)
143114

144115
if optional_coin_price is None:
145-
self.logger.info(
146-
"Skipping scouting... optional coin {} not found".format(
147-
pair.to_coin + self.config.BRIDGE
148-
)
149-
)
116+
self.logger.info(f"Skipping scouting... optional coin {pair.to_coin + self.config.BRIDGE} not found")
150117
continue
151118

152119
self.db.log_scout(pair, pair.ratio, coin_price, optional_coin_price)
@@ -161,16 +128,11 @@ def _get_ratios(self, coin: Coin, coin_price):
161128

162129
if self.config.USE_MARGIN == "yes":
163130
ratio_dict[pair] = (
164-
(1 - transaction_fee) * coin_opt_coin_ratio / pair.ratio
165-
- 1
166-
- self.config.SCOUT_MARGIN / 100
131+
(1 - transaction_fee) * coin_opt_coin_ratio / pair.ratio - 1 - self.config.SCOUT_MARGIN / 100
167132
)
168133
else:
169134
ratio_dict[pair] = (
170-
coin_opt_coin_ratio
171-
- transaction_fee
172-
* self.config.SCOUT_MULTIPLIER
173-
* coin_opt_coin_ratio
135+
coin_opt_coin_ratio - transaction_fee * self.config.SCOUT_MULTIPLIER * coin_opt_coin_ratio
174136
) - pair.ratio
175137
return ratio_dict
176138

@@ -196,19 +158,15 @@ def bridge_scout(self):
196158
bridge_balance = self.manager.get_currency_balance(self.config.BRIDGE.symbol)
197159

198160
for coin in self.db.get_coins():
199-
current_coin_price = self.manager.get_ticker_price(
200-
coin + self.config.BRIDGE
201-
)
161+
current_coin_price = self.manager.get_ticker_price(coin + self.config.BRIDGE)
202162

203163
if current_coin_price is None:
204164
continue
205165

206166
ratio_dict = self._get_ratios(coin, current_coin_price)
207167
if not any(v > 0 for v in ratio_dict.values()):
208168
# There will only be one coin where all the ratios are negative. When we find it, buy it if we can
209-
if bridge_balance > self.manager.get_min_notional(
210-
coin.symbol, self.config.BRIDGE.symbol
211-
):
169+
if bridge_balance > self.manager.get_min_notional(coin.symbol, self.config.BRIDGE.symbol):
212170
self.logger.info(f"Will be purchasing {coin} using bridge coin")
213171
self.manager.buy_alt(coin, self.config.BRIDGE)
214172
return coin

binance_trade_bot/backtest.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,11 @@ def get_ticker_price(self, ticker_symbol: str):
5151
if end_date > datetime.now():
5252
end_date = datetime.now()
5353
end_date = end_date.strftime("%d %b %Y %H:%M:%S")
54-
self.logger.info(
55-
f"Fetching prices for {ticker_symbol} between {self.datetime} and {end_date}"
56-
)
54+
self.logger.info(f"Fetching prices for {ticker_symbol} between {self.datetime} and {end_date}")
5755
for result in self.binance_client.get_historical_klines(
5856
ticker_symbol, "1m", target_date, end_date, limit=1000
5957
):
60-
date = datetime.utcfromtimestamp(result[0] / 1000).strftime(
61-
"%d %b %Y %H:%M:%S"
62-
)
58+
date = datetime.utcfromtimestamp(result[0] / 1000).strftime("%d %b %Y %H:%M:%S")
6359
price = float(result[1])
6460
cache[f"{ticker_symbol} - {date}"] = price
6561
cache.commit()
@@ -79,14 +75,12 @@ def buy_alt(self, origin_coin: Coin, target_coin: Coin):
7975
target_balance = self.get_currency_balance(target_symbol)
8076
from_coin_price = self.get_ticker_price(origin_symbol + target_symbol)
8177

82-
order_quantity = self._buy_quantity(
83-
origin_symbol, target_symbol, target_balance, from_coin_price
84-
)
78+
order_quantity = self._buy_quantity(origin_symbol, target_symbol, target_balance, from_coin_price)
8579
target_quantity = order_quantity * from_coin_price
8680
self.balances[target_symbol] -= target_quantity
87-
self.balances[origin_symbol] = self.balances.get(
88-
origin_symbol, 0
89-
) + order_quantity * (1 - self.get_fee(origin_coin, target_coin, False))
81+
self.balances[origin_symbol] = self.balances.get(origin_symbol, 0) + order_quantity * (
82+
1 - self.get_fee(origin_coin, target_coin, False)
83+
)
9084
self.logger.info(
9185
f"Bought {origin_symbol}, balance now: {self.balances[origin_symbol]} - bridge: "
9286
f"{self.balances[target_symbol]}"
@@ -107,13 +101,11 @@ def sell_alt(self, origin_coin: Coin, target_coin: Coin):
107101
origin_balance = self.get_currency_balance(origin_symbol)
108102
from_coin_price = self.get_ticker_price(origin_symbol + target_symbol)
109103

110-
order_quantity = self._sell_quantity(
111-
origin_symbol, target_symbol, origin_balance
112-
)
104+
order_quantity = self._sell_quantity(origin_symbol, target_symbol, origin_balance)
113105
target_quantity = order_quantity * from_coin_price
114-
self.balances[target_symbol] = self.balances.get(
115-
target_symbol, 0
116-
) + target_quantity * (1 - self.get_fee(origin_coin, target_coin, True))
106+
self.balances[target_symbol] = self.balances.get(target_symbol, 0) + target_quantity * (
107+
1 - self.get_fee(origin_coin, target_coin, True)
108+
)
117109
self.balances[origin_symbol] -= order_quantity
118110
self.logger.info(
119111
f"Sold {origin_symbol}, balance now: {self.balances[origin_symbol]} - bridge: "

0 commit comments

Comments
 (0)