### Copy Example Configuration Source: https://github.com/smallfish06/krsec/blob/main/README.md Copies the example configuration file to `config.yaml`. This file will be used to configure the krsec server and broker connections. ```bash cp config.example.yaml config.yaml ``` -------------------------------- ### Get Current Price Response Example Source: https://github.com/smallfish06/krsec/blob/main/README.md Example JSON response for a current price query. ```json {"ok": true, "data": {"symbol": "005930", "price": 70000, ...}, "broker": "KIS"} ``` -------------------------------- ### Install krsec CLI Source: https://github.com/smallfish06/krsec/blob/main/README.md Installs the krsec command-line interface tool using Go modules. Ensure you have Go installed and configured. ```bash go install github.com/smallfish06/krsec/cmd/krsec@latest ``` -------------------------------- ### krsec Configuration Example Source: https://github.com/smallfish06/krsec/blob/main/README.md An example `config.yaml` file demonstrating how to configure the krsec server port and multiple broker accounts. It shows settings for KIS, LS, and Toss securities firms, including sandbox modes, API keys, and account identifiers. ```yaml server: port: 8080 accounts: - name: "main" broker: kis sandbox: true app_key: "YOUR_APP_KEY" app_secret: "YOUR_APP_SECRET" account_id: "12345678-01" - name: "ls-main" broker: ls sandbox: false app_key: "YOUR_LS_APP_KEY" app_secret: "YOUR_LS_APP_SECRET" account_id: "ls-main" # mac_address: "YOUR_MAC_ADDRESS" # LS 계정에서 요구되는 경우만 설정 - name: "toss-main" broker: toss sandbox: false app_key_env: "TOSSINVEST_CLIENT_ID" app_secret_env: "TOSSINVEST_CLIENT_SECRET" account_id: "toss-main" # krsec 로컬 selector account_seq: "1" # Toss X-Tossinvest-Account 값 ``` -------------------------------- ### Toss증권 Raw Proxy Call Example Source: https://github.com/smallfish06/krsec/blob/main/README.md Example of calling Toss OpenAPI operations through the raw proxy. This allows access to all REST operations defined in the OpenAPI JSON snapshot. ```Go /toss/{path...} ``` -------------------------------- ### Get Current Price (KRX) Source: https://github.com/smallfish06/krsec/blob/main/README.md Fetch the current stock price for a given symbol on the KRX market. This uses a GET request to the /quotes endpoint. ```bash curl http://localhost:8080/quotes/KRX/005930 ``` -------------------------------- ### Get Current Price (US-NASDAQ) Source: https://github.com/smallfish06/krsec/blob/main/README.md Fetch the current stock price for a given symbol on a US NASDAQ market. This uses a GET request to the /quotes endpoint. ```bash curl http://localhost:8080/quotes/US-NASDAQ/AAPL ``` -------------------------------- ### LS증권 Common Quote API Example Source: https://github.com/smallfish06/krsec/blob/main/README.md Example of accessing overseas stock quotes using the common quote API. This is an alternative to using the raw POST endpoint. ```Go GET /quotes/US-NASDAQ/AAPL ``` -------------------------------- ### Call Toss API for Prices Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a POST request to the Toss API to get prices for multiple symbols. The symbols are provided as a comma-separated string in the query parameters. ```bash curl -X POST http://localhost:8080/toss/api/v1/prices \ -H "Content-Type: application/json" \ -d '{"query":{"symbols":"005930,AAPL"}}' ``` -------------------------------- ### Get Account Balance Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves the balance information for a specific account. ```APIDOC ## GET /accounts/{id}/balance ### Description Retrieves the balance information for a specific account. ### Method GET ### Endpoint /accounts/{id}/balance ``` -------------------------------- ### Call KIS Endpoint with Generated Specs Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a request to a KIS endpoint using generated types from kisspecs. This example demonstrates fetching overseas price data. ```go import ( "context" "net/http" "github.com/smallfish06/krsec/pkg/kis" kisspecs "github.com/smallfish06/krsec/pkg/kis/specs" ) req := &kisspecs.KISOverseasPriceV1QuotationsPriceRequest{ AUTH: "", EXCD: "NAS", SYMB: "AAPL", } resp, err := adapter.CallEndpoint( context.Background(), http.MethodGet, "/uapi/overseas-price/v1/quotations/price", "HHDFS00000300", req, ) _ = resp // typed documented response object _ = err ``` -------------------------------- ### Get Current Quotes Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves the current market price for a given symbol. ```APIDOC ## GET /quotes/{market}/{symbol} ### Description Retrieves the current market price for a given symbol. ### Method GET ### Endpoint /quotes/{market}/{symbol} ### Request Example ```bash curl http://localhost:8080/quotes/KRX/005930 ``` ### Response Example ```json {"ok": true, "data": {"symbol": "005930", "price": 70000, ...}, "broker": "KIS"} ``` ``` -------------------------------- ### Get Multi-Account Summary Balance Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves an integrated balance summary across multiple accounts. ```APIDOC ## GET /accounts/summary ### Description Retrieves an integrated balance summary across multiple accounts. ### Method GET ### Endpoint /accounts/summary ``` -------------------------------- ### Get Instrument Information Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves detailed information about a specific financial instrument. ```APIDOC ## GET /instruments/{market}/{symbol} ### Description Retrieves detailed information about a specific financial instrument. ### Method GET ### Endpoint /instruments/{market}/{symbol} ``` -------------------------------- ### Get OHLCV Data Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves daily or minute-level OHLCV (Open, High, Low, Close, Volume) data for a given symbol. ```APIDOC ## GET /quotes/{market}/{symbol}/ohlcv ### Description Retrieves daily or minute-level OHLCV (Open, High, Low, Close, Volume) data for a given symbol. ### Method GET ### Endpoint /quotes/{market}/{symbol}/ohlcv ``` -------------------------------- ### Get Order Fills Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves the fill details for a specific order within an account. ```APIDOC ## GET /accounts/{account_id}/orders/{id}/fills ### Description Retrieves the fill details for a specific order within an account. ### Method GET ### Endpoint /accounts/{account_id}/orders/{id}/fills ``` -------------------------------- ### Get Order Status Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves the status of a specific order within an account. ```APIDOC ## GET /accounts/{account_id}/orders/{id} ### Description Retrieves the status of a specific order within an account. ### Method GET ### Endpoint /accounts/{account_id}/orders/{id} ``` -------------------------------- ### Get Account Positions Source: https://github.com/smallfish06/krsec/blob/main/README.md Retrieves the current positions held within a specific account. ```APIDOC ## GET /accounts/{id}/positions ### Description Retrieves the current positions held within a specific account. ### Method GET ### Endpoint /accounts/{id}/positions ``` -------------------------------- ### Call KIS Overseas Price API Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a POST request to the KIS API to get overseas price data. Requires specifying the TR ID and parameters like exchange code and symbol. ```bash curl -X POST http://localhost:8080/kis/overseas-price/v1/quotations/price \ -H "Content-Type: application/json" \ -d '{ "tr_id": "HHDFS00000300", "params": { "AUTH": "", "EXCD": "NAS", "SYMB": "AAPL" } }' ``` -------------------------------- ### Embed krsec HTTP Server Source: https://github.com/smallfish06/krsec/blob/main/README.md Instantiate and run the embeddable krsec HTTP server. Ensure all necessary brokers and accounts are configured. ```go import ( "github.com/smallfish06/krsec/pkg/broker" apiserver "github.com/smallfish06/krsec/pkg/server" ) srv := apiserver.New(apiserver.Options{ Port: 8080, Accounts: []apiserver.Account{{ID: "acc-1", Name: "Main", Broker: "custom"}}, Brokers: map[string]broker.Broker{"acc-1": myBroker}, }) srv.Run() ``` -------------------------------- ### Run krsec Application Source: https://github.com/smallfish06/krsec/blob/main/README.md Execute the krsec application using a configuration file. Ensure the config.yaml file is present in the execution directory. ```bash krsec -config config.yaml ``` -------------------------------- ### Project Development Commands Source: https://github.com/smallfish06/krsec/blob/main/README.md Common make commands for development tasks including testing, building, linting, mock generation, and spec management for various services. ```bash make test # 테스트 make build # 빌드 make lint # lint make mock # mock 재생성 make kis-spec-check # KIS generated spec/type 동기화 확인 make kis-spec-refresh # KIS 포털 snapshot 갱신 + generated 파일 재생성 make kiwoom-spec-check # Kiwoom generated spec/type 동기화 확인 make kiwoom-spec-refresh # Kiwoom 포털 snapshot 갱신 + generated 파일 재생성 make ls-spec-check # LS generated spec 동기화 확인 make ls-spec-refresh # LS 포털 snapshot 갱신 + generated 파일 재생성 make toss-spec-check # Toss generated spec 동기화 확인 make toss-spec-refresh # Toss OpenAPI snapshot 갱신 + generated 파일 재생성 ``` -------------------------------- ### Call Toss API for Orders Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a POST request to the Toss API to place an order. Requires specifying account ID, method, and detailed order parameters in the body. ```bash curl -X POST http://localhost:8080/toss/api/v1/orders \ -H "Content-Type: application/json" \ -d '{ "account_id": "toss-main", "method": "POST", "body": { "clientOrderId": "my-order-001", "symbol": "005930", "side": "BUY", "orderType": "LIMIT", "quantity": "10", "price": "70000" } }' ``` -------------------------------- ### Toss API Key Environment Variable Usage Source: https://github.com/smallfish06/krsec/blob/main/README.md Recommended method for using Toss API keys by referencing environment variables. This enhances security and flexibility. ```Go app_key_env/app_secret_env ``` -------------------------------- ### LS증권 Build and Subscribe to Trade Subscriptions Source: https://github.com/smallfish06/krsec/blob/main/README.md Builds a list of KOSPI/KOSDAQ trade subscriptions based on LS stock master data and subscribes to them on a single connection. This is for real-time trade data. ```Go BuildTradeSubscriptions(ctx, lsStockMaster) SubscribeMany(ctx, conn, subscriptions) ``` -------------------------------- ### Place Order Source: https://github.com/smallfish06/krsec/blob/main/README.md Submits a new order for a specified account. ```APIDOC ## POST /accounts/{account_id}/orders ### Description Submits a new order for a specified account. ### Method POST ### Endpoint /accounts/{account_id}/orders ``` -------------------------------- ### Swagger UI Source: https://github.com/smallfish06/krsec/blob/main/README.md Provides access to the Swagger UI for API documentation and exploration. ```APIDOC ## GET /swagger/ ### Description Provides access to the Swagger UI for API documentation and exploration. ### Method GET ### Endpoint /swagger/ ``` -------------------------------- ### LS증권 Build and Subscribe to Overseas Trade Subscriptions Source: https://github.com/smallfish06/krsec/blob/main/README.md Builds and subscribes to overseas trade subscriptions. Supports specifying the market and retrieving real-time data for specific stocks. ```Go BuildOverseasTradeSubscriptions(ctx, "US-NASDAQ", maxRows) OverseasRealtimeKey("82", "AAPL") GSC/GSH TR ``` -------------------------------- ### Toss Open API Endpoint Source: https://github.com/smallfish06/krsec/blob/main/README.md Calls Toss Open API endpoints. Validates path/method based on official OpenAPI snapshot. ```APIDOC ## POST /toss/{path...} ### Description Calls Toss Open API endpoints. Validates path/method based on official OpenAPI snapshot. ### Method POST ### Endpoint /toss/{path...} ### Request Example ```bash curl -X POST http://localhost:8080/toss/api/v1/prices \ -H "Content-Type: application/json" \ -d '{"query":{"symbols":"005930,AAPL"}}' ``` ```bash curl -X POST http://localhost:8080/toss/api/v1/orders \ -H "Content-Type: application/json" \ -d '{ "account_id": "toss-main", "method": "POST", "body": { "clientOrderId": "my-order-001", "symbol": "005930", "side": "BUY", "orderType": "LIMIT", "quantity": "10", "price": "70000" } }' ``` ``` -------------------------------- ### Kiwoom Spec Management: Check Drift Source: https://github.com/smallfish06/krsec/blob/main/README.md CI command to check for generated file drift in Kiwoom API specifications. Ensures that generated code matches the snapshot. ```bash make kiwoom-spec-check ``` -------------------------------- ### KIS Endpoint Source: https://github.com/smallfish06/krsec/blob/main/README.md Calls static endpoints registered in the KIS documentation specification. Excludes the '/uapi' prefix. ```APIDOC ## POST /kis/ ### Description Calls static endpoints registered in the KIS documentation specification. ### Method POST ### Endpoint /kis/ ### Request Example ```bash curl -X POST http://localhost:8080/kis/overseas-price/v1/quotations/price \ -H "Content-Type: application/json" \ -d '{ "tr_id": "HHDFS00000300", "params": { "AUTH": "", "EXCD": "NAS", "SYMB": "AAPL" } }' ``` ``` -------------------------------- ### LS Spec Management: Check Drift Source: https://github.com/smallfish06/krsec/blob/main/README.md CI command to check for generated file drift in LS API specifications. Ensures that generated code matches the snapshot. ```bash make ls-spec-check ``` -------------------------------- ### LS Spec Management: Refresh Snapshot Source: https://github.com/smallfish06/krsec/blob/main/README.md Command to refresh the LS API specification snapshot and regenerate associated files. This updates the codebase with the latest API definitions. ```bash make ls-spec-refresh ``` -------------------------------- ### Toss Spec Management: Check Drift Source: https://github.com/smallfish06/krsec/blob/main/README.md CI command to check for generated file drift in Toss API specifications. Ensures that generated code matches the snapshot. ```bash make toss-spec-check ``` -------------------------------- ### Kiwoom Spec Management: Refresh Snapshot Source: https://github.com/smallfish06/krsec/blob/main/README.md Command to refresh the Kiwoom API specification snapshot and regenerate associated files. This updates the codebase with the latest API definitions. ```bash make kiwoom-spec-refresh ``` -------------------------------- ### KIS Spec Management: Check Drift Source: https://github.com/smallfish06/krsec/blob/main/README.md CI command to check for generated file drift in KIS API specifications. Ensures that generated code matches the snapshot. ```bash make kis-spec-check ``` -------------------------------- ### Kiwoom Endpoint Source: https://github.com/smallfish06/krsec/blob/main/README.md Calls Kiwoom endpoints. Maps '/api' path + 'api_id' based on implementation/documentation snapshots (non-websocket REST). ```APIDOC ## POST /kiwoom/{path...} ### Description Calls Kiwoom endpoints. Maps '/api' path + 'api_id' based on implementation/documentation snapshots (non-websocket REST). ### Method POST ### Endpoint /kiwoom/{path...} ``` -------------------------------- ### Call LS Stock Market Data API Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a POST request to the LS API to retrieve stock market data. Requires specifying the TR code and parameters for the input block. ```bash curl -X POST http://localhost:8080/ls/stock/market-data \ -H "Content-Type: application/json" \ -d '{ "tr_cd": "t1102", "params": { "t1102InBlock": { "shcode": "078020", "exchgubun": "K" } } }' ``` -------------------------------- ### KIS Spec Management: Refresh Snapshot Source: https://github.com/smallfish06/krsec/blob/main/README.md Command to refresh the KIS API specification snapshot and regenerate associated files. This updates the codebase with the latest API definitions. ```bash make kis-spec-refresh ``` -------------------------------- ### LS OpenAPI Endpoint Source: https://github.com/smallfish06/krsec/blob/main/README.md Calls LS OpenAPI endpoints. Passes 'tr_cd' and request block, validating REST TR based on documentation snapshots. ```APIDOC ## POST /ls/{path...} ### Description Calls LS OpenAPI endpoints. Passes 'tr_cd' and request block, validating REST TR based on documentation snapshots. ### Method POST ### Endpoint /ls/{path...} ### Request Example ```bash curl -X POST http://localhost:8080/ls/stock/market-data \ -H "Content-Type: application/json" \ -d '{ "tr_cd": "t1102", "params": { "t1102InBlock": { "shcode": "078020", "exchgubun": "K" } } }' ``` ```bash curl -X POST http://localhost:8080/ls/overseas-stock/market-data \ -H "Content-Type: application/json" \ -d '{ "tr_cd": "g3101", "params": { "g3101InBlock": { "delaygb": "R", "keysymbol": "82AAPL", "exchcd": "82", "symbol": "AAPL" } } }' ``` ``` -------------------------------- ### Toss Spec Management: Refresh Snapshot Source: https://github.com/smallfish06/krsec/blob/main/README.md Command to refresh the Toss OpenAPI snapshot and regenerate associated files. This updates the codebase with the latest API definitions. ```bash make toss-spec-refresh ``` -------------------------------- ### Call LS Overseas Stock Market Data API Source: https://github.com/smallfish06/krsec/blob/main/README.md Make a POST request to the LS API for overseas stock market data. Requires specifying the TR code and detailed parameters for the input block. ```bash curl -X POST http://localhost:8080/ls/overseas-stock/market-data \ -H "Content-Type: application/json" \ -d '{ "tr_cd": "g3101", "params": { "g3101InBlock": { "delaygb": "R", "keysymbol": "82AAPL", "exchcd": "82", "symbol": "AAPL" } } }' ``` -------------------------------- ### Cancel Order Source: https://github.com/smallfish06/krsec/blob/main/README.md Cancels a specific order for a specified account. ```APIDOC ## DELETE /accounts/{account_id}/orders/{id} ### Description Cancels a specific order for a specified account. ### Method DELETE ### Endpoint /accounts/{account_id}/orders/{id} ``` -------------------------------- ### Amend Order Source: https://github.com/smallfish06/krsec/blob/main/README.md Modifies an existing order for a specified account. ```APIDOC ## PUT /accounts/{account_id}/orders/{id} ### Description Modifies an existing order for a specified account. ### Method PUT ### Endpoint /accounts/{account_id}/orders/{id} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.