Skip to content

No-Trade-No-Life/Yuan

Repository files navigation

English | 简体中文

Language TS Contributors Forks Stargazers MIT License

Discord Issues Bugs Open Bugs Closed


Logo

Yuan

Personal Investment Operating System

AI empowered, global market, serverless, cloud-native, and privacy.

Access the Yuan GUI from any device »

Read the Docs 📖 · Report Bug 🐛 · Request Feature 💡 · Join Discord

Snapshots

image

image

image

Motivation

In the early stages of our quantitative trading endeavors, after extensively searching and researching various existing quantitative trading frameworks and products, we found that none could fully meet the development and research needs of our unique trading strategies. Thus, undeterred by the challenges, we embarked on creating our own product, Yuan, driven by our specific requirements.

Our basic requirements are:

  1. Strong Privacy Security

    Quantitative model code is the core asset of users and is at risk of being stolen. Many products on the market require uploading strategy code to servers, and these products can fully evaluate and steal the code as long as they have the user's code. If the user's strategy can be grasped by potential competitors, the user will be at a disadvantage. Therefore, there are also some products on the market that allow private deployment. We have designed a local workspace for users to ensure that their privacy is protected from being stolen by anyone, including the Yuan project team. Additionally, we have completed open-source, subject to the supervision of the open-source community, and will not do anything in the code that harms the interests of users.

  2. Full Market Compatibility

    Users invest and trade in different markets. We hope that the same strategy code can be applied to different market varieties, both for historical backtesting and real-time trading, without any additional cost. We also hope that the platform product can support various types of markets. However, due to regional laws and regulations and some business restrictions, products on the market usually only support a part of the markets, forcing users to use different platforms in different markets. Through architectural design, we decouple specific market modules, not only improving software quality but also overcoming compliance obstacles, paving the way for the globalization of the product.

  3. Cross-Platform Compatibility

    We hope that our product can run without restrictions on any device on any platform, whether on desktop or mobile. After all, the market does not care about the user's situation. Users can switch to work and interact with the market at any time in any scenario.

  4. Low Cost and High Scalability

    Industry initial licensing fees often reach thousands, not to mention the high additional and maintenance costs. We believe that these costs are partly due to bundling sales to offset development costs, partly due to inefficiency, and partly due to the desire to profit. As a product aimed at individual investors rather than enterprises, we must consider the consumption ability of ordinary investors. For investors, the most important aspect of tools is cheap and durable. Whether on personal computers or server clusters, our product can run effectively. Yuan is an investment operating system designed to empower you to master your finances.

(back to top)

Why use Yuan

Powerful Web GUI

With Yuan Web GUI, you have access to a comprehensive solution for creating, testing, and managing your trading system, as well as deploying and monitoring your applications. The GUI is completely open-source and can be deployed anywhere, without an internet connection. You can easily switch between multiple environments using just one GUI, making your experience more streamlined.

We have designed the GUI with modern browsers in mind, and it integrates with the latest web technologies, such as WebWorker, FileSystemHandle, WebRTC, and more. It is highly responsive and fast, and we are constantly working to make it even better for you.

Although the GUI is currently written in Chinese, we have plans to make it internationalized, so you can use it in your native language in the future. We welcome contributions to the project's translation, so everyone can benefit from this amazing tool. You can access the GUI for free under the MIT license, without the need to install anything - simply use the GUI.

Simple language and AI assistant

If you're interested in developing a trading strategy without the need to learn a new language or DSL, the modern JavaScript/TypeScript language is an excellent option. You can use any IDE to write your code and any version control system to manage it. If you have difficulty with coding, you can seek assistance from an AI assistant by communicating your idea to it.

// It's a simple trend-tracking trading strategy that uses the SMA indicator.
import { useSMA, useSimplePositionManager } from '@libs';
export default () => {
  const { close } = useOHLC('Y', 'XAUUSD', 'PT1H');
  const ma20 = useSMA(close, 20);
  const accountInfo = useAccountInfo();
  const [targetVolume, setTargetVolume] = useSimplePositionManager(accountInfo.account_id, 'XAUUSD');
  useEffect(() => {
    const idx = close.length - 2;
    if (close[idx] > ma20[idx]) {
      setTargetVolume(1);
    } else {
      setTargetVolume(0);
    }
  }, [close.length]);
};

More examples can be found here.

Local, cloud...or hybrid!

Yuan is a hybrid-cloud software that allows you to deploy your trading system in your home or public cloud simultaneously. You can start using your home PC and then gradually switch to the public cloud as your business grows. Choosing between your home PC or the public cloud will depend on your availability, costs, privacy, and security requirements.

Extension-first Ecosystem

In Yuan, extensions are treated as first-class citizens. Many core features are built and distributed as extensions. You can use extensions to add new features, connect with more markets, and enhance your experience. You can download extensions from the community or create your own extensions to share with others.

(back to top)

Built with

TypeScript reactivex react kubernetes docker prometheus mongodb zeromq openai nginx pnpm monaco editor vite rollup ajv webrtc letsencrypt

