Skip to content

Commit

Permalink
优化 "Getting Started" 上关于 Env 配置的内容,并且列出有的环境变量。 (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored May 21, 2024
1 parent ed82986 commit e15ec4c
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 112 deletions.
89 changes: 55 additions & 34 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,44 @@ go get github.com/longportapp/openapi-go

下面我们以获取资产为例,演示一下如何使用 SDK。

## 配置开发者账户
## 配置

### 开通开发中账户

1. 下载 [LongPort](https://longportapp.com/download),并完成开户
2. 完成 Python 3 环境安装,并安装 Pip
3.[LongPort OpenAPI](https://open.longportapp.com) 官网获取 `App Key`, `App Secret`, `Access Token` 等信息。
2.[LongPort OpenAPI](https://open.longportapp.com) 官网获取 `App Key`, `App Secret`, `Access Token` 等信息。

**_获取 App Key, App Secret, Access Token 等信息_**
**_获取 App Key, App Secret, Access Token 等信息_**

访问 [LongPort OpenAPI](https://open.longportapp.com) 网站,登录后,进入“个人中心”。
访问 [LongPort OpenAPI](https://open.longportapp.com) 网站,登录后,进入“个人中心”。

在页面上会给出“应用凭证”凭证信息,我们拿到以后设置环境变量,便于后面开发使用方便。
在页面上会给出“应用凭证”凭证信息,我们拿到以后设置环境变量,便于后面开发使用方便。

:::tip 关于环境变量
### 环境变量

:::caution
请注意保护好您的 **Access Token** 信息,任何人获得到它,都可以通过 OpenAPI 来交易你的账户!
:::

建议您设置好 `LONGPORT_APP_KEY`, `LONGPORT_APP_SECRET`, `LONGPORT_ACCESS_TOKEN` 这几个环境变量。我们为了演示方便,后面各章节文档中的示例代码都会使用这几个环境变量。
| 环境变量 | 说明 | 值范围 |
| --------------------------- | ------------------------------------------------------------ | --------------- |
| `LONGPORT_APP_KEY` | 从页面上获取到的 App Key | |
| `LONGPORT_APP_SECRET` | 从页面上获取到的 App Secret | |
| `LONGPORT_ACCESS_TOKEN` | 从页面上获取到的 Access Token | |
| `LONGPORT_REGION` | API 服务器接入点,请根据你所在地区设置,以获得更好的连接速度 | `hk`, `cn` |
| `LONGPORT_ENABLE_OVERNIGHT` | 是否开启夜盘行情,设置 `true` 开启,`false` 关闭 | `true`, `false` |

建议您设置好这几个环境变量,我们后面各章节文档中的示例代码都会使用这几个环境变量。

:::tip 关于环境变量

环境变量**非必要**条件,如设置不方便或遇到问题难以解决,可不用环境变量,而是直接在代码里用参数来初始化。

LongPort OpenAPI SDK 的 `Config` 均可以直接传入 `app_key`, `app_secret`, `access_token` 等参数来初始化,注意看后面的例子注释内 `Init config without ENV` 的部分。

:::

### macOS / Linux 环境下设置环境变量
#### macOS / Linux 环境下设置环境变量

打开终端,输入下面的命令即可:

Expand All @@ -136,43 +151,49 @@ export LONGPORT_APP_SECRET="从页面上获取到的 App Secret"
export LONGPORT_ACCESS_TOKEN="从页面上获取到的 Access Token"
```

### Windows 下设置环境变量
#### Windows 下设置环境变量

Windows 要稍微复杂一些,按下 `Win + R` 快捷键,输入 `cmd` 命令启动命令行(建议使用 [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) 获得更好的开发体验)。
Windows 要稍微复杂一些,有下面两种方式可以设置环境变量:

在命令行里面输入下面的命令设置环境变量:
1. **通过图形界面设置**:在桌面上找到“我的电脑”,右键点击,选择“属性”,在弹出的窗口中点击“高级系统设置”。

```bash
C:\Users\jason> setx LONGPORT_APP_KEY "从页面上获取到的 App Key"
成功:指定的值已得到保存。
- 在弹出的窗口中点击“环境变量”。

C:\Users\jason> setx LONGPORT_APP_SECRET "从页面上获取到的 App Secret"
成功:指定的值已得到保存。
<img src="https://assets.lbkrs.com/uploads/82e31e5e-6062-4726-966b-2a72954f4192/windows-env-set.png" width="500" />

C:\Users\jason> setx LONGPORT_ACCESS_TOKEN "从页面上获取到的 Access Token"
成功:指定的值已得到保存。
```
- 在弹出的窗口中点击“新建”,然后输入环境变量名称,比如 `LONGPORT_APP_KEY``Value` 分别填写从页面上获取到的 App Key,App Secret,Access Token,Region。

:::caution Windows 环境变量
2. **CMD 命令行设置**:按下 `Win + R` 快捷键,输入 `cmd` 命令启动命令行(建议使用 [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) 获得更好的开发体验)。

Windows 环境变量限制,当上面 3 条命令执行成功以后,你需要重新启动 Windows 或者注销后重新登录一次,才可以读取到。
在命令行里面输入下面的命令设置环境变量:

:::
```bash
C:\Users\jason> setx LONGPORT_APP_KEY "从页面上获取到的 App Key"
成功:指定的值已得到保存。

注销或重新启动后,再次打开命令行,输入下面的命令验证一下环境变量是否设置正确:
C:\Users\jason> setx LONGPORT_APP_SECRET "从页面上获取到的 App Secret"
成功:指定的值已得到保存。

```bash
C:\Users\jason> set LONGPORT
LONGPORT_APP_KEY=xxxxxxx
LONGPORT_APP_SECRET=xxxxxx
LONGPORT_ACCESS_TOKEN=xxxxxxx
```
C:\Users\jason> setx LONGPORT_ACCESS_TOKEN "从页面上获取到的 Access Token"
成功:指定的值已得到保存。
```

如果能正确打印你刚才设置的值,那么环境变量就是对了。
:::caution Windows 环境变量

:::caution
请注意保护好您的 **Access Token** 信息,任何人获得到它,都可以通过 OpenAPI 来交易你的账户!
:::
Windows 环境变量限制,当上面命令执行成功以后,你需要重新启动 Windows 或者注销后重新登录一次,才可以读取到。

:::

注销或重新启动后,再次打开命令行,输入下面的命令验证一下环境变量是否设置正确:

```bash
C:\Users\jason> set LONGPORT
LONGPORT_APP_KEY=xxxxxxx
LONGPORT_APP_SECRET=xxxxxx
LONGPORT_ACCESS_TOKEN=xxxxxxx
```

如果能正确打印你刚才设置的值,那么环境变量就是对了。

## 场景示范

Expand Down
95 changes: 57 additions & 38 deletions i18n/en/docusaurus-plugin-content-docs/current/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,42 @@ go get github.com/longportapp/openapi-go

Let's take obtaining assets as an example to demonstrate how to use the SDK.

## Configure Developer Account
## Configuration

1. Download App and open an account.
2. Complete the Python 3 environment installation and install Pip
3. Get App Key, App Secret, Access Token and other information from [LongPort OpenAPI](https://open.longportapp.com) official website
2. Get App Key, App Secret, Access Token and other information from [LongPort OpenAPI](https://open.longportapp.com) official website

**_Get App Key, App Secret, Access Token and other information_**
**_Get App Key, App Secret, Access Token and other information_**

Login the [LongPort OpenAPI](https://open.longportapp.com) website, and enter the "User Center".
Login the [LongPort OpenAPI](https://open.longportapp.com) website, and enter the "User Center".

The "application credential" credential information will be given on the page. After we get it, we will set the environment variable, which is convenient for later development and use.
The "application credential" credential information will be given on the page. After we get it, we will set the environment variable, which is convenient for later development and use.

### Setting Environment Variables In macOS / Linux Environment
### Environment Variables

:::caution
Please pay attention to protect your **Access Token** information, anyone who gets it can trade your account through OpenAPI!
:::

| 环境变量 | 说明 | 值范围 |
| --------------------------- | ------------------------------------------------------------------ | --------------- |
| `LONGPORT_APP_KEY` | App Key get from developer center | |
| `LONGPORT_APP_SECRET` | App Secret get from developer center | |
| `LONGPORT_ACCESS_TOKEN` | Access Token get from developer center | |
| `LONGPORT_REGION` | The region of the API, `cn` for mainland China, `hk` for Hong Kong | `cn`, `hk` |
| `LONGPORT_ENABLE_OVERNIGHT` | Set `true` to enable overnight quote | `true`, `false` |

We recommend that you set the environment variables. For the convenience of demonstration, these environment variables will be used in the sample code in the documents in the following chapters.

:::tip About ENV

The ENV variables are **not necessary** conditions, if it is inconvenient to set the ENV variables or encounter problems that are difficult to solve, you can not set the ENV variables, but directly use the parameters in the code to initialize.

The `Config` in LongPort OpenAPI SDK can be directly passed in parameters such as `app_key`, `app_secret`, `access_token` to initialize, pay attention to the comments in the example code below `Init config without ENV`.

:::

#### Set Environment for macOS / Linux

Open the terminal and enter the following command:

Expand All @@ -126,53 +149,49 @@ export LONGPORT_APP_SECRET="App Secret get from user center"
export LONGPORT_ACCESS_TOKEN="Access Token get from user center"
```

:::tip About ENV
#### Set Environment for Windows

We recommend that you set the environment variables `LONGPORT_APP_KEY`, `LONGPORT_APP_SECRET`, `LONGPORT_ACCESS_TOKEN`. For the convenience of demonstration, these environment variables will be used in the sample code in the documents in the following chapters.
Windows is a little more complicated, we provide two methods to set the environment variables.

The ENV variables are **not necessary** conditions, if it is inconvenient to set the ENV variables or encounter problems that are difficult to solve, you can not set the ENV variables, but directly use the parameters in the code to initialize.
1. **Through the GUI**: Right click on "My Computer" on the desktop, select "Properties", click "Advanced system settings" in the pop-up window.

The `Config` in LongPort OpenAPI SDK can be directly passed in parameters such as `app_key`, `app_secret`, `access_token` to initialize, pay attention to the comments in the example code below `Init config without ENV`.
- Click "Environment Variables" in the pop-up window.

:::

### Setting Environment Variables In Windows Environment
<img src="https://assets.lbkrs.com/uploads/82e31e5e-6062-4726-966b-2a72954f4192/windows-env-set.png" width="500" />

Windows is a little more complicated, press the `Win + R` shortcut keys and enter the `cmd` command to start the command line (it is recommended to use [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) for a better development experience).
- Click "New" in the pop-up window, then enter the environment variable name, such as `LONGPORT_APP_KEY`, `Value` respectively fill in the App Key, App Secret, Access Token, Region obtained from the page.

Enter the following command in the command line to set the environment variable:
2. **Through the CMD**: Press the `Win + R` shortcut keys and enter the `cmd` command to start the command line (it is recommended to use [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) for a better development experience).

```bash
C:\Users\jason> setx LONGPORT_APP_KEY "App Key get from user center"
Success: the specified value has been saved.
Enter the following command in the command line to set the environment variable:

C:\Users\jason> setx LONGPORT_APP_SECRET "App Secret get from user center"
Success: the specified value has been saved.
```bash
C:\Users\jason> setx LONGPORT_APP_KEY "App Key get from user center"
Success: the specified value has been saved.

C:\Users\jason> setx LONGPORT_ACCESS_TOKEN "Access Token get from user center"
Success: the specified value has been saved.
```
C:\Users\jason> setx LONGPORT_APP_SECRET "App Secret get from user center"
Success: the specified value has been saved.

:::caution Windows ENV Restrictions
C:\Users\jason> setx LONGPORT_ACCESS_TOKEN "Access Token get from user center"
Success: the specified value has been saved.
```

Windows ENV Restrictions, when the above 3 commands are executed successfully, you need to restart Windows or log out and log in again before you can read it.
:::caution Windows ENV Restrictions

:::
Windows ENV Restrictions, when the above commands are executed successfully, you need to restart Windows or log out and log in again before you can read it.

After logging out or restarting, open the command line again and enter the following command to verify that the environment variables are set correctly:
:::

```bash
C:\Users\jason> set LONGPORT
LONGPORT_APP_KEY=xxxxxxx
LONGPORT_APP_SECRET=xxxxxx
LONGPORT_ACCESS_TOKEN=xxxxxxx
```
After logging out or restarting, open the command line again and enter the following command to verify that the environment variables are set correctly:

If it prints the value you just set correctly, then the environment variable is right.
```bash
C:\Users\jason> set LONGPORT
LONGPORT_APP_KEY=xxxxxxx
LONGPORT_APP_SECRET=xxxxxx
LONGPORT_ACCESS_TOKEN=xxxxxxx
```

:::caution
Please pay attention to protect your **Access Token** information, anyone who gets it can trade your account through OpenAPI!
:::
If it prints the value you just set correctly, then the environment variable is right.

## Scene Demonstration

Expand Down
Loading

0 comments on commit e15ec4c

Please sign in to comment.