Skip to content

Commit 81fd61d

Browse files
committed
Added PERCENT_PRICE filter
1 parent bf5fc1a commit 81fd61d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Bot/ExchangeInfo.py

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, symbol, filters):
1414
self.maxPrice = Decimal(self.strip_zeros(filters['PRICE_FILTER']['maxPrice']))
1515
self.minPrice = Decimal(self.strip_zeros(filters['PRICE_FILTER']['minPrice']))
1616

17+
self.multipUp = Decimal(self.strip_zeros(filters['PERCENT_PRICE']['multiplierUp']))
18+
self.multipDown = Decimal(self.strip_zeros(filters['PERCENT_PRICE']['multiplierDown']))
19+
1720

1821
# def __init__(self, minPrice, maxPrice, tickSize, minQty, maxQty, stepSize, minNotional, **kvargs):
1922
# self.minNotional = Decimal(self.strip_zeros(minNotional))
@@ -54,6 +57,13 @@ def is_quanity_above_min(self, q):
5457
def is_min_notional_ok(self, q, p):
5558
return q * p >= self.minNotional
5659

60+
def is_within_multiplier_range(self, p, current_price):
61+
return current_price * float(self.multipDown) <= p <= current_price * float(self.multipUp)
62+
63+
def msg_mutliplier_range_error(self, current_price):
64+
return 'Price can not be lower thant {:.8f} and higher than {:.8f}.'\
65+
.format(current_price * float(self.multipDown), current_price * float(self.multipUp))
66+
5767

5868
class ExchangeInfo:
5969
__shared_state = {}

Bot/Strategy/PlaceOrderStrategy.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def execute(self, new_price):
4646
if self.validate_all_orders(targets):
4747
return
4848

49-
alloc = self.prepare_volume_allocation(targets)
49+
alloc = self.prepare_volume_allocation(targets, self.get_single_price(new_price))
5050

5151
if alloc:
5252
self.place_orders(alloc)
@@ -75,7 +75,7 @@ def validate_all_orders(self, targets):
7575
def validate_all_completed(self, targets):
7676
return all(t.status.is_completed() for t in targets)
7777

78-
def prepare_volume_allocation(self, targets):
78+
def prepare_volume_allocation(self, targets, current_price=0):
7979
currency_balance = self.get_balance_for_side()
8080

8181
bal = self.trade.get_cap(currency_balance.avail) + (
@@ -101,10 +101,16 @@ def prepare_volume_allocation(self, targets):
101101
adjusted_balance = round(bal / price, 8)
102102

103103
vol = self.exchange_info.adjust_quanity(t.vol.get_val(adjusted_balance))
104+
104105
t.calculated_volume = vol
105106

107+
if not self.exchange_info.is_within_multiplier_range(price, current_price):
108+
self.logWarning('Target price {:.8f} is not within exchange multipliers. {}'
109+
.format(price, self.exchange_info.msg_mutliplier_range_error(current_price)))
110+
continue
111+
106112
if vol == 0:
107-
self.logWarning('No volume left to process order @ price {:.0f}'.format(price))
113+
self.logWarning('No volume left to process order @ price {:.8f}'.format(price))
108114
continue
109115

110116
if bal - vol < 0:
@@ -117,7 +123,7 @@ def prepare_volume_allocation(self, targets):
117123
# if self.last_target_smart() and t == last_target:
118124
# continue
119125
orders.append({
120-
'price': self.exchange_info.adjust_price(price),
126+
'price': price,
121127
'volume': vol,
122128
'side': self.trade_side().name,
123129
'target': t})

0 commit comments

Comments
 (0)