Skip to content

tjr1508313-beep/programgarden

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

685 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

์†Œ๊ฐœ

Python Release License: AGPL-3.0 Company: LS Product: OverseasStock

programgarden ๊ทธ๋ฆฌ๊ณ  ls

โš ๏ธ ์ฃผ์˜: ์˜คํ”ˆ์†Œ์Šค ์‚ฌ์šฉ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์— ๋Œ€ํ•œ ์ฑ…์ž„์€ ์‚ฌ์šฉ์ž์—๊ฒŒ ์žˆ์œผ๋ฉฐ, ๋ผ์ด์„ ์Šค๋ฅผ ๋ฐ˜๋“œ์‹œ ํ™•์ธํ•ด ์ฃผ์„ธ์š”. ๋ผ์ด์„ ์Šค ๋ณด๊ธฐ

โš ๏ธ ๋ชจ์˜ํˆฌ์ž ์•ˆ๋‚ด: ํ•ด์™ธ์„ ๋ฌผ์€ ํ™์ฝฉ๊ฑฐ๋ž˜์†Œ (HKEX)์˜ ๋ชจ์˜ํˆฌ์ž๋งŒ ์ง€์›๋˜๋ฉฐ, CME, EUREX ๋“ฑ ๋‹ค๋ฅธ ๊ฑฐ๋ž˜์†Œ์™€ ํ•ด์™ธ์ฃผ์‹์€ ๋ชจ์˜ํˆฌ์ž๊ฐ€ ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค (์‹ค์ „ํˆฌ์ž๋งŒ ๊ฐ€๋Šฅ). ๋ชจ์˜ํˆฌ์ž ์‹œ ์‹ค์ œ ์ฒด๊ฒฐ ๊ฐ€๊ฒฉ๊ณผ ์ฐจ์ด๊ฐ€ ๋ฐœ์ƒํ•˜๋‹ˆ ์œ ์˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋น ๋ฅธ ์‹คํ–‰ ๊ฐ€์ด๋“œ ๋ณด๊ธฐ

๐Ÿ“ข ํ˜„ํ™ฉ: ๊ตญ๋‚ด์ฃผ์‹ Finance API(88๊ฐœ TR) + ์›Œํฌํ”Œ๋กœ์šฐ ๋…ธ๋“œ 13๊ฐœ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”์ธ์€ ์ œ์ž‘์ค‘์ž…๋‹ˆ๋‹ค.

์†Œ๊ฐœ

ProgramGarden์€ ์˜คํ”ˆ์†Œ์Šค ๊ธฐ๋ฐ˜ AI ํ€€ํŠธ ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค. ์ฝ”๋”ฉ ์—†์ด ๋…ธ๋“œ๋ฅผ ์กฐํ•ฉํ•˜์—ฌ ์ž๋™๋งค๋งค ์ „๋žต์„ ๊ตฌ์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”„๋กœ๊ทธ๋žจ ๋™์‚ฐ๊ณผ LS์ฆ๊ถŒ ํ˜‘์—…์œผ๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ์œผ๋ฉฐ, ๊ฐœ์ธ ํˆฌ์ž์ž๋ถ€ํ„ฐ ์ž๋™๋งค๋งค ์„œ๋น„์Šค๋ฅผ ์›ํ•˜๋Š” ๊ธฐ์—…๊นŒ์ง€ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž์„ธํ•œ ์‚ฌ์šฉ๋ฒ•์€ ๊ฐ€์ด๋“œ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

AI ํ€€ํŠธ ์•ฑ

์˜คํ”ˆ์†Œ์Šค ๊ธฐ๋ฐ˜์œผ๋กœ ๊ตฌ์ถ•๋œ ์›น์‚ฌ์ดํŠธ์™€ ์•ฑ์—์„œ ์ด์šฉํ•˜์„ธ์š”.

์ปค๋ฎค๋‹ˆํ‹ฐ

