### Install ctpbee on Mac (pip) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/install.md Installs the ctpbee library on macOS. Requires first installing the ctpbee_api directly from the GitHub repository using pip3. ```bash # 如果你的网速不行, 可以使用gitee导入此项目 pip3 install git+https://github.com/ctpbee/ctpbee_api pip3 install ctpbee ``` -------------------------------- ### Install ctpbee on Windows (pip) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/install.md Installs the ctpbee library using pip3 on a Windows operating system. ```bash pip3 install ctpbee ``` -------------------------------- ### Initialize Chinese Locale on Linux (bee CLI) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/install.md Uses the ctpbee CLI tool to initialize Chinese locale support on Linux. Provides commands for both root and user (with sudo) initialization. ```bash # linux用户快速生成中文支持/ windows用户无须设置 ## for root bee init-locale ## for user, xxx为你的用户密码, 注意你当前用户需要拥有sudo权限 bee init-locale --password xxxxx ``` -------------------------------- ### Install ctpbee on Linux (pip) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/install.md Installs the ctpbee library using pip3 on a Linux operating system. Requires prior installation of gcc tools. ```bash pip3 install ctpbee ``` -------------------------------- ### Getting ctpbee System Path Output (ctpbee, Text) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Provides an example of the output from calling `get_ctpbee_path`, showing a typical path structure which may vary based on the user's operating system and username. ```textmate ctpbee path: /home/somewheve/.ctpbee ``` -------------------------------- ### Replacing ctpbee_api SO Files and Installing (Linux Bash) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/error.md Provides steps to replace the CTP API .so files within the ctpbee_api project directory on Linux before compiling and installing the package using pip3. ```bash # 假设你当前目录下已经下载 thosttraderapi_se.so 和 thostmduserapi_se.so # linux使用的即时编译技术 所以需要在编译之前替换so文件 先下载ctpbee_api项目 git clone https://github.com/ctpbee/ctpbee_api # 复制并替换依赖库 此处注意需要添加lib前缀 cp ./thosttraderapi_se.so ./ctpbee_api/ctpbee_api/ctp/libthosttraderapi_se.so cp ./thostmduserapi_se.so ./ctpbee_api/ctpbee_api/ctp/libthostmduserapi_se.so # 进入到以下目录, 然后使用pip3进行编译安装 cd ./ctpbee_api pip3 install . ``` -------------------------------- ### Locating ctpbee_api Installation for DLL Replacement (Windows Bash) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/error.md Provides instructions using pip3 show to find the installation directory of ctpbee_api on Windows. This location is where users should copy replacement DLL files for the CTP API. ```bash pip3 install ctpbee_api pip3 show ctpbee_api # 会显示下面信息 Name: ctpbee_api Version: 0.45 Summary: Trading API support for China Future Home-page: https://github.com/ctpbee/ctpbee_api Author: somewheve Author-email: somewheve@gmail.com License: MIT Location: c:\users\somew\appdata\local\programs\python\python39\lib\site-packages Requires: Required-by: ctpbee # 然后找到Location目录 并添加ctpbee_api 如果要替换ctp, 那么目录路径再增加一个ctp 然后复制同名dll到下方路径 c:\users\somew\appdata\local\programs\python\python39\lib\site-packages\ctpbee_api\ctp ``` -------------------------------- ### Initializing CtpBee with Kline Plugin (Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/error.md Demonstrates how to initialize a CtpBee application and integrate the ctpbee_kline plugin. This setup is typically used to enable k-line data processing within the application. ```python from ctpbee import CtpbeeApi, CtpBee from ctpbee.constant import * from ctpbee_kline import Kline kline = Kline() app = CtpBee("market", __name__, refresh=True).with_tools(kline) ``` -------------------------------- ### Switching Current App Context Output (ctpbee, Text) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Shows the console output when running the `switch_app` example, demonstrating how the `current_app.name` changes as different App objects are switched to the active context. ```textmate ctpbee1 ctpbee2 ctpbee3 ``` -------------------------------- ### Getting ctpbee System Path (ctpbee, Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Explains the `get_ctpbee_path` function which returns the default directory path used by the ctpbee system for configuration or data storage. ```python from ctpbee import get_ctpbee_path path = get_ctpbee_path() print("path: ", path) ``` -------------------------------- ### Getting Current App Object (ctpbee, Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Explains how to access the active App object from anywhere in the application using `current_app`, which acts as a proxy to the core App. ```python from ctpbee import current_app app = current_app() ``` -------------------------------- ### Initializing CtpBee Core Application (Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/module.md This snippet demonstrates how to import the `CtpBee` class and create the main application instance. The constructor requires two parameters: a unique string identifier for the account (e.g., "somewheve") and the current module's name (`__name__`). These parameters are essential for isolating account data and identifying the module. ```python from ctpbee import CtpBee app = CtpBee("somewheve", __name__) ``` -------------------------------- ### Retrieving App Object by Name (ctpbee, Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Demonstrates how to retrieve a specific App object by providing the name used during its creation, confirming that subsequent calls with the same name return the identical object instance. ```python from ctpbee import CtpBee, get_app app1 = CtpBee("hello1", __name__) # 假定你已经通过上述代码创建了名为somewheve的App,那么下面代码将让你获取该app app2 = get_app("hello1") assert app1 == app2 ``` -------------------------------- ### Sending Order Request (ctpbee, Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Describes the `send_order` API for submitting trading orders, requiring an order request object and optionally an app name. Mentions using the `helper` module to facilitate request generation. ```python from ctpbee import send_order from ctpbee import helper # 通过helper提供的方法来快速生成报单请求 ``` -------------------------------- ### Switching Current App Context (ctpbee, Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/API.md Illustrates how to change the active App context by pushing a specified App onto the top of the stack, making it the target for operations via `current_app`. ```python from ctpbee import current_app, switch_app, CtpBee app = CtpBee("hello1", __name__) print(current_app.name) app2 = CtpBee("hello2", __name__) # 此时候你会发现current_app2被切换到 current_app上面去 print(current_app.name) # 现在通过调用switch_app将yutiansut1再次切换到栈顶, 也就是current_app上面 switch_app("hello1") print(current_app.name) ``` -------------------------------- ### Defining a Custom Log Handler with ctpbee VLogger (Python) Source: https://github.com/ctpbee/ctpbee_tutorial/blob/master/modules/log.md This snippet defines a function `handler_record` intended to be used as a custom log handler within the ctpbee framework. Decorated with `@VLogger()`, it receives log record data, formats a message string containing time, name, level, owner, and message, and prints it to the console. It includes a placeholder comment for implementing further log processing. ```Python from ctpbee import VLogger @VLogger() def handler_record(**record): msg = f"{record['time'].split(' ')[1]} {record['name']} {record['level']} {record['owner']} {record['message']}" print(msg) # todo: 实现log处理 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.