MCPcopy Create free account
hub / github.com/ccxt/ccxt / test_aggregate

Function test_aggregate

python/ccxt/test/base/test_aggregate.py:18–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16from ccxt.test.exchange.base import test_shared_methods # noqa E402
17
18def test_aggregate():
19 exchange = ccxt.Exchange({
20 'id': 'sampleexchange',
21 })
22 assert exchange.milliseconds() > 0, 'go transpiler workaround'
23 # @SKIP_START_GO
24 bids = [[789.1, 111.05], [789.1, 111.05], [123.3, 456.2], [784.2, 111.05], [789.1, 111.05]]
25 expected_bids = [[123.3, 456.2], [784.2, 111.05], [789.1, 333.15]]
26 test_shared_methods.assert_deep_equal(exchange, None, 'aggregate', exchange.aggregate(exchange.sort_by(bids, 0)), expected_bids)
27 asks = [[123.2, 456.2], [784.2, 222.44], [789.1, 111.01]]
28 expected_asks = [[123.2, 456.2], [784.2, 222.44], [789.1, 111.01]]
29 test_shared_methods.assert_deep_equal(exchange, None, 'aggregate', exchange.aggregate(exchange.sort_by(asks, 0)), expected_asks)
30 test_shared_methods.assert_deep_equal(exchange, None, 'aggregate', exchange.aggregate([]), [])
31 # Test 1: Simple aggregation - same price combined
32 result1 = exchange.aggregate([[100.2, 1.01], [101.5, 2.01], [100.2, 0.5]])
33 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result1, [[100.2, 1.51], [101.5, 2.01]])
34 # Test 2: With extra fields (should be ignored)
35 result2 = exchange.aggregate([[100.2, 1.01, 'extra'], [101.5, 2.01, 'data', 'more']])
36 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result2, [[100.2, 1.01], [101.5, 2.01]])
37 # Test 3: Zero volumes should be skipped
38 result3 = exchange.aggregate([[100.2, 1.01], [101.5, 0], [102.4, 2.01]])
39 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result3, [[100.2, 1.01], [102.4, 2.01]])
40 # Test 4: Empty array
41 result4 = exchange.aggregate([])
42 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result4, [])
43 # Test 5: Single entry
44 result5 = exchange.aggregate([[100.2, 1.01]])
45 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result5, [[100.2, 1.01]])
46 # Test 6: Many same prices aggregated
47 result6 = exchange.aggregate([[100.2, 0.12], [100.2, 0.2], [100.2, 0.3], [100.2, 0.4]])
48 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result6, [[100.2, 1.02]])
49 # Test 7: All zero volumes - empty result
50 result7 = exchange.aggregate([[100.2, 0], [101.5, 0], [102.4, 0]])
51 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result7, [])
52 # # Test 8: Preserves order of first occurrence
53 # const result8 = exchange.aggregate ([ [ 103, 1.0 ], [ 101.5, 1.0 ], [ 102.4, 1.0 ], [ 101.5, 0.5 ] ]);
54 # testSharedMethods.assertDeepEqual (exchange, undefined, 'testAggregate', result8, [ [ 103, 1.0 ], [ 101.5, 1.5 ], [ 102.4, 1.0 ] ]);
55 # Test 9: Decimal prices
56 result9 = exchange.aggregate([[100.5, 1.04], [100.5, 2.04], [101.5, 1.05]])
57 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result9, [[100.5, 3.08], [101.5, 1.05]])
58 # Test 10: Mixed zero and non-zero for same price
59 result10 = exchange.aggregate([[100.2, 1.04], [100.2, 0], [100.2, 2.04]])
60 test_shared_methods.assert_deep_equal(exchange, None, 'testAggregate', result10, [[100.2, 3.08]])
61 # @SKIP_END_GO
62 exchange.uuid() # placeholder for astt

Callers 1

base_tests_initFunction · 0.90

Calls 5

millisecondsMethod · 0.95
aggregateMethod · 0.95
sort_byMethod · 0.95
uuidMethod · 0.95
ExchangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…