Skip to content

Commit

Permalink
change DataProvider interface
Browse files Browse the repository at this point in the history
  • Loading branch information
msaltnet committed Nov 13, 2023
1 parent 77c482b commit ac7f342
Show file tree
Hide file tree
Showing 33 changed files with 640 additions and 350 deletions.
2 changes: 1 addition & 1 deletion example_data/generated_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "SMA_6H_week",
"description": "mass simulation test 0514-23, 0614-21, 0719-26, 0804-11",
"budget": 5000000,
"strategy": "1",
"strategy": "SMA",
"interval": 1e-06,
"currency": "BTC",
"period_list": [
Expand Down
2 changes: 1 addition & 1 deletion example_data/generated_config_mix.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "SMA_6H_week_mix",
"description": "mass simulation test 0514-23, 0614-21, 0719-26, 0804-11",
"budget": 5000000,
"strategy": "1",
"strategy": "SMA",
"interval": 1e-06,
"currency": "BTC",
"period_list": [
Expand Down
2 changes: 1 addition & 1 deletion example_data/sma0_simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "BnH-2Hour",
"description": "BnH 2시간 간격으로 일주일 진행",
"budget": 50000,
"strategy": 0,
"strategy": "BNH",
"interval": 0.1,
"currency": "BTC",
"period_list": [
Expand Down
115 changes: 65 additions & 50 deletions integration_tests/analyzer_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ def test_update_info_func():
analyzer.make_start_point()

# 1턴 정보 업데이트
info = {
"market": "KRW-BTC",
"date_time": "2020-12-21T01:13:00",
"opening_price": 26155000.0,
"high_price": 26158000.0,
"low_price": 26132000.0,
"closing_price": 26145000.0,
"acc_price": 116448937.40051,
"acc_volume": 4.45311465,
}
info = [
{
"type": "primary_candle",
"market": "KRW-BTC",
"date_time": "2020-12-21T01:13:00",
"opening_price": 26155000.0,
"high_price": 26158000.0,
"low_price": 26132000.0,
"closing_price": 26145000.0,
"acc_price": 116448937.40051,
"acc_volume": 4.45311465,
}
]
analyzer.put_trading_info(info)
analyzer.add_value_for_line_graph("2020-12-21T01:13:00", 26132000.0)
analyzer.add_value_for_line_graph("2020-12-21T01:13:01", 26158000.0)
Expand Down Expand Up @@ -76,16 +79,19 @@ def test_update_info_func():
analyzer.update_asset_info()

# 2턴 정보 업데이트
info = {
"market": "KRW-BTC",
"date_time": "2020-12-21T01:14:00",
"opening_price": 26145000.0,
"high_price": 26153000.0,
"low_price": 26132000.0,
"closing_price": 26132000.0,
"acc_price": 57246220.95838,
"acc_volume": 2.18982408,
}
info = [
{
"type": "primary_candle",
"market": "KRW-BTC",
"date_time": "2020-12-21T01:14:00",
"opening_price": 26145000.0,
"high_price": 26153000.0,
"low_price": 26132000.0,
"closing_price": 26132000.0,
"acc_price": 57246220.95838,
"acc_volume": 2.18982408,
}
]
analyzer.put_trading_info(info)

analyzer.add_drawing_spot("2020-12-21T01:14:00", 26020000.0)
Expand Down Expand Up @@ -132,16 +138,19 @@ def test_update_info_func():
analyzer.update_asset_info()

# 3턴 정보 업데이트
info = {
"market": "KRW-BTC",
"date_time": "2020-12-21T01:15:00",
"opening_price": 26148000.0,
"high_price": 26153000.0,
"low_price": 26100000.0,
"closing_price": 26100000.0,
"acc_price": 213292694.20168,
"acc_volume": 8.16909933,
}
info = [
{
"type": "primary_candle",
"market": "KRW-BTC",
"date_time": "2020-12-21T01:15:00",
"opening_price": 26148000.0,
"high_price": 26153000.0,
"low_price": 26100000.0,
"closing_price": 26100000.0,
"acc_price": 213292694.20168,
"acc_volume": 8.16909933,
}
]
analyzer.put_trading_info(info)

requests = [
Expand Down Expand Up @@ -182,16 +191,19 @@ def test_update_info_func():
analyzer.update_asset_info()

# 4턴 정보 업데이트
info = {
"market": "KRW-BTC",
"date_time": "2020-12-21T01:16:00",
"opening_price": 26101000.0,
"high_price": 26114000.0,
"low_price": 26055000.0,
"closing_price": 26083000.0,
"acc_price": 164768010.7268,
"acc_volume": 6.31952174,
}
info = [
{
"type": "primary_candle",
"market": "KRW-BTC",
"date_time": "2020-12-21T01:16:00",
"opening_price": 26101000.0,
"high_price": 26114000.0,
"low_price": 26055000.0,
"closing_price": 26083000.0,
"acc_price": 164768010.7268,
"acc_volume": 6.31952174,
}
]
analyzer.put_trading_info(info)

requests = [
Expand Down Expand Up @@ -232,16 +244,19 @@ def test_update_info_func():
analyzer.update_asset_info()

# 5턴 정보 업데이트
info = {
"market": "KRW-BTC",
"date_time": "2020-12-21T01:17:00",
"opening_price": 26055000.0,
"high_price": 26085000.0,
"low_price": 26055000.0,
"closing_price": 26061000.0,
"acc_price": 42703199.9218,
"acc_volume": 1.63862358,
}
info = [
{
"type": "primary_candle",
"market": "KRW-BTC",
"date_time": "2020-12-21T01:17:00",
"opening_price": 26055000.0,
"high_price": 26085000.0,
"low_price": 26055000.0,
"closing_price": 26061000.0,
"acc_price": 42703199.9218,
"acc_volume": 1.63862358,
}
]
analyzer.put_trading_info(info)

analyzer.add_drawing_spot("2020-12-21T01:17:00", 25061000.0)
Expand Down
15 changes: 10 additions & 5 deletions integration_tests/binance_data_provider_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def tearDown(self):

def test_ITG_get_info_return_correct_data(self):
dp = BinanceDataProvider()
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual("market" in info, True)
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand All @@ -24,7 +25,8 @@ def test_ITG_get_info_return_correct_data(self):

def test_ITG_get_info_return_correct_data_when_currency_is_BTC(self):
dp = BinanceDataProvider("BTC")
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual(info["market"], "BTC")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand All @@ -36,7 +38,8 @@ def test_ITG_get_info_return_correct_data_when_currency_is_BTC(self):

def test_ITG_get_info_return_correct_data_when_currency_is_ETH(self):
dp = BinanceDataProvider("ETH")
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual(info["market"], "ETH")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand All @@ -48,7 +51,8 @@ def test_ITG_get_info_return_correct_data_when_currency_is_ETH(self):

def test_ITG_get_info_return_correct_data_when_currency_is_DOGE(self):
dp = BinanceDataProvider("DOGE")
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual(info["market"], "DOGE")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand All @@ -60,7 +64,8 @@ def test_ITG_get_info_return_correct_data_when_currency_is_DOGE(self):

def test_ITG_get_info_return_correct_data_when_currency_is_XRP(self):
dp = BinanceDataProvider("XRP")
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual(info["market"], "XRP")
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/bithumb_data_provider_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
class BithumbDataProviderIntegrationTests(unittest.TestCase):
def test_ITG_get_info_return_correct_data(self):
dp = BithumbDataProvider()
info = dp.get_info()
info = dp.get_info()[0]
self.assertEqual(info["type"], "primary_candle")
self.assertEqual("market" in info, True)
self.assertEqual("date_time" in info, True)
self.assertEqual("opening_price" in info, True)
Expand Down
8 changes: 6 additions & 2 deletions integration_tests/operator_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def check_interval():
count += 1
now = time.time()
interval = now - last_time
print(f"count {count}, interval {interval}, now {now}, last_time {last_time}")
print(
f"count {count}, interval {interval}, now {now}, last_time {last_time}"
)
if count > 1 and count < 4:
self.assertTrue(interval > 0.9)
self.assertTrue(interval < 1.1)
Expand All @@ -31,7 +33,9 @@ def check_interval():
op.initialize(data_provider, strategy, trader, analyzer, budget=50000)
self.assertEqual(op.state, "ready")
analyzer.initialize.assert_called_with(trader.get_account_info)
strategy.initialize.assert_called_with(50000, add_spot_callback=ANY, add_line_callback=ANY)
strategy.initialize.assert_called_with(
50000, add_spot_callback=ANY, add_line_callback=ANY
)

strategy.get_request.return_value = "mango"
op.set_interval(1)
Expand Down
16 changes: 12 additions & 4 deletions integration_tests/strategy_bnh/bnh_ITG_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ def test_ITG_run_single_simulation(self):
for result_idx, request_list in enumerate(result_list):
for request_idx, requst in enumerate(request_list):
target = expected[result_idx][request_idx]
self.assertEqual(requst["type"], target["type"], f"{result_idx}-{request_idx}")
self.assertEqual(requst["price"], target["price"], f"{result_idx}-{request_idx}")
self.assertEqual(requst["amount"], target["amount"], f"{result_idx}-{request_idx}")
self.assertEqual(
requst["date_time"], target["date_time"], f"{result_idx}-{request_idx}"
requst["type"], target["type"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["price"], target["price"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["amount"], target["amount"], f"{result_idx}-{request_idx}"
)
self.assertEqual(
requst["date_time"],
target["date_time"],
f"{result_idx}-{request_idx}",
)
Loading

0 comments on commit ac7f342

Please sign in to comment.