Skip to content

Steampipe plugin for Query from LongPort OpenAPI.

License

Notifications You must be signed in to change notification settings

longportapp/steampipe-plugin-longport

Repository files navigation

LongPort Plugin for Steampipe

Use SQL to query securities, quote from LongPort.

通过 Steampipe 与此插件集成,可以采用 SQL 的方式查询 LongPort 的证券行情和订单数据。

Screenshots

steampipe-plugin-longport

Quick start

Install the plugin with Steampipe:

steampipe plugin install ghcr.io/longportapp/longport

Upgrade new version:

steampipe plugin uninstall ghcr.io/longportapp/longport
steampipe plugin install ghcr.io/longportapp/longport

Open ~/.steampipe/config/longport.spc and setup your AppKey, AppSecret and AccessToken.

You can get them from LongPort OpenAPI.

connection "longport" {
  plugin = "ghcr.io/longportapp/longport"

  # The longport app key. Required.
  # This can also be set via the `LONGPORT_APP_KEY` environment variable.
  # app_key      = "908ed33331781b219f8b850cc4669aa9"

  # The longport app secret. Required.
  # This can also be set via the `LONGPORT_APP_SECRET` environment variable.
  # app_secret   = "ddb3f3898f358257fa192cb0eb2acd615ac7c1377b7d9b4a4633fd4c6e4b155d"

  # The longport access token. Required.
  # This can also be set via the `LONGPORT_ACCESS_TOKEN` environment variable.
  # access_token = "tcwJAQJ7gk8RSijkrs1rN5Sn_L2Z8kAKZ_rIiI023-jJMdnIUO5T0RTl1HN7Q0tImFTHHWhz5KGMcUwHgpl7gwq44NvrR"
}

Alternatively, you can also use the standard Longport environment variables to obtain credentials only if other arguments (app_key, app_secret, and access_token) are not specified in the connection:

export LONGPORT_APP_KEY=908ed33331781b219f8b850cc4669aa9
export LONGPORT_APP_SECRET=ddb3f3898f358257fa192cb0eb2acd615ac7c1377b7d9b4a4633fd4c6e4b155d
export LONGPORT_ACCESS_TOKEN=tcwJAQJ7gk8RSijkrs1rN5Sn_L2Z8kAKZ_rIiI023-jJMdnIUO5T0RTl1HN7Q0tImFTHHWhz5KGMcUwHgpl7gwq44NvrR

Run a query, use steampipe query command to startup Steampipe Query interface.

$ steampipe query

Now you can write SQL now:

select
   symbol,
   name_en,
   exchange,
   currency,
   lot_size,
   total_shares,
   eps
from
   longport_static_info
where
   symbol in
   (
      'BABA.US',
      'TSLA.US',
      '700.HK'
   )
;

Output:

+---------+---------------+----------+----------+--------------+---------------------+
| symbol  | name_en       | exchange | lot_size | total_shares | eps                 |
+---------+---------------+----------+----------+--------------+---------------------+
| AAPL.US | Apple Inc.    | NASD     | 1        | 15552752000  | 6.1607              |
| NFLX.US | Netflix, Inc. | NASD     | 1        | 437679669    | 10.1011             |
| TSLA.US | Tesla, Inc.   | NASD     | 1        | 3178921391   | 4.0201              |
| 700.HK  | TENCENT       | SEHK     | 100      | 9508314888   | 22.1632033382862025 |
+---------+---------------+----------+----------+--------------+---------------------+

Tables

Quote

Trade

License

MIT License