์ฃผ์š” ๊ธฐ๋Šฅ

  • ๋…ธ๋“œ ๊ธฐ๋ฐ˜ ์›Œํฌํ”Œ๋กœ์šฐ โ€” 73๊ฐœ ๋…ธ๋“œ๋ฅผ ์กฐํ•ฉํ•˜์—ฌ ์ฝ”๋”ฉ ์—†์ด ์ „๋žต ๊ตฌ์„ฑ
  • ํ•ด์™ธ์ฃผ์‹ ยท ํ•ด์™ธ์„ ๋ฌผ ยท ๊ตญ๋‚ด์ฃผ์‹ โ€” LS์ฆ๊ถŒ OpenAPI ๊ธฐ๋ฐ˜ ์‹ค์‹œ๊ฐ„ ์‹œ์„ธ ์กฐํšŒ ๋ฐ ์ž๋™ ์ฃผ๋ฌธ
  • AI Agent โ€” LLM ๊ธฐ๋ฐ˜ ๋ถ„์„ ๋ฐ ์˜์‚ฌ๊ฒฐ์ •์„ ์›Œํฌํ”Œ๋กœ์šฐ์— ํ†ตํ•ฉ
  • ์ „๋žต ํ”Œ๋Ÿฌ๊ทธ์ธ โ€” RSI, MACD ๋“ฑ ์ปค๋ฎค๋‹ˆํ‹ฐ ๊ธฐ์—ฌ ์ „๋žต์„ ์กฐํ•ฉํ•˜์—ฌ ํ™œ์šฉ
  • ์œ„ํ—˜ ๊ด€๋ฆฌ โ€” ํฌํŠธํด๋ฆฌ์˜ค ์ถ”์ , HWM/Drawdown, ์œ„ํ—˜ ์ด๋ฒคํŠธ ๊ฐ์‚ฌ ๊ธฐ๋ก
  • ๋™์  ๋…ธ๋“œ ์ฃผ์ž… โ€” ์™ธ๋ถ€ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋Ÿฐํƒ€์ž„์— ์ปค์Šคํ…€ ๋…ธ๋“œ๋ฅผ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ

ํŒจํ‚ค์ง€ ๊ตฌ์กฐ

src/
โ”œโ”€โ”€ programgarden/          # ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰ ์—”์ง„ (๋ฉ”์ธ ํŒจํ‚ค์ง€)
โ”‚   โ””โ”€โ”€ examples/           # ์›Œํฌํ”Œ๋กœ์šฐ ์˜ˆ์ œ (workflows JSON, dynamic_plugins, programmer_example)
โ”œโ”€โ”€ core/                   # ๋…ธ๋“œ ํƒ€์ž…, ๋ฒ ์ด์Šค ํด๋ž˜์Šค, ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ, i18n
โ”œโ”€โ”€ finance/                # LS์ฆ๊ถŒ OpenAPI ๋ž˜ํผ (ํ•ด์™ธ์ฃผ์‹, ํ•ด์™ธ์„ ๋ฌผ, ๊ตญ๋‚ด์ฃผ์‹)
โ”‚   โ””โ”€โ”€ example/            # LS์ฆ๊ถŒ ๋ฐ์ดํ„ฐ API ํ˜ธ์ถœ ์˜ˆ์ œ (TR ๋‹จ์œ„)
โ””โ”€โ”€ community/              # ์ „๋žต ํ”Œ๋Ÿฌ๊ทธ์ธ (RSI, MACD ๋“ฑ)

์˜ˆ์ œ

  • ์›Œํฌํ”Œ๋กœ์šฐ(์ž๋™๋งค๋งค): src/programgarden/examples/
    • workflows/ โ€” 77๊ฐœ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ์›Œํฌํ”Œ๋กœ์šฐ JSON + ๋™๋ฐ˜ .md ๋ฌธ์„œ
    • dynamic_plugins/, dynamic_nodes/ โ€” ๋Ÿฐํƒ€์ž„ ๋™์  ์ฃผ์ž… ์˜ˆ์‹œ
    • programmer_example/ โ€” AI Agent ยท quant ํ†ตํ•ฉ ์Šคํฌ๋ฆฝํŠธ
  • LS์ฆ๊ถŒ ๋ฐ์ดํ„ฐ API: src/finance/example/
    • ํ•ด์™ธ์ฃผ์‹ ยท ํ•ด์™ธ์„ ๋ฌผ ยท ๊ตญ๋‚ด์ฃผ์‹ TR ํ˜ธ์ถœ ์ƒ˜ํ”Œ

์„ค์น˜

