# Creating Bars

We create 1-minute bars (bucket_interval=60 seconds) below.

```ipython3
import onetick.py as otp

trd = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')

trd = trd.character_present(trd['COND'], 'O6TUHILNRWZ47QMBCGPV', discard_on_match=True)

bars = trd.agg({'VOLUME': otp.agg.sum('SIZE'),
                'HIGH': otp.agg.max('PRICE'),
                'LOW': otp.agg.min('PRICE'),
                'OPEN': otp.agg.first('PRICE'),
                'COUNT': otp.agg.count(),
                'CLOSE': otp.agg.last('PRICE')},
                bucket_interval=otp.Minute(1))

otp.run(
    bars,
    symbols=['AAPL'],
    start=otp.dt(2024, 2, 1, 9, 30),
    end=otp.dt(2024, 2, 1, 10),
    timezone='EST5EDT'
)
```

```myst-ansi
                  Time  VOLUME      HIGH       LOW      OPEN  COUNT     CLOSE
0  2024-02-01 09:31:00  405208  184.3600  183.8200  183.9850   2147  184.2850
1  2024-02-01 09:32:00  269872  184.4600  183.9600  184.2850   1395  184.2099
2  2024-02-01 09:33:00  259842  184.8712  184.0100  184.2000   1330  184.4900
3  2024-02-01 09:34:00  214295  185.0800  184.3900  184.4800   1061  184.9593
4  2024-02-01 09:35:00  241206  185.2100  184.7900  184.9685   1042  185.0212
5  2024-02-01 09:36:00  186926  185.2900  184.9300  185.0300    966  185.2200
6  2024-02-01 09:37:00  176105  185.2250  184.8200  185.2250    970  184.9450
7  2024-02-01 09:38:00  154281  185.2200  184.7500  184.9500    898  185.0600
8  2024-02-01 09:39:00  146778  185.2100  184.8800  185.0650    878  184.9400
9  2024-02-01 09:40:00  201106  185.3389  184.9400  184.9500    841  185.1550
10 2024-02-01 09:41:00  154387  185.3400  184.8709  185.1500    832  185.3300
11 2024-02-01 09:42:00  165414  185.3500  185.0700  185.3173    668  185.3300
12 2024-02-01 09:43:00  226133  185.6400  185.3200  185.3400    956  185.4900
13 2024-02-01 09:44:00  121385  185.6200  185.3500  185.5000    634  185.5700
14 2024-02-01 09:45:00  129403  185.6400  185.2100  185.5700    590  185.2200
15 2024-02-01 09:46:00  262331  185.2262  184.6500  185.2100   1166  184.8800
16 2024-02-01 09:47:00   95166  185.1600  184.8900  184.8900    587  185.0201
17 2024-02-01 09:48:00  116609  185.0900  184.7000  185.0350    688  184.9400
18 2024-02-01 09:49:00  104638  185.0000  184.7200  184.9650    605  184.7900
19 2024-02-01 09:50:00   86386  184.9200  184.7300  184.7800    456  184.7950
20 2024-02-01 09:51:00  126998  184.8880  184.6850  184.8100    728  184.7100
21 2024-02-01 09:52:00   87979  184.9288  184.6200  184.7100    525  184.9000
22 2024-02-01 09:53:00   82921  185.0500  184.7700  184.9100    435  184.9600
23 2024-02-01 09:54:00   94808  185.1450  184.9400  184.9700    490  185.0200
24 2024-02-01 09:55:00   90658  185.2000  184.9900  185.0300    514  185.0300
25 2024-02-01 09:56:00   91304  185.1500  184.9550  185.0340    515  185.0500
26 2024-02-01 09:57:00  109770  185.1450  184.9749  185.0200    566  185.0419
27 2024-02-01 09:58:00   87780  185.1550  184.9900  185.0550    500  185.0600
28 2024-02-01 09:59:00   88513  185.2500  185.0400  185.0650    348  185.2150
29 2024-02-01 10:00:00  136385  185.5000  185.2000  185.2150    647  185.5000
```

<div class="alert alert-block alert-info">
Note: OneTick Cloud has minute bars precomputed and available in \*_BARS databases under the tick type TRD_1M.
</div>

Daily OHLCV data with the official closing prices is also available: see [OHLCV](../daily_OHLCV.md).

Note the use of [`apply_times_daily`](../../../api/run.md#onetick.py.run) to limit each day's interval to 9:30-4:00pm (plus one minute is added as the minute bar for 9:30-9:31 has the timestamp of 9:31).

```ipython3
bars = otp.DataSource('US_COMP_BARS', tick_type='TRD_1M')
bars = bars[['FIRST', 'HIGH', 'LOW', 'LAST', 'VOLUME']]
otp.run(
    bars,
    symbols=['AAPL'],
    start=otp.dt(2024, 2, 1, 9, 31),
    end=otp.dt(2024, 2, 1, 16, 1),
    timezone='EST5EDT',
    apply_times_daily=True)
```

```myst-ansi
                   Time     FIRST      HIGH     LOW      LAST   VOLUME
0   2024-02-01 09:31:00  184.0100  184.3600  183.81  184.2850  1071527
1   2024-02-01 09:32:00  184.2850  184.4600  183.96  184.2099   269872
2   2024-02-01 09:33:00  184.2000  184.8712  184.01  184.4900   259842
3   2024-02-01 09:34:00  184.4800  185.0800  184.39  184.9593   214295
4   2024-02-01 09:35:00  184.9685  185.2100  184.79  185.0212   241206
..                  ...       ...       ...     ...       ...      ...
385 2024-02-01 15:56:00  186.5900  186.6900  186.58  186.6800   277485
386 2024-02-01 15:57:00  186.6850  186.6850  186.54  186.6000   316508
387 2024-02-01 15:58:00  186.6050  186.7900  186.57  186.7800   317427
388 2024-02-01 15:59:00  186.7850  186.7850  186.65  186.7600   366951
389 2024-02-01 16:00:00  186.7550  186.9500  186.69  186.8900   830791

[390 rows x 6 columns]
```
