# Flat Files S3 API – Complete Guide: Authentication, Discovery, Download & Extraction

## Flat Files S3 API – Complete Guide: Authentication, Discovery, Download & Extraction

This guide walks through the full workflow for accessing **FinFeedAPI Flat Files via S3 API**, covering:

* Authentication
* File discovery (listing)
* Downloading data
* Extracting `.csv.gz` files

Each step provides **two options**:

* **Option A:** cURL / Postman
* **Option B:** AWS CLI

## 🔐 Step 1: Authentication

FinFeedAPI uses a simplified S3-compatible authentication model:

```
Access Key ID: YOUR_FINFEEDAPI_KEY
Secret Access Key: finfeedapi
Region: us-east-1
```

### Key Notes

* Your **API key acts as the Access Key**
* Secret is always: finfeedapi
* No token/session exchange required
* Works across all supported tools

### 🌐 Option A — cURL / Postman

Authentication is passed via headers:

```
Authorization: YOUR_FINFEEDAPI_KEY
Accept: application/xml
```

### Postman Setup

* Method: `GET`
* Add headers:
  * `Authorization: YOUR_FINFEEDAPI_KEY`
  * `Accept: application/xml`

### 🛠️ Option B — AWS CLI

Configure credentials:

```
aws configure
```

```
AWS Access Key ID: YOUR_FINFEEDAPI_KEY
AWS Secret Access Key: finfeedapi
Default region name: us-east-1
Default output format: [Leave blank]
```



## 🔍 Step 2: Discover Files (Listing)

You must first **list files using prefixes** to identify available datasets.

Flat Files are organized using a structured naming convention:

```
E-[EXCHANGE]/
└── T-OHLCV+TP-1DAY/
    └── D-YYYYMMDD.csv.gz
```

### Structure Breakdown

* `E-` → Exchange (e.g., `E-IEXG`)
* `T-` → Data type + time interval
  * Always `OHLCV+TP`
  * Example: `T-OHLCV+TP-1DAY`
* `D-` → Date + file name
  * Example: `D-20240118.csv.gz`

### 🧠 Example Path

```
/E-IEXG/T-OHLCV+TP-1DAY/D-20240118.csv.gz
```

### 🌐 Option A — cURL / Postman

#### List available files for an exchange and interval

```sh
curl-X GET \\
-H"Accept: application/xml" \\
-H"Authorization: YOUR_FINFEEDAPI_KEY" \\
"<https://s3.flatfiles.finfeedapi.com/finfeedapi?prefix=E-IEXG/T-OHLCV%2BTP-1DAY/&delimiter=/>"
```

#### 📄 Sample Response

```xml
<Contents>
        <Key>E-IEXG/T-OHLCV+TP-1DAY/D-20161212.csv.gz</Key>
        <LastModified>2025-06-18T22:51:50.994Z</LastModified>
        <Size>187642</Size>
    </Contents>
```

### 🛠️ Option B — AWS CLI

```sh
aws --endpoint-url <http://s3.flatfiles.finfeedapi.com> s3 ls s3://finfeedapi/E-IEXG/T-OHLCV+TP-1DAY/
```

#### 📄 Sample Response

```
2025-07-18 08:11:19       1798 D-20240118.csv.gz
2025-07-19 08:10:36       1792 D-20240119.csv.gz
2025-07-22 08:10:01       1847 D-20240122.csv.gz
```

#### 🧠 Discovery Tips

* Start from exchange level:

```
prefix=E-IEXG/
```

* Then drill down:

```
E-IEXG/T-OHLCV+TP-1DAY/
```

* Dates are encoded directly in file names (`D-YYYYMMDD.csv.gz`)

## 📥 Step 3: Download Files

Once you identify the `Key`, download the file.

### 🌐 Option A — cURL / Postman

```sh
curl-X GET \\
-H"Authorization: YOUR_FINFEEDAPI_KEY" \\
"<https://s3.flatfiles.finfeedapi.com/finfeedapi/E-XJAM/T-OHLCV+TP-1DAY/D-20240118.csv.gz>" \\
--output D-20240118.csv.gz

```

### 🛠️ Option B — AWS CLI

```sh
aws --endpoint-url <http://s3.flatfiles.finfeedapi.com> s3 cp s3://finfeedapi/E-XJAM/T-OHLCV+TP-1DAY/D-20240118.csv.gz ~/local/path/
```

## 🧊 Step 4: Extract `.csv.gz` Files

Flat Files are delivered as compressed `.csv.gz`.

### 🌐 Option A — Terminal (Mac / Linux)

```sh
gunzip D-20240118.csv.gz
```

### Keep original file

```sh
gzip-dk D-20240118.csv.gz
```

### 🛠️ Option B — Python

```python
import gzip
import shutil

with gzip.open("trades.csv.gz", "rb") as f_in:
    with open("trades.csv", "wb") as f_out:
        shutil.copyfileobj(f_in, f_out)
```

### 🪟 (Optional) Windows

Use **7-Zip**:

* Right-click → Extract
* Extract again if needed

## 📄 Resulting CSV

After extraction:

```
D-20240118.csv
```

Typical contents:

```
id_exchange;exchange_symbol;time_period_start;time_period_end;time_open;time_close;price_open;price_high;price_low;price_close;volume_traded;trades_count
IEXG;SWVL;2024-01-18T00:00:00.0000000;2024-01-19T00:00:00.0000000;2024-01-18T00:00:00.0000000;2024-01-19T00:00:00.0000000;2.1;2.1;2;2.07;0;0
```

## 🚀 Workflow Summary

* Authenticate using API key
* List files using:

```sh
prefix=E-{EXCHANGE}/T-OHLCV+TP-{INTERVAL}/
```

* Identify file: D-YYYYMMDD.csv.gz
* Download file
* Extract `.csv.gz`

## ✅ **Congratulations!**

🎉 You now know how to authenticate, discover, download, and extract Flat Files using the S3 API.

With the consistent structure:

E-{EXCHANGE}/T-OHLCV+TP-{INTERVAL}/D-{YYYYMMDD}.csv.gz

You can easily locate and retrieve OHLCV data for use in your workflows or pipelines.