์›Œํฌํ”Œ๋กœ์šฐ ์—”์ง„ ์ „์ฒด (๋…ธ๋“œ + ์ „๋žต ํ”Œ๋Ÿฌ๊ทธ์ธ + finance + core ํฌํ•จ):

pip install programgarden
# ๋˜๋Š” Poetry
poetry add programgarden

LS์ฆ๊ถŒ OpenAPI ๋งŒ ๋‹จ๋… ์‚ฌ์šฉ (์›Œํฌํ”Œ๋กœ์šฐ ์—”์ง„ ์—†์ด TR ํ˜ธ์ถœ ์Šคํฌ๋ฆฝํŠธ๋งŒ ํ•„์š”ํ•  ๋•Œ):

pip install programgarden-finance
# ๋˜๋Š” Poetry
poetry add programgarden-finance

AI ์ฝ”๋”ฉ ์—์ด์ „ํŠธ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ (Claude ยท Codex)

ProgramGarden ์€ ๋‘ ์ข…๋ฅ˜์˜ ์‚ฌ์šฉ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ž์‹ ์ด ํ•˜๋ ค๋Š” ์ž‘์—…์— ํ•ด๋‹นํ•˜๋Š” ์„น์…˜์„ ํŽผ์นœ ๋’ค, ์•ˆ์ชฝ ์ฝ”๋“œ ๋ธ”๋ก(์šฐ์ƒ๋‹จ ๋ณต์‚ฌ ๋ฒ„ํŠผ)์„ ํ†ต์งธ๋กœ ๋ณต์‚ฌํ•ด AI ์—์ด์ „ํŠธ์˜ ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ ๋˜๋Š” ์ฒซ ๋ฉ”์‹œ์ง€์— ๋ถ™์—ฌ ๋„ฃ์œผ์„ธ์š”. ๋„๋ฉ”์ธ ํŠนํ™” ์ฝ”๋“œ๋ฒ ์ด์Šค(์›Œํฌํ”Œ๋กœ์šฐ DSL + LS์ฆ๊ถŒ OpenAPI)๋ผ ์ฝœ๋“œ ๋ฆฌ๋”ฉ๋งŒ์œผ๋กœ๋Š” ์ •ํ™•ํ•œ ์ถ”๋ก ์ด ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์—, ์•ž๋‹จ์— ์ปจํ…์ŠคํŠธ๋ฅผ ์ฃผ๋Š” ๊ฒƒ์ด ์ถœ๋ ฅ ํ’ˆ์งˆ์„ ํฌ๊ฒŒ ์ขŒ์šฐํ•ฉ๋‹ˆ๋‹ค.

์›Œํฌํ”Œ๋กœ์šฐ ์‚ฌ์šฉ์ž์šฉ (programgarden โ€” ๋…ธ๋“œ ๊ธฐ๋ฐ˜ ์ž๋™ํ™”)

WorkflowExecutor ๋กœ ์‹คํ–‰ํ•  ์›Œํฌํ”Œ๋กœ์šฐ JSON ์„ ์ž‘์„ฑํ•˜๊ฑฐ๋‚˜ ๋””๋ฒ„๊น…ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๋ธ”๋ก์„ ํ†ต์งธ๋กœ ๋ณต์‚ฌํ•ด ์—์ด์ „ํŠธ์—๊ฒŒ ๋ถ™์—ฌ ๋„ฃ์œผ์„ธ์š”.

# ProgramGarden โ€” Workflow User Context

