ig_trading_api 0.3.0

A Rust client for the REST and Streaming APIs from IG.com.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# AI Agent Guidelines for IG Trading API

**Last Updated**: November 18, 2025  
**Project**: IG Trading API v0.3.0  
**License**: GPL-3.0-only

---

## ๐ŸŽฏ Purpose

This document defines rules, guidelines, and best practices for AI agents working on this project. Following these rules ensures consistency, quality, and adherence to industry standards.

---

## ๐Ÿ“‹ Table of Contents

1. [General Rules]#general-rules
2. [Code Standards]#code-standards
3. [Documentation Standards]#documentation-standards
4. [Version Control]#version-control
5. [Changelog & Release Notes]#changelog--release-notes
6. [Testing Requirements]#testing-requirements
7. [Security Guidelines]#security-guidelines
8. [Communication Style]#communication-style

---

## ๐Ÿ”ง General Rules

### Project Constraints

1. **ALWAYS identify yourself** at the beginning of EVERY response:
   ```
   **Model: [Your Model Name] (`[model-identifier]`)**
   ```

2. **NEVER make assumptions** - If information is missing, ask the user or search for it in the codebase

3. **ALWAYS work autonomously** - Don't ask for confirmation at every step unless the action is destructive (delete, force push, etc.)

4. **Language**:
   - Code comments: ALWAYS in English
   - Documentation: ALWAYS in English
   - User communication: English (unless specifically requested otherwise)

5. **Date Format**: ALWAYS use ISO 8601 or explicit format (e.g., "November 18, 2025")

---

## ๐Ÿ’ป Code Standards

### Rust Best Practices

1. **Follow Rust idioms** and conventions
2. **Use meaningful names** for variables, functions, and types
3. **Write documentation comments** for public APIs using `///`
4. **Implement error handling** properly - no `.unwrap()` in production code
5. **Use clippy** and fix all warnings before committing

### Code Structure

```rust
// GOOD: Clear, documented, error handling
/// Load API configuration from environment variables and config file.
/// 
/// # Errors
/// Returns an error if required environment variables are missing.
pub fn from_env_and_config() -> Result<Self, Box<dyn Error>> {
    // Implementation
}

// BAD: No docs, unwrap in production
pub fn from_env_and_config() -> Self {
    Self::load_env().unwrap()  // โŒ Don't use unwrap
}
```

### Security

1. **NEVER commit secrets** - Use environment variables
2. **ALWAYS validate input** from external sources
3. **Use secure dependencies** - Check for vulnerabilities
4. **Follow OWASP guidelines** for web security

---

## ๐Ÿ“š Documentation Standards

### Project Documentation Structure

The project follows this standard structure:

```
ig_trading_api/
โ”œโ”€โ”€ README.md                    # Main project documentation
โ”œโ”€โ”€ CHANGELOG.md                 # Complete version history (primary source)
โ”œโ”€โ”€ RELEASE_NOTES_v*.md         # Specific release details (optional)
โ”œโ”€โ”€ LICENSE                      # GPL-3.0 license
โ””โ”€โ”€ AGENTS.md                    # This file
```

### README.md Requirements

1. **MUST include**:
   - Project logo and branding
   - Professional badges (shields.io)
   - Clear description
   - Installation instructions
   - Configuration guide (with security best practices)
   - Usage examples
   - API documentation
   - Contributing guidelines
   - License information
   - Contact information

2. **Structure**:
   - Use proper markdown hierarchy (h1 โ†’ h2 โ†’ h3)
   - Include table of contents for long documents
   - Use code blocks with language identifiers
   - Add clear section separators

---

## ๐Ÿ”„ Version Control

### Semantic Versioning (SemVer)

