Skip to main content

py_femas

中金技术api之python封装,实现接口调用。支持windows(x86/x64) linux(x64).

示例

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__title__ = 'test py ctp of se'
__author__ = 'HaiFeng'
__mtime__ = '20190506'

import sys

sys.path.append('.')
from py_femas.trade import CtpTrade
from py_femas.quote import CtpQuote
from py_femas.enums import *
import time


class TestTrade(object):
    def __init__(self, addr: str, broker: str, user: str, pwd: str, appid: str, auth_code: str, proc: str):
        self.front = addr
        self.broker = broker
        self.investor = user
        self.pwd = pwd
        self.appid = appid
        self.authcode = auth_code
        self.proc = proc

        self.t = CtpTrade()
        self.t.OnConnected = self.on_connect
        self.t.OnUserLogin = lambda o, x: print('Trade logon:', x)
        self.t.OnDisConnected = lambda o, x: print(x)
        self.t.OnRtnNotice = lambda obj, time, msg: print(f'OnNotice: {time}:{msg}')
        self.t.OnErrRtnQuote = lambda obj, quote, info: None
        self.t.OnErrRtnQuoteInsert = lambda obj, o: None
        self.t.OnOrder = lambda obj, o: print(o)
        self.t.OnErrOrder = lambda obj, f, info: print(info)
        self.t.OnTrade = lambda obj, o: print(o)
        self.t.OnInstrumentStatus = lambda obj, inst, stat: None

    def on_connect(self, obj):
        self.t.ReqUserLogin(self.investor, self.pwd, self.broker, self.proc, self.appid, self.authcode)

    def run(self):
        self.t.ReqConnect(self.front)
        # self.t.ReqConnect('tcp://192.168.52.4:41205')

    def release(self):
        self.t.ReqUserLogout()


class TestQuote(object):
    """TestQuote"""

    def __init__(self, addr: str, broker: str, investor: str, pwd: str):
        """"""
        self.front = addr
        self.broker = broker
        self.investor = investor
        self.pwd = pwd

        self.q = CtpQuote()
        self.q.OnConnected = lambda x: self.q.ReqUserLogin(self.investor, self.pwd, self.broker)
        self.q.OnUserLogin = lambda o, i: self.q.ReqSubscribeMarketData('IF1911')
        self.q.OnTick = lambda q, t: print(f'{t.LastPrice}, {t.Volume}')

    def run(self):
        self.q.ReqConnect(self.front)

    def release(self):
        self.q.ReqUserLogout()


if __name__ == "__main__":
    front_trade = 'tcp://101.226.253.127:58002'
    front_quote = 'tcp://101.226.253.127:58005'
    broker = '0137'
    investor = ''
    pwd = ''
    appid = 'client_LB_1.0'
    auth_code = 'Q5V2UZ1G6AB2QC'
    proc = ''
    if investor == '':
        investor = input('invesotr:')
        pwd = input('password:')
        appid = input('appid:')
        auth_code = input('auth code:')
        proc = input('product info:')
    tt = TestTrade(front_trade, broker, investor, pwd, appid, auth_code, proc)
    tt.run()
    time.sleep(5)
    if tt.t.logined:
        tt.t.ReqOrderInsert('IF1911', DirectType.Buy, OffsetType.Open, 3885, 3)

    qq = TestQuote(front_quote, broker, investor, pwd)
    qq.run()
    #
    # time.sleep(6)
    # for inst in tt.t.instruments.values():
    #     print(inst)
    input()
    tt.release()
    qq.release()
    input()

Metadata

Release files for py-femas 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-femas 0.0.4
File Size Uploaded Provenance
py_femas-0.0.4.tar.gz 5.1 MB Without provenance Details

Release files / py_femas-0.0.4.tar.gz

Download URL py_femas-0.0.4.tar.gz
Size 5.1 MB
Tags Source
SHA-256 checksum
How to use checksums
af3c8802b914a5d03bed17f3cfa760cb162e03ae131949f988fb5b3647b715d7
BLAKE2b-256 checksum
How to use checksums
a2b964c321d6f0a8696da6c1808aae131c5e569f382e8642ebc2190f651d864a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Security for py-femas 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page