You are helping a user of the ProgramGarden automated-trading library
(https://github.com/programgarden/programgarden). They are building or debugging
workflow JSON that runs through `WorkflowExecutor`. Follow this context strictly.

## What this library is

- Node-based automation DSL. A workflow is a JSON document with `nodes`,
  `edges`, `credentials`, and `notes`.
- 73 nodes across 12 categories: `infra` / `account` / `market` / `condition` /
  `order` / `risk` / `schedule` / `data` / `display` / `analysis` / `ai` /
  `messaging`. Full schema lives in `CLAUDE.md` and
  `src/core/programgarden_core/nodes/`.
- 77 community plugins, referenced via the `plugin` field in `ConditionNode`,
  `NewOrderNode`, etc. See `src/community/programgarden_community/plugins/`.
- Expression binding: `{{ nodes.<id>.<port> }}` flows data between nodes.
  Auto-iterate (`item` / `index` / `total`) when an upstream node emits an
  array. Function namespaces: `date.*`, `finance.*`, `stats.*`, `format.*`,
  `lst.*`.
- Edge types: `main` (default DAG execution), `ai_model` (connects
  `LLMModelNode` โ†’ `AIAgentNode`), `tool` (registers a node as an AI Agent
  tool). `IfNode` branches use `from_port: "true"` / `"false"` (or dot
  notation `"from": "if1.true"`).
- i18n keys live in `src/core/programgarden_core/i18n/locales/{ko,en}.json`
  under the patterns `nodes.{Type}.name|description`,
  `fields.{Type}.{field}`, `outputs.{Type}.{port}`.
- Two execution entry points:
  (1) `WorkflowExecutor` โ€” run an entire JSON workflow.
  (2) `NodeRunner` โ€” run a single node standalone.

## Prompt templates

### Build a new workflow

```
First read `CLAUDE.md` to learn the node / edge / expression rules, then study
`src/programgarden/examples/workflows/01-account-stock-balance.json` plus one
or two strategy workflows in the same directory.
Then build the following workflow JSON:

- Goal: buy at market for 5 NASDAQ tickers whose RSI is <= 30
- Constraint: must pass `WorkflowExecutor.validate()`
```

### Debug a failing workflow

```
Running this workflow JSON raises `Node X failed: ...`.
Run it in dry-run mode by passing
`context_params={"dry_run": True, "max_cycles": 1}` to
`WorkflowExecutor.execute()`. Order, messaging, and real-time nodes will
return mock results so you can locate where the actual error happens.
Wire up an `ExecutionListener`
(see `src/core/programgarden_core/bases/listener.py`) to print node and edge
state transitions while it runs.
```

### Contribute a new plugin

```
Add a new strategy plugin `IchimokuCloud` to ProgramGarden. The plugin layout
is a single `__init__.py` inside
`src/community/programgarden_community/plugins/<plugin_name>/` plus an
optional `README.md`. See `plugins/rsi/__init__.py` for the canonical
example. Plugins are registered through `plugins/__init__.py`. Write all i18n
keys in English only.
```

## Gotchas โ€” call these out up front, they trip agents constantly

1. Symbols are arrays, never dict keys:
   `[{"symbol": "AAPL", "exchange": "NASDAQ"}]`
2. Broker connection is auto-injected by Executor via DAG traversal โ€” never
   bind `connection` manually.
3. Method chaining inside `{{ }}` is supported:
   `{{ nodes.account.filter('pnl > 0').count() }}`
4. Retry is disabled by default for order nodes (`*NewOrderNode`,
   `*ModifyOrderNode`, `*CancelOrderNode`) to prevent duplicate submissions.
   Enabling `resilience.retry.enabled = True` needs explicit justification.
5. Auto-iterate: when the upstream node emits an array, the downstream node
   runs once per item โ€” no explicit loop needed.
6. There is **no** `WorkflowExecutor.dry_run()` method. Dry-run is enabled
   via `execute(..., context_params={"dry_run": True})`.

## Reference files to read before answering

- `src/programgarden/programgarden/executor.py` โ€” `WorkflowExecutor`,
  `execute()`, `validate()`, dry-run behavior
- `src/core/programgarden_core/bases/listener.py` โ€” `ExecutionListener`
  callback contract
- `src/programgarden/examples/workflows/` โ€” 77 runnable workflow JSON files
  (start with `01-account-stock-balance.json`)
- `src/community/programgarden_community/plugins/rsi/__init__.py` โ€” canonical
  plugin shape
LS์ฆ๊ถŒ API ์ง์ ‘ ์‚ฌ์šฉ์ž์šฉ (programgarden-finance ๋‹จ๋…)

์›Œํฌํ”Œ๋กœ์šฐ ์—”์ง„ ์—†์ด LS์ฆ๊ถŒ OpenAPI ๋ž˜ํผ๋งŒ ์‚ฌ์šฉํ•ด ์ž์‹ ์˜ ์Šคํฌ๋ฆฝํŠธ์—์„œ TR(๊ฑฐ๋ž˜์ฝ”๋“œ)์„ ์ง์ ‘ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๋ธ”๋ก์„ ํ†ต์งธ๋กœ ๋ณต์‚ฌํ•ด ์—์ด์ „ํŠธ์—๊ฒŒ ๋ถ™์—ฌ ๋„ฃ์œผ์„ธ์š”.

# ProgramGarden Finance โ€” Direct LS Securities API Context

You are helping a user of the `programgarden-finance` library
(https://pypi.org/project/programgarden-finance/). They are calling LS Securities
OpenAPI TRs directly through their own scripts, without the workflow engine.
Follow this context strictly.

## What this library is

- A typed sync/async wrapper over LS Securities OpenAPI. Each TR (e.g.
  `t1410`, `t8407`) is a Pydantic `blocks.py` module exposing
  `InBlock` / `OutBlock` types. The TR class itself exposes both `.req()`
  (sync) and `.req_async()` (async) callers.
- Coverage: ~150 TR blocks across Overseas Stock / Overseas Futures / Korea
  Stock REST, plus ~28 real-time WebSocket TR blocks (7 overseas stock +
  7 overseas futures + 13 Korea stock + 1 shared).
- TR layout:
  `src/finance/programgarden_finance/ls/{market_segment}/{kind}/t####/` โ€”
  every TR has its own folder; `blocks.py` defines all fields with
  `Field(title=..., description=..., examples=[...])`.
- Authentication: `appkey` + `appsecret` from the LS Securities developer
  portal. Token refresh and rate-limit handling are built in.
- Source-of-truth rule: the library never asserts LS-undocumented formulas,
  sign conventions, units, or time-series ordering. If LS spec doesn't say it,
  the field description literally says `"Not declared in available source."`
  Respect this โ€” do not infer.

## Prompt templates

### Call a single TR

```
Using `programgarden_finance`, write a script that calls Korea Stock TR
`t1410` (์ดˆ์ €์œ ๋™์„ฑ์กฐํšŒ / ultra-low-liquidity query).
See `src/finance/example/korea_stock/run_t1410.py` for the canonical calling
convention (both `.req()` and `.req_async()` patterns).
Read `appkey` / `appsecret` from env vars `LS_APPKEY` / `LS_APPSECRET`.
```

### Find the right TR

```
I need to fetch minute-bar OHLCV for a Korea stock. Browse
`src/finance/programgarden_finance/ls/korea_stock/` to find the right TR,
read its `blocks.py` to understand the InBlock / OutBlock fields
(`src/finance/programgarden_finance/ls/korea_stock/market/t1410/blocks.py` is
a canonical reference for field metadata structure), then write a runnable
example modeled after the matching
`src/finance/example/korea_stock/run_t####.py`.
```

### Real-time subscription

```
Subscribe to Korea Stock real-time price ticks using `programgarden_finance`.
Use the singleton WebSocket pattern from
`src/finance/programgarden_finance/ls/real_base.py`. See
`src/finance/example/korea_stock/real_S3_.py` for a complete subscription
example. Print each tick as it arrives and handle reconnect cleanly.
```

## Gotchas โ€” call these out up front, they trip agents constantly

1. Don't invent field semantics. If the description says
   `"Not declared in available source"`, do not derive a formula or unit โ€”
   ask the user instead.
2. Rate limits are per-TR and enforced by the library. Don't hand-roll your
   own throttling on top.
3. WebSocket is a singleton per credential โ€” don't open multiple connections;
   add subscriptions to the existing session.
4. Field `title` / `description` / `examples` are AI-chatbot ground truth for
   every TR. When editing `blocks.py`, preserve all three.
5. Korean stock uses `shcode` (6 digits); overseas stock uses
   `symbol` + `exchange`. They are not interchangeable.

## Reference files to read before answering

- `src/finance/example/` โ€” runnable per-TR samples (overseas stock / futures /
  Korea stock)
- `src/finance/programgarden_finance/ls/real_base.py` โ€” singleton WebSocket
  pattern for all real-time subscriptions
- `src/finance/programgarden_finance/ls/korea_stock/market/t1410/blocks.py` โ€”
  canonical TR `blocks.py` to mirror when adding or studying a TR
- LS Securities OpenAPI portal: https://openapi.ls-sec.co.kr/apiservice

About

๐ŸŒŽ๐Ÿ“ˆโฐ The best automated trading system

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%