Skip to content

Commit 6214eec

Browse files
committed
Fix tick scheme next bid and ask price lists
1 parent 0bffdf4 commit 6214eec

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

nautilus_trader/model/instruments/base.pyx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -546,19 +546,12 @@ cdef class Instrument(Data):
546546
if num_ticks <= 0:
547547
return []
548548

549-
cdef Price value_price = Price(value, self.price_precision)
550-
cdef Price initial_price = self._tick_scheme.next_bid_price(value=value, n=0)
551-
552549
cdef:
553550
list prices = []
554551
Price price
555552
int i
556553

557-
if value_price != initial_price:
558-
prices.append(initial_price.as_decimal())
559-
num_ticks -= 1
560-
561-
for i in range(1, num_ticks + 1):
554+
for i in range(num_ticks):
562555
try:
563556
price = self._tick_scheme.next_bid_price(value=value, n=i)
564557
if price is None:
@@ -605,19 +598,12 @@ cdef class Instrument(Data):
605598
if num_ticks <= 0:
606599
return []
607600

608-
cdef Price value_price = Price(value, self.price_precision)
609-
cdef Price initial_price = self._tick_scheme.next_ask_price(value=value, n=0)
610-
611601
cdef:
612602
list prices = []
613603
Price price
614604
int i
615605

616-
if value_price != initial_price:
617-
prices.append(initial_price.as_decimal())
618-
num_ticks -= 1
619-
620-
for i in range(1, num_ticks + 1):
606+
for i in range(num_ticks):
621607
try:
622608
price = self._tick_scheme.next_ask_price(value=value, n=i)
623609
if price is None:

tests/integration_tests/adapters/betfair/test_betting_tick_scheme.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def test_betting_instrument_tick_scheme_next_ask_prices() -> None:
178178

179179
assert len(result) == 10
180180
assert result == [
181+
Decimal("3.00"),
181182
Decimal("3.05"),
182183
Decimal("3.10"),
183184
Decimal("3.15"),
@@ -187,7 +188,6 @@ def test_betting_instrument_tick_scheme_next_ask_prices() -> None:
187188
Decimal("3.35"),
188189
Decimal("3.40"),
189190
Decimal("3.45"),
190-
Decimal("3.50"),
191191
]
192192

193193

@@ -198,6 +198,7 @@ def test_betting_instrument_tick_scheme_next_bid_prices() -> None:
198198

199199
assert len(result) == 10
200200
assert result == [
201+
Decimal("20.00"),
201202
Decimal("19.50"),
202203
Decimal("19.00"),
203204
Decimal("18.50"),
@@ -207,5 +208,23 @@ def test_betting_instrument_tick_scheme_next_bid_prices() -> None:
207208
Decimal("16.50"),
208209
Decimal("16.00"),
209210
Decimal("15.50"),
210-
Decimal("15.00"),
211211
]
212+
213+
214+
@pytest.mark.parametrize(
215+
"instrument, expected_bids, expected_asks",
216+
[
217+
(betting_instrument(), 10, 20),
218+
],
219+
)
220+
def test_next_prices(instrument, expected_bids, expected_asks):
221+
bid_price = instrument.next_bid_price(1.102)
222+
ask_price = instrument.next_ask_price(1.102)
223+
bid_prices = instrument.next_bid_prices(1.102, 20)
224+
ask_prices = instrument.next_ask_prices(1.102, 20)
225+
226+
assert bid_price == bid_prices[0]
227+
assert ask_price == ask_prices[0]
228+
229+
assert len(bid_prices) == expected_bids
230+
assert len(ask_prices) == expected_asks

tests/unit_tests/model/test_instrument.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ def test_next_bid_prices_length(self, instrument, value, num_ticks, expected_len
636636
@pytest.mark.parametrize(
637637
("instrument", "value", "num_ticks", "expected_first", "expected_last"),
638638
[
639-
(AUDUSD_SIM, 0.72000, 10, "0.72001", "0.72010"),
639+
(AUDUSD_SIM, 0.72000, 10, "0.72000", "0.72009"),
640640
(AUDUSD_SIM, 0.72001, 5, "0.72002", "0.72006"),
641-
(AUDUSD_SIM, 0.90001, 3, "0.90002", "0.90004"),
641+
(AUDUSD_SIM, 0.90001, 3, "0.90001", "0.90003"),
642642
],
643643
)
644644
def test_next_ask_prices_values(
@@ -665,7 +665,7 @@ def test_next_ask_prices_values(
665665
[
666666
(AUDUSD_SIM, 0.72000, 10, "0.71999", "0.71990"),
667667
(AUDUSD_SIM, 0.72000, 5, "0.71999", "0.71995"),
668-
(AUDUSD_SIM, 0.90000, 3, "0.89999", "0.89997"),
668+
(AUDUSD_SIM, 0.90000, 3, "0.90000", "0.89998"),
669669
],
670670
)
671671
def test_next_bid_prices_values(

0 commit comments

Comments
 (0)