(back to top)

Getting started (for developers) 🚀

Prerequisites: nodejs >= 18.17.0, docker for image build, and rush for mono repo management.

npm install -g @microsoft/rush

Then you can install dependencies and build projects

rush update && rush build

If you have no docker installed, you can skip the docker build by setting the environment variable CI_RUN to true.

CI_RUN=true rush build

(back to top)

Packages

Libraries

All the libraries should be independent of the platform by default. They can be used in the browser, node.js, or other platforms. And provide both ESM and CommonJS modules.

  • @yuants/data-model Data Model and related utils.
  • @yuants/protocol Network protocol, service definition and infrastructure.
  • @yuants/utils Some general utils that are not found in the community.
  • @yuants/kernel The kernel of Time-Machine. Time-Machine can travel from history to the future. This package also contains some useful units and scenes.
  • @yuants/agent Agent is a trading bot. The agent contains the core of the trading strategy.
  • @yuants/extension This defined the extension interface. You can use extensions to enhance your experience.
  • @yuants/prometheus-client Prometheus client for the browser / node. Better performance than promjs.

Apps

All the apps should provide an image and publish it as a npm package. You can deploy the app by docker and Kubernetes. You can find the App List and get the image. All the apps implemented the extension interface. So you can treat them as extensions.

  • @yuants/app-host Host is a very lightweight message broker. Terminals can connect to the host and send messages to each other. Notice that all terminals in a host should trust each other. In practice, all the terminals in a host belong to the same owner. There's no need to verify every message. You can deploy multiple hosts to isolate the risk.
  • @yuants/app-market-data-collector This will deploy a terminal as a data-collecting service. The terminal collects market data from the market terminals continuously.
  • @yuants/app-data-collector This will deploy a terminal as a data-collecting service. The terminal collects series data from the data series provider terminals continuously. It's a general version of the market data collector. You can use it to collect any data series.
  • @yuants/app-agent This will deploy a terminal as the daemon service of the agent. You can run the agent in real mode. It can automatically correct the history data error. It can also automatically restart the agent when it crashes.
  • @yuants/app-alert-receiver This will deploy a terminal as an alert-receiving service. It receives alerts from the alert terminals and sends them to the notifier terminals.
  • @yuants/app-mongodb-storage This will deploy a terminal as a storage service. It stores data in MongoDB.
  • @yuants/app-email-notifier This will deploy a terminal as a notifier service. It sends notifications to your email.
  • @yuants/app-feishu-notifier This will deploy a terminal as a notifier service. It sends notifications to your Feishu by a Feishu bot.
  • @yuants/app-trade-copier This will deploy a terminal as a trade copier service. It watches the source accounts and ensures the target accounts follow the source accounts.
  • @yuants/app-metrics-collector This will deploy a terminal as a metrics-collecting service. The metrics collector collects metrics from terminals continuously. It works with Prometheus.
  • @yuants/app-account-composer This will deploy a terminal as an account-composing service. It composes multiple account info into one account info. So you can view your money dispersed across many accounts.
  • @yuants/app-general-datasource This will deploy a terminal as a general data source service. It composes multiple specific data sources into one general data source. Useful for creating an index price series.
  • @yuants/app-general-realtime-data-source This will deploy a terminal as a general real-time data source service. It's the real-time version of the general data source. Useful for creating an index price ticks.
  • @yuants/app-k8s-manifest-operator This will deploy a terminal as a Kubernetes manifest operator. It watches the manifest CRD of the Kubernetes cluster and ensures the Kubernetes cluster follows the manifest CRD. You can add manifest CRD to the k8s cluster and then the operator will deploy the resources defined in the manifest CRD.
  • @yuants/app-transfer-controller A transfer controller is a service that transfers money between accounts. It watches the transfer request and ensures the transfer is completed.
  • @yuants/app-risk-manager This will deploy a terminal as a risk manager. It makes transfer decisions based on the configured risk info.
  • @yuants/app-hosts This is a very lightweight host cluster that can handle message forwarding business for multiple hosts within a single process. There is no need to pre-register the host's token table; it can automatically accept terminals that comply with ED25519 signatures, and terminals do not need to send the signed private key to the host. It is highly suitable for multi-tenant environments and scenarios that require low-cost creation of multiple hosts.
  • @yuants/app-portal This will deploy a service that allows sharing existing services (and channels) from a host with other hosts. It acts as an intermediary, capable of forwarding messages from one host to another. It is a very powerful tool that can help you build data sharing scenarios.
  • @yuants/app-namespaced-mongodb-storage This will deploy a terminal as a storage service. It stores data in MongoDB and supports namespaces. This means you can store data for multiple tenants within the same MongoDB instance.
  • @yuants/app-prometheus-client This will deploy a terminal as a Prometheus client. It provides a service for querying data from the Prometheus database, making it suitable for building monitoring dashboards.

Web UI

@yuants/ui-web, you can directly access https://y.ntnl.io to access the Yuan GUI.

