Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert CryptoToFiatConverter into a Singleton #423

Merged
merged 1 commit into from Jan 22, 2018

Conversation

glonlas
Copy link
Member

@glonlas glonlas commented Jan 22, 2018

Summary

Speed up unit test from 60s to 6s by Change CryptoToFiatConverter() to a Singleton.

The issue is CryptoToFiatConverter() call Pymarketcap() lib at the __init__. When Pymarketcap() get instanced, it calls some other services. It results in a latency of 2 sec.

By changing CryptoToFiatConverter() to a Singleton, we avoid to init Pymarketcap() every time.

Solve the issue: #420

Quick changelog

  • Change CryptoToFiatConverter() to a Singleton. The bot will instance Pymarketcap() only once.
  • Accelerate Unit test
  • Accelerate every time the bot calls CryptoToFiatConverter()

What's new?

Faster unit tests, Faster bot.
Below the new performance of the tests.

Test Original duration  New duration
[x] freqtrade/tests/test_main.py::test_handle_trade_roi 6.70s 0.02s 
[x] freqtrade/tests/test_main.py::test_handle_overlpapping_signals 4.23s 0.02s 
[x] freqtrade/tests/test_main.py::test_sell_profit_only_enable_profit 4.15s 0.01s 
[x] freqtrade/tests/test_main.py::test_handle_trade_experimental 4.12s 0.01s 
[x] freqtrade/tests/test_main.py::test_sell_profit_only_disable_loss 4.10s 0.01s 
[x] freqtrade/tests/test_main.py::test_sell_profit_only_disable_profit 4.10s 0.02s 
[x] freqtrade/tests/test_main.py::test_process_trade_creation 2.92s 0.04s 
[x] freqtrade/tests/test_main.py::test_process_trade_handling 2.36s 0.02s 
[x] freqtrade/tests/test_main.py::test_sell_profit_only_enable_loss 2.29s 0.06s 
[x] freqtrade/tests/test_main.py::test_execute_sell_without_conf_sell_up 2.25s 0.01s 
[x] freqtrade/tests/test_main.py::test_close_trade 2.13s 0.02s 
[x] freqtrade/tests/rpc/test_rpc_telegram.py::test_status_handle 2.10s 0.01s 
[x] freqtrade/tests/rpc/test_rpc_telegram.py::test_count_handle 2.09s 0.01s 
[x] freqtrade/tests/rpc/test_rpc_telegram.py::test_status_table_handle 2.09s 0.01s 
[x] freqtrade/tests/test_main.py::test_execute_sell_without_conf_sell_down 2.07s 0.01s 
[x] freqtrade/tests/test_main.py::test_create_trade_minimal_amount 2.06s 0.01s 
[x] freqtrade/tests/rpc/test_rpc_telegram.py::test_performance_handle 2.03s 0.02s 
[x] freqtrade/tests/test_main.py::test_create_trade 2.02s 0.01s 
[x] freqtrade/tests/test_fiat_convert.py::test_fiat_convert_is_supported 1.25s 0.08s 
[x] freqtrade/tests/test_fiat_convert.py::test_fiat_convert_get_price 1.23s 0.08s 
[x] freqtrade/tests/test_fiat_convert.py::test_fiat_convert_find_price 1.23s 0.08s 
[x] freqtrade/tests/test_fiat_convert.py::test_fiat_convert_add_pair 1.19s 0.08s 

Result in a speed up of the unittest from 60s to 4s

Because it cost time to load Pymarketcap() every time we create
a CryptoToFiatConverter, it worth it to change it into a
Singleton.
@vertti vertti merged commit f7e979f into develop Jan 22, 2018
@vertti vertti deleted the feature/Crypto2Fiat_Singleton branch January 22, 2018 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants