Giter Site home page Giter Site logo

jinxin1688 / algoplus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keyalgo/algoplus

1.0 1.0 0.0 4.53 MB

最忠实于CTP官方API特性、最低延时、最易使用的Python版量化投资开源框架。

License: MIT License

Python 51.48% C++ 26.32% C 22.17% Batchfile 0.01% Shell 0.01%

algoplus's Introduction

简介

AlgoPlus是上期技术CTP API的Python封装,具有以下特点:

  • 易使用:Python语言,结构清晰,注释完整,文档详尽。
  • 低延时:基于Cython释放GIL;支持多路行情源;无需主事件引擎,实现去中心化。
  • 忠实于CTP官方特性:充分利用CTP的异步、多线程特性。

AlgoPlus文档

http://algo.plus

安装

首先配置Anaconda环境,然后使用pip命令安装:

pip install AlgoPlus

从两个例子开始

订阅行情并落地为CSV文件

补充账户密码之后运行,可以订阅行情,并将接收到的数据写入csv文件中。

from AlgoPlus.CTP.MdApi import run_mdrecorder
from AlgoPlus.CTP.FutureAccount import FutureAccount, get_simnow_account

if __name__ == '__main__':

    instrument_id_list = [b'ni2003']  #需要订阅的合约列表

    future_account = get_simnow_account(
        investor_id=b'',                        #SimNow账户
        password=b'',                           #SimNow账户密码
        instrument_id_list=instrument_id_list,  #合约列表
        server_name='TEST'                      #电信1、电信2、移动、TEST
    )

    tick_engine = run_mdrecorder(future_account)

监控账户成交

from multiprocessing import Process, Queue
from AlgoPlus.CTP.MdApi import run_mdapi
from AlgoPlus.CTP.TraderApi import run_traderapi
from AlgoPlus.CTP.FutureAccount import FutureAccount, get_simnow_account

if __name__ == '__main__':

    pl_parameter = {
        'StrategyID': 9,
        'ProfitLossParameter': {
            b'rb2005': {'0': [5], '1': [5]},   # '0'代表止盈, '1'代表止损
            b'ni2003': {'0': [50], '1': [50]}  # '0'代表止盈, '1'代表止损
        },
    }

    instrument_id_list = []
    for instrument_id in pl_parameter['ProfitLossParameter']:
        instrument_id_list.append(instrument_id)

    future_account = get_simnow_account(
        investor_id='',                         # SimNow账户
        password='',                            # SimNow账户密码
        instrument_id_list=instrument_id_list,  # 合约列表
        # server_name='TEST'                    # 电信1、电信2、移动、TEST
    )

    # 共享队列
    share_queue = Queue(maxsize=100)
    share_queue.put(pl_parameter)

    # 行情进程
    md_process = Process(target=run_mdapi, args=(future_account, [share_queue]))
    # 交易进程
    trader_process = Process(target=run_traderapi, args=(future_account, share_queue))

    md_process.start()
    trader_process.start()

    md_process.join()
    trader_process.join()

开源地址

  1. 码云:https://gitee.com/AlgoPlus/
  2. GitHub:https://github.com/CTPPlus/AlgoPlus

QQ群与微信公众号

  • QQ群:866469866

  • 微信公众号:AlgoPlus

版权

MIT

algoplus's People

Contributors

keyalgo avatar

Stargazers

量化交易王 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.