The graphical user interface (GUI) is the most widely used human-computer interaction interface today. It can do everything that command-line interfaces (CLI), natural language interfaces (NUI, LUI), and other interfaces can do.

  • Single-line Deployment: All users use the same, latest version of the GUI.
  • Strong Privacy: The content of the workspace used by the GUI is completely confidential.
  • Extensibility: You can install extensions to enhance your workspace.
  • Multi-device Adaptation: Any device with a modern browser can access the GUI and its features. We will continuously improve multi-device adaptability.
  • PWA Support: The GUI can be installed as a desktop application via PWA. Mobile devices can also use PWA to install to the home screen.

Distributions

Yuan is a powerful operating system, but it is also too low-level, primitive, and difficult to use. Only tech-savvy users can handle it, and it is not suitable for direct use by ordinary users.

For different user scenarios, it is best to provide specific distributions that are pre-configured with some features so that users can use them directly.

Below are some distributions we provide as references. You can create your own distributions based on your needs.

Creating a Distribution

The essence of a distribution is a workspace, and the essence of a workspace is a file directory and its contents. We can package the workspace into a distribution, and then users can download and unzip it to use. We recommend using the npm package management tool to manage distributions, i.e., distributions will be published to the npm repository, and users can install distributions via npm.

In the Web GUI's address parameters, we can specify installing the distribution from npm using the from_npm parameter. For example, https://y.ntnl.io?from_npm=1&scope=yuants&name=dist-origin.

URL Parameters:

  • from_npm: Whether to install the distribution from npm. 1 for yes, leave empty for no.
  • scope: The scope of the npm package, optional parameter.
  • name: The name of the npm package, required parameter.
  • version: The version of the npm package, in the format of a semver compliant version range, optional parameter. Defaults to the latest version.
// Install the latest version of the @yuants/dist-origin distribution
https://y.ntnl.io?from_npm=1&scope=yuants&name=dist-origin

// Install a specific version (0.0.2) of the @yuants/dist-origin distribution
https://y.ntnl.io?from_npm=1&scope=yuants&name=dist-origin&version=0.0.2

// Install a specific version (>=0.0.2) of the @yuants/dist-origin distribution
https://y.ntnl.io?from_npm=1&scope=yuants&name=dist-origin&version=>=0.0.2

Documents

@yuants/docs is the document of Yuan.

It's built by Docusaurus. You can find the latest documents here.

Toolkit

@yuants/tool-kit is all you need. This provides a CLI when you need to build an extension. It helps you to build a docker image, create a bundle and more. To ensure your extension is ready to use.

Vendors

Vendors include markets, exchanges, and data sources. You can access the global market through various vendors. For some legal reason, they are probably not open to everyone. But you can use them if you gain permission from the provider.

Every vendor is a gateway to connect the external service directly. Your private data including account info and market data will not be stored in Yuan Cloud Service. You can deploy the vendor in your own cloud or local machine.

  • @yuants/vendor-ctp This connects to the "Comprehensive Transaction Platform" (CTP). The CTP platform was developed by the Shanghai Futures Exchange (SHFE). CTP provides China's future exchanges. To comply with regulations, you might have to request permission from your broker company.

  • @yuants/vendor-ccxt This connects to the "CryptoCurrency eXchange Trading Library" (CCXT). CCXT is a JavaScript / Python / PHP cryptocurrency trading library that supports many cryptocurrency exchanges and trading markets. You can use it to trade cryptocurrencies.

  • @yuants/vendor-binance This connects to Binance, which is a famous crypto exchange.

  • @yuants/vendor-okx This connects to OKX, which is a famous crypto exchange.

  • @yuants/vendor-huobi This connects to Huobi, which is a famous crypto exchange.

  • @yuants/vendor-gate This connects to Gate, which is a famous crypto exchange.

  • @yuants/vendor-bitget This connects to BitGet, which is a famous crypto exchange.

  • @yuants/vendor-coinex This connects to CoinEX, which is a famous crypto exchange.

(back to top)

Contributing

Contributions make the open-source community a fantastic place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open a feature request issue. Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contributors

Thanks sincerely to the contributors:

Zheng Chen
Zheng Chen

🧑‍🏫 💻 🎨 👀
Siyuan Wang
Siyuan Wang

💻 🚇
Jinhaolin
Jinhaolin

💻
Hobo Chen
Hobo Chen

🐛
Yalun Lin Hsu
Yalun Lin Hsu

💻
SakurazukaKen
SakurazukaKen

💻
Haoran Ren
Haoran Ren

💻
pruderior
pruderior

💻
playground
playground

💻

(back to top)

Contact

  • Join Discord server: Discord

(back to top)

Acknowledgments 📖

  1. Yuan-Public-Workspace You can learn how to write strategy models from this repository. You can import it to your workspace from the GUI. The repository is embedded in AI with a vector database. Contribute with your examples is greatly appreciated!
  2. Yuan-Public-Data Our public data is maintained here as a repository. Free to use. Welcome to contribute if you have other data!

(back to top)

Star History

Star History Chart

(back to top)