kaizen-ai / kaizenflow

KaizenFlow is a framework for Bayesian reasoning and AI/ML stream computing
GNU General Public License v3.0
110 stars 76 forks source link

Test broker with multiple submit twap orders #1103

Closed Sameep2808 closed 1 month ago

Sameep2808 commented 2 months ago

Currently we only test our order submission using only one broker class calling submit twap orders once.

We want to create a test where we have 1 instance of broker and same instance will call submit twap orders twice. Trying to mimic what happens in the production trading

You can refer the test cases present in the below class to understand how to mock and run with one broker and one call to submit twap order function: https://github.com/kaizen-ai/kaizenflow/blob/master/oms/broker/ccxt/test/test_ccxt_broker.py#L1768

Helper function which creates broker instance and calls 1 iteration of _submit_twap_orders: https://github.com/kaizen-ai/kaizenflow/blob/master/oms/broker/ccxt/test/mock_exchange_test_case.py#L384

As from the above code you can understand how a broker object is created and _submit_twap_orders is awoked using solipsism loop.

Now just like this we would like to have 2 calls to _submit_twap_orders inorder to test multiple order submission using one broker instance.

The test will go in this file - https://github.com/kaizen-ai/kaizenflow/blob/master/oms/broker/ccxt/test/test_ccxt_broker.py

Lets start with proposing the plan and architecture and then we will move forward with actual testing. Feel free to ask any questions or provide your thoughts into it.

FYI @samarth9008

jayati1397 commented 2 months ago

@samarth9008 can you please update the links, none of them are accessible

jayati1397 commented 2 months ago

@samarth9008 I looked into the code https://github.com/cryptokaizen/cmamp/blob/master/oms/broker/ccxt/test/mock_exchange_test_case.py#L394 has definition for test_submit_twap_orders which is being called by other tests from https://github.com/cryptokaizen/cmamp/blob/master/oms/broker/ccxt/test/test_ccxt_broker.py#L2108

test_submit_twap_orders invokes get_test_broker to create a broker instance and function submit_twap_orders to submit the orders. So to have just one instance of broker call submit_twap_orders twice we would have to add a test in https://github.com/cryptokaizen/cmamp/blob/master/oms/broker/ccxt/test/mock_exchange_test_case.py that creates one instance of broker and then, in the same test we call submit_twap_orders twice.
We can add a test in class https://github.com/cryptokaizen/cmamp/blob/master/oms/broker/ccxt/test/test_ccxt_broker.py#L2108 where we can call the new test function we created(which calls submit_twap_orders twice)

samarth9008 commented 2 months ago

Okay, lets do a draft PR with some architecture to have a better idea. Seems like going in a right direction.

FYI @Sameep2808