Skip to content

Commit

Permalink
Fixed testcases that were failing due to str(float) diferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbeced committed Jul 30, 2018
1 parent a8c26fb commit 3cae241
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
12 changes: 10 additions & 2 deletions samples/bccharts_example_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ def onOrderUpdated(self, order):
orderType = "Buy"
else:
orderType = "Sell"
self.info("%s order %d updated - Status: %s - %s" % (

exec_info_str = ""
if order.getExecutionInfo():
exec_info_str = " - Price: %s - Amount: %s - Fee: %s" % (
order.getExecutionInfo().getPrice(), order.getExecutionInfo().getQuantity(),
round(order.getExecutionInfo().getCommission(), 2)
)

self.info("%s order %d updated - Status: %s%s" % (
orderType,
order.getId(),
basebroker.Order.State.toString(order.getState()),
order.getExecutionInfo(),
exec_info_str
))


Expand Down
54 changes: 27 additions & 27 deletions testcases/data/bccharts_example_2.output
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
2014-06-26 23:00:00 strategy [INFO] Buy 1.69 at 580.0
2014-06-26 23:00:00 strategy [INFO] Buy order 1 updated - Status: SUBMITTED - None
2014-06-26 23:30:00 strategy [INFO] Buy order 1 updated - Status: ACCEPTED - None
2014-06-26 23:30:00 strategy [INFO] Buy order 1 updated - Status: FILLED - 2014-06-26 23:30:00 - Price: 580.0 - Amount: 1.69 - Fee: 2.4505
2014-06-26 23:00:00 strategy [INFO] Buy order 1 updated - Status: SUBMITTED
2014-06-26 23:30:00 strategy [INFO] Buy order 1 updated - Status: ACCEPTED
2014-06-26 23:30:00 strategy [INFO] Buy order 1 updated - Status: FILLED - Price: 580.0 - Amount: 1.69 - Fee: 2.45
2014-06-26 23:30:00 strategy [INFO] Buy 0.029 at 579.99
2014-06-26 23:30:00 strategy [INFO] Buy order 2 updated - Status: SUBMITTED - None
2014-06-27 00:00:00 strategy [INFO] Buy order 2 updated - Status: ACCEPTED - None
2014-06-27 00:00:00 strategy [INFO] Buy order 2 updated - Status: FILLED - 2014-06-27 00:00:00 - Price: 579.99 - Amount: 0.029 - Fee: 0.042049275
2014-06-26 23:30:00 strategy [INFO] Buy order 2 updated - Status: SUBMITTED
2014-06-27 00:00:00 strategy [INFO] Buy order 2 updated - Status: ACCEPTED
2014-06-27 00:00:00 strategy [INFO] Buy order 2 updated - Status: FILLED - Price: 579.99 - Amount: 0.029 - Fee: 0.04
2014-07-03 18:30:00 strategy [INFO] Sell 1.719 at 639.0
2014-07-03 18:30:00 strategy [INFO] Sell order 3 updated - Status: SUBMITTED - None
2014-07-03 19:00:00 strategy [INFO] Sell order 3 updated - Status: ACCEPTED - None
2014-07-03 19:00:00 strategy [INFO] Sell order 3 updated - Status: FILLED - 2014-07-03 19:00:00 - Price: 639.0 - Amount: 1.719 - Fee: 2.7461025
2014-07-03 18:30:00 strategy [INFO] Sell order 3 updated - Status: SUBMITTED
2014-07-03 19:00:00 strategy [INFO] Sell order 3 updated - Status: ACCEPTED
2014-07-03 19:00:00 strategy [INFO] Sell order 3 updated - Status: FILLED - Price: 639.0 - Amount: 1.719 - Fee: 2.75
2014-07-11 19:30:00 strategy [INFO] Buy 1.692 at 634.91
2014-07-11 19:30:00 strategy [INFO] Buy order 4 updated - Status: SUBMITTED - None
2014-07-11 20:00:00 strategy [INFO] Buy order 4 updated - Status: ACCEPTED - None
2014-07-11 20:00:00 strategy [INFO] Buy order 4 updated - Status: FILLED - 2014-07-11 20:00:00 - Price: 634.91 - Amount: 1.692 - Fee: 2.6856693
2014-07-11 19:30:00 strategy [INFO] Buy order 4 updated - Status: SUBMITTED
2014-07-11 20:00:00 strategy [INFO] Buy order 4 updated - Status: ACCEPTED
2014-07-11 20:00:00 strategy [INFO] Buy order 4 updated - Status: FILLED - Price: 634.91 - Amount: 1.692 - Fee: 2.68
2014-07-11 20:30:00 strategy [INFO] Buy 0.03 at 634.99
2014-07-11 20:30:00 strategy [INFO] Buy order 5 updated - Status: SUBMITTED - None
2014-07-11 21:00:00 strategy [INFO] Buy order 5 updated - Status: ACCEPTED - None
2014-07-11 21:00:00 strategy [INFO] Buy order 5 updated - Status: FILLED - 2014-07-11 21:00:00 - Price: 634.99 - Amount: 0.03 - Fee: 0.04762425
2014-07-11 20:30:00 strategy [INFO] Buy order 5 updated - Status: SUBMITTED
2014-07-11 21:00:00 strategy [INFO] Buy order 5 updated - Status: ACCEPTED
2014-07-11 21:00:00 strategy [INFO] Buy order 5 updated - Status: FILLED - Price: 634.99 - Amount: 0.03 - Fee: 0.048
2014-07-14 01:30:00 strategy [INFO] Sell 1.722 at 626.79
2014-07-14 01:30:00 strategy [INFO] Sell order 6 updated - Status: SUBMITTED - None
2014-07-14 02:00:00 strategy [INFO] Sell order 6 updated - Status: ACCEPTED - None
2014-07-14 02:00:00 strategy [INFO] Sell order 6 updated - Status: FILLED - 2014-07-14 02:00:00 - Price: 627.9 - Amount: 1.722 - Fee: 2.7031095
2014-07-14 01:30:00 strategy [INFO] Sell order 6 updated - Status: SUBMITTED
2014-07-14 02:00:00 strategy [INFO] Sell order 6 updated - Status: ACCEPTED
2014-07-14 02:00:00 strategy [INFO] Sell order 6 updated - Status: FILLED - Price: 627.9 - Amount: 1.722 - Fee: 2.7
2014-07-31 14:00:00 strategy [INFO] Buy 1.81 at 584.13
2014-07-31 14:00:00 strategy [INFO] Buy order 7 updated - Status: SUBMITTED - None
2014-07-31 14:30:00 strategy [INFO] Buy order 7 updated - Status: ACCEPTED - None
2014-07-31 14:30:00 strategy [INFO] Buy order 7 updated - Status: FILLED - 2014-07-31 14:30:00 - Price: 584.1 - Amount: 1.81 - Fee: 2.6430525
2014-07-31 14:00:00 strategy [INFO] Buy order 7 updated - Status: SUBMITTED
2014-07-31 14:30:00 strategy [INFO] Buy order 7 updated - Status: ACCEPTED
2014-07-31 14:30:00 strategy [INFO] Buy order 7 updated - Status: FILLED - Price: 584.1 - Amount: 1.81 - Fee: 2.64
2014-07-31 14:30:00 strategy [INFO] Buy 0.031 at 588.5
2014-07-31 14:30:00 strategy [INFO] Buy order 8 updated - Status: SUBMITTED - None
2014-07-31 15:00:00 strategy [INFO] Buy order 8 updated - Status: ACCEPTED - None
2014-07-31 15:00:00 strategy [INFO] Buy order 8 updated - Status: FILLED - 2014-07-31 15:00:00 - Price: 588.5 - Amount: 0.031 - Fee: 0.04560875
2014-07-31 14:30:00 strategy [INFO] Buy order 8 updated - Status: SUBMITTED
2014-07-31 15:00:00 strategy [INFO] Buy order 8 updated - Status: ACCEPTED
2014-07-31 15:00:00 strategy [INFO] Buy order 8 updated - Status: FILLED - Price: 588.5 - Amount: 0.031 - Fee: 0.05
2014-08-03 00:00:00 strategy [INFO] Sell 1.841 at 587.64
2014-08-03 00:00:00 strategy [INFO] Sell order 9 updated - Status: SUBMITTED - None
2014-08-03 00:30:00 strategy [INFO] Sell order 9 updated - Status: ACCEPTED - None
2014-08-03 00:30:00 strategy [INFO] Sell order 9 updated - Status: FILLED - 2014-08-03 00:30:00 - Price: 589.59 - Amount: 1.841 - Fee: 2.713587975
2014-08-03 00:00:00 strategy [INFO] Sell order 9 updated - Status: SUBMITTED
2014-08-03 00:30:00 strategy [INFO] Sell order 9 updated - Status: ACCEPTED
2014-08-03 00:30:00 strategy [INFO] Sell order 9 updated - Status: FILLED - Price: 589.59 - Amount: 1.841 - Fee: 2.71
12 changes: 12 additions & 0 deletions testcases/doc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import os

import six

from testcases import common


Expand All @@ -29,6 +31,12 @@ def init_data_path():
os.mkdir(storage)


def round_csv_line(line, column, precision):
parts = line.split(",")
parts[column] = str(round(float(parts[column]), precision))
return ",".join(parts)


class TutorialsTestCase(common.TestCase):
def testTutorial1(self):
with common.CopyFiles([os.path.join("testcases", "data", "WIKI-ORCL-2000-quandl.csv")], "."):
Expand Down Expand Up @@ -330,6 +338,10 @@ def testExample1(self):
lines = common.get_file_lines("30min-bitstampUSD.csv")
os.remove("30min-bitstampUSD.csv")

# Float str doesn't behave the same in Pyhton2 and Python3.
if six.PY3:
lines = lines[0:1] + [round_csv_line(line, 5, 8) for line in lines[1:]]

self.assertTrue(res.exit_ok())
self.assertEqual(
lines[0:10],
Expand Down

0 comments on commit 3cae241

Please sign in to comment.