Code Monkey home page Code Monkey logo

qatrader's Introduction

QATrader

QATrader兼容 QIFI协议标准

version

pip install QATRADER

QATRADER 会逐步开放多个语言的实现

==> GO Client

QATrader_GO

==> Rust Client

QATrader_Rust

QATRADER websocket 接入的期货交易/ 并给予HTTP接口方便快速调用业务(可自行封装)

需要先行配置好Rabbitmq/ quantaxis_pubsub

rabbitmq ubuntu一键部署 https://github.com/yutiansut/QUANTAXIS_RUN/blob/master/ubuntu_install.bash

windows 可以参考, erlang/rabbit的安装文件在群文件中有

安装部署可以参见: 安装参考

策略无需考虑交易的部分, 及策略只负责从数据库读取实时的账户数据/ 并发送业务请求到EVENT MQ即可实现交易

这种设置主要是为了单账户多策略/ 以及单策略多市场等考虑

QATRADER 提供的两种交易接入方案

1. eventmq 接入(AMQP协议)

eventmq的接入模式速度较快, 延迟也较低

AMQP协议天生也支持多个语言: c++/java/python/go/javascript/rust (具体可以在github搜索 rabbitmq的相关支持)

QUANTAIXS的python版本的api接入 采用quantaxis_pubsub