Follow [Semantic Versioning 2.0.0](https://semver.org/):

- **MAJOR** (X.0.0): Breaking changes, incompatible API changes
- **MINOR** (0.X.0): New features, backwards-compatible
- **PATCH** (0.0.X): Bug fixes, backwards-compatible

### Version Bump Rules

```rust
0.2.3 โ†’ 0.3.0  // Breaking change (security refactoring)
0.3.0 โ†’ 0.3.1  // Bug fix (no breaking changes)
0.3.0 โ†’ 0.4.0  // New feature (backwards-compatible)
```

### Git Operations - CRITICAL RULES

**โš ๏ธ NEVER do these operations without explicit user authorization:**

1. โŒ **NEVER commit changes** - Always ask first
2. โŒ **NEVER push to remote** - Always ask first
3. โŒ **NEVER create pull requests** - Always ask first
4. โŒ **NEVER merge branches** - Always ask first
5. โŒ **NEVER force push** - Even if asked, warn about dangers
6. โŒ **NEVER delete branches** - Always ask first
7. โŒ **NEVER rebase** - Always ask first
8. โŒ **NEVER amend commits** - Always ask first

**โœ… What you CAN do autonomously:**
- Read git status
- View git log
- Check diffs
- View branches
- Inspect commits
- Prepare commit messages (but don't execute)

**๐Ÿค” What you MUST ask for:**
```markdown
"I have prepared the following changes. Would you like me to commit them?

Files changed:
- file1.rs
- file2.md

Proposed commit message:
โœจ feat(api): add new feature

Should I proceed with this commit? (yes/no)"
```

### Git Commit Messages

Follow [Conventional Commits](https://www.conventionalcommits.org/) with optional emojis.

#### Format

```bash
[emoji] <type>(<scope>): <subject>

[optional body]

[optional footer(s)]
```

#### Commit Types

| Type | Emoji | Description | Example |
|------|-------|-------------|---------|
| `feat` | โœจ | New feature | `โœจ feat(api): add streaming support` |
| `fix` | ๐Ÿ› | Bug fix | `๐Ÿ› fix(auth): resolve session timeout` |
| `docs` | ๐Ÿ“ | Documentation | `๐Ÿ“ docs(readme): add installation guide` |
| `style` | ๐Ÿ’„ | Code style/formatting | `๐Ÿ’„ style(api): format with rustfmt` |
| `refactor` | โ™ป๏ธ | Code refactoring | `โ™ป๏ธ refactor(config): simplify loading` |
| `perf` | โšก | Performance improvement | `โšก perf(api): optimize request caching` |
| `test` | โœ… | Tests | `โœ… test(api): add integration tests` |
| `build` | ๐Ÿ‘ท | Build system | `๐Ÿ‘ท build(deps): update tokio to 1.35` |
| `ci` | ๐Ÿ’š | CI configuration | `๐Ÿ’š ci: add GitHub Actions workflow` |
| `chore` | ๐Ÿ”ง | Maintenance | `๐Ÿ”ง chore: update .gitignore` |
| `revert` | โช | Revert changes | `โช revert: revert commit abc123` |
| `security` | ๐Ÿ”’ | Security improvements | `๐Ÿ”’ security(config): move secrets to .env` |
| `release` | ๐Ÿš€ | Release/version bump | `๐Ÿš€ release: version 0.3.0` |

#### Subject Line Rules

1. **Use imperative mood** - "add feature" not "added feature"
2. **No period at end** - "add feature" not "add feature."
3. **Max 50 characters** for subject line
4. **Capitalize first letter** after type/emoji
5. **Be specific** - "fix login timeout" not "fix bug"

#### Body Rules (Optional)

1. **Wrap at 72 characters**
2. **Explain WHAT and WHY**, not HOW
3. **Use bullet points** for multiple items
4. **Reference issues**: "Fixes #123" or "Closes #456"

#### Footer Rules (Optional)

```bash
# Breaking changes
BREAKING CHANGE: environment variables now required

# Issue references
Fixes #123
Closes #456
Refs #789
```

#### Complete Examples

**Simple commit:**
```bash
โœจ feat(config): add environment variable support
```

**With body:**
```bash
๐Ÿ”’ security(config): separate secrets from configuration

Move all sensitive data (API keys, passwords) from config.yaml
to .env file following 12-factor app principles.

- Add dotenvy dependency for .env loading
- Update ApiConfig to load from environment
- Add .env.example template
- Update documentation

BREAKING CHANGE: config.yaml no longer contains secrets
Fixes #42
```

**Bug fix:**
```bash
๐Ÿ› fix(api): resolve session timeout in long operations

Sessions were expiring during position creation due to
extended API call duration. Added automatic token refresh
middleware to handle this case.

Fixes #38
```

**Documentation:**
```bash
๐Ÿ“ docs(readme): add professional badges and logo

- Add shields.io badges (version, license, build)
- Include IG logo with proper branding
- Restructure sections following open-source best practices
- Add table of contents
```

**Release:**
```bash
๐Ÿš€ release: version 0.3.0

Major release with security improvements:
- Environment-based secrets management
- Professional documentation
- 14/14 tests passing

BREAKING CHANGE: configuration system refactored
See RELEASE_NOTES_v0.3.0.md for migration guide
```

#### Commit Message Checklist

Before committing, verify:

- [ ] Type is correct (feat, fix, docs, etc.)
- [ ] Scope is specified (if applicable)
- [ ] Subject is imperative and under 50 chars
- [ ] Body explains WHY (if needed)
- [ ] Breaking changes are documented
- [ ] Issues are referenced
- [ ] Code is tested (`cargo test`)
- [ ] Code is formatted (`cargo fmt`)
- [ ] No linter errors (`cargo clippy`)

#### What NOT to Do

โŒ **Vague messages:**
```bash
fix stuff
update code
changes
WIP
```

โŒ **Multiple unrelated changes in one commit:**
```bash
feat: add streaming + fix auth + update docs
```

โŒ **Commit without testing:**
```bash
fix: resolve issue (untested)
```

โŒ **Past tense:**
```bash
added feature
fixed bug
```

โœ… **Good commits:**
```bash
โœจ feat(streaming): add WebSocket support
๐Ÿ› fix(auth): handle expired tokens
๐Ÿ“ docs(api): document rate limits
๐Ÿ”’ security: update dependencies
```

#### Emoji Usage (Optional)

Emojis are **optional** but recommended for visual clarity:

- โœ… **Use**: For quick visual identification in git log
- โœ… **Consistent**: Always use the same emoji per type
- โŒ **Don't overuse**: One emoji per commit
- โŒ **Don't mix**: Either use emojis for all commits or none

**Without emojis (also acceptable):**
```bash
feat(config): add environment variable support
fix(auth): resolve session timeout issue
docs(readme): add installation instructions
```

**With emojis (recommended):**
```bash
โœจ feat(config): add environment variable support
๐Ÿ› fix(auth): resolve session timeout issue
๐Ÿ“ docs(readme): add installation instructions
```

---

## ๐Ÿ“ Changelog & Release Notes

### CHANGELOG.md - The Source of Truth

**ALWAYS follow [Keep a Changelog](https://keepachangelog.com/) format.**

#### Structure

```markdown
# Changelog

## [X.Y.Z] - YYYY-MM-DD

### ๐Ÿ”’ Security (if applicable)
- Security improvements and breaking changes

### โœจ Added
- New features

### ๐Ÿ”ง Changed
- Changes in existing functionality

### ๐Ÿ—‘๏ธ Deprecated
- Soon-to-be removed features

### โŒ Removed
- Removed features

### ๐Ÿ› Fixed
- Bug fixes

### โœ… Testing
- ALWAYS include test results for major releases
- Format: "X/Y tests passing (Z%)"
- Breakdown by test type

### ๐Ÿ“ Documentation
- Documentation improvements
```

#### Critical Rules for CHANGELOG.md

1. **ALWAYS update** on every release
2. **ALWAYS use exact dates** (YYYY-MM-DD format)
3. **ALWAYS include version number** in brackets: `## [0.3.0]`
4. **ALWAYS include test results** for major/minor releases:
   ```markdown
   ### โœ… Testing
   
   All integration tests pass successfully:
   - **14/14 REST API tests**: 100% PASS
   - **Compilation**: Debug and Release builds successful
   - **Configuration loading**: Verified working correctly
   - **Authentication**: All authentication flows working
   ```

5. **Breaking changes** MUST be clearly marked:
   ```markdown
   ### ๐Ÿ”ง Changed - BREAKING
   ```

6. **Security changes** MUST be at the top:
   ```markdown
   ### ๐Ÿ”’ Security - BREAKING CHANGES
   ```

7. **Migration instructions** for breaking changes:
   ```markdown
   ### ๐Ÿ”„ Migration Required
   
   To upgrade from vX to vY:
   1. Step-by-step instructions
   ```

8. **Include links** at the bottom:
   ```markdown
   ## Links
   
   - **Release Notes**: [RELEASE_NOTES_vX.Y.Z.md](RELEASE_NOTES_vX.Y.Z.md)
   - **Repository**: [URL]
   - **Documentation**: [README.md](README.md)
   ```

### RELEASE_NOTES_vX.Y.Z.md - User-Friendly Version

**Optional but recommended** for major releases.

#### Structure

```markdown
# Release Notes - vX.Y.Z

**Release Date**: Month DD, YYYY
**Type**: Major/Minor/Patch Release
**Focus**: Brief description

## ๐ŸŽฏ Overview
- High-level summary

## ๐Ÿ”’ Security Improvements (if applicable)
- Before/After comparison
- Why this matters

## โœจ New Features
- Feature descriptions

## ๐Ÿ“š Documentation Improvements
- What was improved

## ๐Ÿ”„ Migration Guide
- Quick start steps
- Code examples

## โœ… Testing Results
- Compilation: PASS/FAIL
- Configuration: PASS/FAIL
- Integration Tests: X/Y PASS
- ALWAYS include test details

## ๐Ÿ“ฆ Dependencies
- New/Updated dependencies

## โš ๏ธ Breaking Changes
- What changed
- Code migration examples

## ๐ŸŽ“ Best Practices Implemented
- Standards compliance

## ๐Ÿ”— Resources
- Links to CHANGELOG, README, etc.

## ๐Ÿ’ฌ Support
- How to get help

## ๐Ÿ™ Credits
- Author, License, Website
```

#### Critical Rules for RELEASE_NOTES

1. **ALWAYS include complete test results**:
   ```markdown
   ### Integration Tests: 14/14 PASS โœ…
   - โœ… All 14 tests pass successfully (100%)
   - โœ… Session management tests pass
   - โœ… Account operations tests pass
   - List all test categories
   
   **Conclusion**: System is production-ready with 100% test success.
   ```

2. **ALWAYS provide migration examples** for breaking changes
3. **ALWAYS link to CHANGELOG.md** for complete details
4. **ALWAYS use exact dates** (e.g., "November 18, 2025")
5. **NEVER say "some tests pass"** - Be specific with numbers

### When to Create Each

| Change Type | CHANGELOG.md | RELEASE_NOTES |
|-------------|--------------|---------------|
| Bug fix (patch) | โœ… Always | โŒ Optional |
| New feature (minor) | โœ… Always | โš ๏ธ Recommended |
| Breaking change (major) | โœ… Always | โœ… Always |

---

## ๐Ÿงช Testing Requirements

### Before ANY Commit

1. **ALWAYS run tests**: `cargo test`
2. **ALWAYS check compilation**: `cargo build --release`
3. **ALWAYS run clippy**: `cargo clippy`
4. **ALWAYS format code**: `cargo fmt`

### Test Result Reporting

When reporting test results, **ALWAYS be precise**:

```markdown
# โœ… GOOD
Tests: 14/14 PASS (100%)
- REST API: 14/14 โœ…
- Unit Tests: 1/1 โœ…
- Compilation: Success

# โŒ BAD
"Most tests pass"
"Some tests fail"
"Tests are working"
```

### Integration Tests

1. **ALWAYS verify** after configuration changes
2. **ALWAYS document** test results in CHANGELOG/RELEASE_NOTES
3. **NEVER claim success** without running tests
4. **ALWAYS include** breakdown by test type

---

## ๐Ÿ” Security Guidelines

### Secrets Management

1. **NEVER commit secrets** to version control
2. **ALWAYS use `.env` files** for sensitive data
3. **ALWAYS add `.env` to `.gitignore`**
4. **ALWAYS provide `.env.example`** template
5. **ALWAYS document** required environment variables

### Environment Variables

```bash
# โœ… GOOD - In .env file (not in git)
IG_API_KEY=actual_secret_key
IG_USERNAME=username
IG_PASSWORD=password

# โŒ BAD - In config.yaml (might be in git)
api_key: "actual_secret_key"
username: "username"
password: "password"
```

### Configuration Structure

```
.env                  # Secrets (NEVER in git)
.env.example          # Template (safe for git)
config.yaml           # Non-sensitive settings (safe for git)
config.default.yaml   # Template (safe for git)
```

### Security Checklist

Before any release:

- [ ] All secrets in `.env`
- [ ] `.env` in `.gitignore`
- [ ] `.env.example` provided
- [ ] `config.yaml` has no secrets
- [ ] README documents security practices
- [ ] CHANGELOG mentions security changes

---

## ๐Ÿ’ฌ Communication Style

### With Users

1. **Be clear and concise** - No unnecessary jargon
2. **Be specific** - Use exact numbers and metrics
3. **Be honest** - Don't claim things that aren't verified
4. **Be helpful** - Provide context and explanations
5. **Use English** - Code and documentation in English

### Documentation Writing

1. **Use active voice**: "Configure the API" not "The API should be configured"
2. **Be specific**: "Run `cargo test`" not "Run the tests"
3. **Provide examples**: Show, don't just tell
4. **Use proper markdown**: Code blocks, lists, headers
5. **Add emojis sparingly**: Only for visual organization (โœ… โŒ โš ๏ธ)

### Error Reporting

```markdown
# โœ… GOOD
Error: 7 tests failed due to API session timeout (HTTP 401)
Root cause: Long-running operations exceed session TTL
Impact: Does NOT affect configuration system

# โŒ BAD
Some tests didn't work
There were problems
Tests failed
```

---

## ๐ŸŽ“ Best Practices Summary

### Always Do

โœ… Update CHANGELOG.md on every release  
โœ… Include exact dates everywhere  
โœ… Run and document all tests  
โœ… Use semantic versioning  
โœ… Write clear commit messages  
โœ… Keep secrets in environment variables  
โœ… Provide migration guides for breaking changes  
โœ… Follow Rust best practices  
โœ… Document all public APIs  

### Never Do

โŒ Commit secrets to git  
โŒ Use vague test descriptions  
โŒ Skip testing before commits  
โŒ Make breaking changes in patch versions  
โŒ Use `.unwrap()` in production  
โŒ Leave code undocumented  
โŒ Guess or assume - verify  
โŒ Mix documentation languages  

---

## ๐Ÿ“š References

### Standards

- [Semantic Versioning]https://semver.org/
- [Keep a Changelog]https://keepachangelog.com/
- [Conventional Commits]https://www.conventionalcommits.org/
- [The Twelve-Factor App]https://12factor.net/
- [OWASP Top 10]https://owasp.org/www-project-top-ten/

### Rust

- [Rust API Guidelines]https://rust-lang.github.io/api-guidelines/
- [Rust Book]https://doc.rust-lang.org/book/
- [Clippy Lints]https://rust-lang.github.io/rust-clippy/

### Security

- [OWASP Secrets Management]https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
- [CIS Controls]https://www.cisecurity.org/controls

---

## ๐Ÿ”„ Updating This Document

When updating AGENTS.md:

1. **Update "Last Updated" date** at the top
2. **Update version number** if project version changed
3. **Document why** the rules were added/changed
4. **Keep it concise** - Only essential rules
5. **Provide examples** for complex rules

---

**Project**: IG Trading API  
**Maintainer**: Daniel Lรณpez Azaรฑa  
**License**: GPL-3.0-only  
**Repository**: https://github.com/daniloaz/ig-trading-api

---

*This document ensures consistency and quality across all AI-assisted development work on this project.*