详细信息可以参考:[eventmq](## EVENTMQ 接入API)

2. http 接入

在pip install 之后, 在命令行输入

qatraderserver

即可开启http端口(8020)

账户相关

查询账户组合: [GET] http://localhost:8020/tradeaccounts?action=list_sim

查询单个账户: [GET] http://localhost:8020/tradeaccounts?action=query_account&account_cookie=1010101

查询账户历史(昨日 前日这些) [GET] http://localhost:8020/tradeaccounts?action=query_accounthistory&account_cookie=1010101

查询账户的资金曲线 [GET] http://localhost:8020/tradeaccounts?action=query_accounthistorytick&account_cookie=1010101

订单相关 [POST] http://localhost:8020/order?action={}&acc={}

下单: [POST]

attention:

  1. exchange 内的交易所大写
  2. direction/offset 大写

http://localhost:8020/order?action=sendorder&acc=1010101&price=3800&code=rb1910&&direction=BUY&offset=OPEN&volume=1&exchange=SHFE&type=sim

撤单 [POST]

http://localhost:8020/order?action=cancel_order&acc=1010101&order_id=xxxxx

转账 [POST]

http://localhost:8020/order?action=transfer&acc=1010101&type=real&amount=100

查询银行 [POST] (实盘独有API)

http://localhost:8020/order?action=query_bank&acc=1010101&type=real&bank_id=1

修改密码 [POST]

http://localhost:8020/order?action=change_password&acc=1010101&new_password=xxxx&type=real

查询结算单 [POST]

http://localhost:8020/order?action=query_settlement&acc=1010101&day=20190818

EVENTMQ 接入API

获取账户数据:

acc = pymongo.MongoClient().QAREALTIME.account.find_one({'account_cookie':'xxxx'})

# 基础信息
print(acc['accounts'])

# 持仓
print(acc['positions'])

# 订单
print(acc['orders'])

# 交易
print(acc['trades'])

# 银期转账
print(acc['transfer'])

# 查询银行(多银行)
print(acc['banks'])

当然 除了从数据库获取, 你也可以从业务平台上订阅该账户的增量信息

from QAPUBSUB import consumer
import json
from QAREALTIME.setting import real_account_mongo_ip
z = consumer.subscriber_routing(host='127.0.0.1', user='admin', password='admin',exchange='QAACCOUNT',routing_key='812572')
import pandas as pd
import QUANTAXIS as QA


def parse(a, b, c, body):
    z = json.loads(str(body, encoding='utf-8'))
    # QA.QA_util_log_info(z)
    if z['aid'] == 'rtn_data':
        data = z['data'][0]['trade']
        account_cookie = str(list(data.keys())[0])
        QA.QA_util_log_info(data)
        user_id = data[account_cookie]['user_id']
        accounts = data[account_cookie]['accounts']['CNY']
        positions = data[account_cookie]['positions']
        orders = data[account_cookie]['orders']
        trades = data[account_cookie]['trades']
        banks = data[account_cookie]['banks']
        transfers = data[account_cookie]['transfers']

        QA.QA_util_log_info("======================= QUANTAXIS ::{}=======================".format(
            account_cookie))
        QA.QA_util_log_info("== pre_balance " + str(accounts['pre_balance']) +
                            "== balance " + str(accounts['balance']))
        QA.QA_util_log_info("== 可用资金 " + str(accounts['available']) +
                            "== 冻结保证金 " + str(accounts['margin']) +
                            "== risk_ratio " + str(accounts['risk_ratio']))
        QA.QA_util_log_info('== position_profit ' +
                            str(accounts['position_profit']))
        QA.QA_util_log_info("==============POSITIONS===============")
        QA.QA_util_log_info(pd.DataFrame(positions))
        QA.QA_util_log_info("==============ORDERS==================")
        QA.QA_util_log_info(pd.DataFrame(orders))
        QA.QA_util_log_info("==============TRADERS==================")
        QA.QA_util_log_info(pd.DataFrame(trades))
z.callback = parse
z.start()

下单:

from QAPUBSUB import producer

p = producer.publisher_routing(
    user='admin', password='admin', host=host, exchange='QAORDER_ROUTER')

p.pub(json.dumps({
    'topic': 'sendorder',
    'account_cookie': '111111',
    'strategy_id': 'test',
    'code': 'rb1910',
    'price': 4750,
    'order_direction': 'BUY',
    'order_offset': 'OPEN',
    'volume': 1,
    'order_time': str(datetime.datetime.now()),
    'exchange_id': 'SHFE'
}), routing_key='111111')

撤单:

from QAPUBSUB import producer

p = producer.publisher_routing(
    user='admin', password='admin', host=host, exchange='QAORDER_ROUTER')
    
p.pub(json.dumps({
    'topic':'cancel_order',
    'order_id':'xxxx'}), routing_key=acc)

qatrader's People

Contributors

kite8 avatar ndiy avatar yutiansut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

qatrader's Issues

推荐使用nats.io,而不是RabbitMQ

nats.io vs RabbitMQ
https://blog.csdn.net/qq_35063002/article/details/89446761
nats.io是有代理的MessageQueue中最快的.
美股券商alpaca的行情就是使用nats.io
https://github.com/alpacahq/alpaca-trade-api-python
https://polygon.io/docs/

	Messaging Patterns:
		https://medium.com/@shijuvar/introducing-nats-to-go-developers-3cfcb98c21d0
		Publish-Subscribe
		Queueing
			Although queue groups have multiple subscribers, each message is only consumed by only one.
		Request-Reply

nats.io的跨语言特性强(Go/Python/JS/Java)
	https://github.com/nats-io/nats.py
	https://github.com/nats-io/nats.go
	https://github.com/nats-io/nats.java
	https://github.com/nats-io/nats.js

centrifugo——另一个推荐
https://github.com/centrifugal/centrifuge
Centrifuge library is a real-time core of Centrifugo server. It's also supposed to be a general purpose real-time messaging library for Go programming language.

Client libraries(跨语言特性强):

centrifuge-js – for browser, NodeJS and React Native
centrifuge-go - for Go language
centrifuge-mobile - for iOS and Android using centrifuge-go as basis and gomobile project to create bindings
centrifuge-dart - for Dart and Flutter
centrifuge-swift – for native iOS development
centrifuge-java – for native Android development and general Java

repository的根目录的autoreload.py会导致ipython自动重载失效

In [1]: %load_ext autoreload
The autoreload module is not an IPython extension.

In [2]: import autoreload

In [3]: autoreload??
Type:        module
String form: <module 'autoreload' from 'e:\\python\\quantaxis\\qatrader\\autoreload.py'>
File:        e:\python\quantaxis\qatrader\autoreload.py
Source:      import pandas as pd

这个似乎是造成冲突了,我把autoreload.py移走之后,%load_ext autoreload可以正常使用了

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.