Beispiel #1
0
def generate_l2_interface(locale='utf-8'):
    datas, enums = parse_struct.parse(
        "../ctp_sse/api/trade/linux64/public/ThostFtdcLevel2UserApiDataType.h",
        '../ctp_sse/api/trade/linux64/public/ThostFtdcLevel2UserApiStruct.h',
        locale)
    #generate python
    f = codecs.open("UserApiStruct.py", "w", "utf-8")
Beispiel #2
0
def generate_l2_interface(locale="utf-8"):
    datas, enums = parse_struct.parse(
        "../ctp_sse/api/trade/linux64/public/ThostFtdcLevel2UserApiDataType.h",
        "../ctp_sse/api/trade/linux64/public/ThostFtdcLevel2UserApiStruct.h",
        locale,
    )
    # generate python
    f = codecs.open("UserApiStruct.py", "w", "utf-8")
Beispiel #3
0
def generate_interface():
    import parse_struct
    datas = parse_struct.parse("../inc/ThostFtdcUserApiDataTypeSSE.h",
                               '../inc/ThostFtdcUserApiStructSSE.h')
    
#generate python
    f=file("UserApiStruct.py", "w")
    f.write('#-*- coding=utf-8 -*-\n"""'+__doc__+'"""\n')
    f.write('"""\n'+__doc__+'"""\n')
    f.write("""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas: generate_py(i, datas, f)

    f.write("# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write("%s=%s\n" % (i[12:-5],i))

    f.close()


#generate cpp
    f=file("struct.cpp", "w")
    f.write("/*"+__doc__+'*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""#include "struct.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""")
    for i in datas: generate_cpp(i, datas, f)
    f.close()

#generate hpp
    f=file("struct.h", "w")
    f.write("/*"+__doc__+'*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

#include <Python.h>
#include "ThostFtdcUserApiStructSSE.h"


PyObject * register_struct(PyObject * self, PyObject * args);
""")
    for i in datas: generate_hpp(i, datas, f)

    f.write("#endif\n")
    f.close()
Beispiel #4
0
def generate_interface(locale='utf-8'):
    import parse_struct
    datas,enums = parse_struct.parse("../ctp/api/trade/linux64/public/ThostFtdcUserApiDataType.h",
                               '../ctp/api/trade/linux64/public/ThostFtdcUserApiStruct.h',locale)
    
#generate python
    f=codecs.open("UserApiStruct.py", "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n'+__doc__+'"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas: generate_py(i, datas, f)

    f.write(u"# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write(u"%s=%s\n" % (i[10:-5],i))

    f.close()
#generate datatype for python
    f=codecs.open("UserApiType.py", "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n'+__doc__+'"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for e in enums.values(): 
        if 'values' in e:
            f.write(u'#%s\n' % e['comment'])
            for (n,v) in e['values'].items():
                f.write(u'%s = %s #%s\n' % (n,v['value'],v['comment']))
    f.close()


#generate cpp
    f=codecs.open("struct.cpp", "w", "utf-8")
    f.write(u"/*"+__doc__+'*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""
#include "struct.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""")
    for i in datas: generate_cpp(i, datas, f)
    f.close()

#generate hpp
    f=codecs.open("struct.h", "w", "utf-8")
    f.write(u"/*"+__doc__+'*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "ThostFtdcUserApiStruct.h"

PyObject * register_struct(PyObject * self, PyObject * args);
""")
    for i in datas: generate_hpp(i, datas, f)

    f.write(u"#endif\n")
    f.close()
Beispiel #5
0
def generate_interface(
    h_types,  # .h file that defines types
    h_structs,  # .h file that defines structs
    py_types,  # output file
    py_structs,  # output file
    basename_wrapper,  # the basename of output cpp files. e.g., basename_wrapper = 'struct', then struct.h, struct.cpp will be generated
    locale="utf-8",
):
    datas, enums = parse_struct.parse(h_types, h_structs, locale)

    # generate python
    f = codecs.open(py_structs, "w", "utf-8")
    f.write(u"#-*- coding=utf-8 -*-\n")
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(
        u"""
#This file is auto generated! Please don't edit directly.
"""
    )
    for i in datas:
        generate_py(i, datas, f)

    f.write(u"# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write(u"%s=%s\n" % (i[10:-5], i))

    f.close()
    # generate datatype for python
    f = codecs.open(py_types, "w", "utf-8")
    f.write(u"#-*- coding=utf-8 -*-\n")
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(
        u"""
#This file is auto generated! Please don't edit directly.
"""
    )
    for e in enums.values():
        if "values" in e:
            f.write(u"#%s\n" % e["comment"])
            for (n, v) in e["values"].items():
                f.write(u"%s = %s #%s\n" % (n, v["value"], v["comment"]))
    f.close()

    # generate cpp
    f = codecs.open("%s.cpp" % basename_wrapper, "w", "utf-8")
    f.write(u"/*" + __doc__ + "*/\n")
    f.write(
        u"""
//This file is auto generated! Please don't edit directly.
"""
    )
    f.write(
        u"""
#include "%s.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
"""
        % basename_wrapper
    )
    for i in datas:
        generate_cpp(i, datas, f)
    f.close()

    # generate hpp
    f = codecs.open("%s.h" % basename_wrapper, "w", "utf-8")
    f.write(u"/*" + __doc__ + "*/\n")
    f.write(
        u"""
//This file is auto generated! Please don't edit directly.
"""
    )
    f.write(
        u"""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "%s"

PyObject * register_struct(PyObject * self, PyObject * args);
"""
        % h_structs
    )
    for i in datas:
        generate_hpp(i, datas, f)

    f.write(u"#endif\n")
    f.close()
Beispiel #6
0
def generate_interface(locale='utf-8'):
    import parse_struct
    datas, enums = parse_struct.parse("../KSFT_API/inc/KSUserApiDataTypeEx.h",
                                      "../KSFT_API/inc/KSCosApiDataType.h",
                                      "../KSFT_API/inc/KSUserApiStructEx.h",
                                      '../KSFT_API/inc/KSCosApiStruct.h',
                                      locale='gbk')

    #generate python
    f = file("../Run/KSUserApiStruct.py", "w")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write("""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas:
        generate_py(i, datas, f)

    f.write("# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write("%s=%s\n" % (i[10:-5], i))

    f.close()

    #generate datatype for python
    f = file("../Run/KSUserApiType.py", "w")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for e in enums.values():
        if 'values' in e:
            f.write(u'#%s\n' % e['comment'])
            for (n, v) in e['values'].items():
                f.write(u'%s = %s #%s\n' % (n, v['value'], v['comment']))
    f.close()

    #generate cpp
    f = file("../_KSApi_Md/KSstruct.cpp", "w")
    f.write("/*" + __doc__ + '*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""
#include "stdafx.h"
#include "KSstruct.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""")
    for i in datas:
        generate_cpp(i, datas, f)
    f.close()
    shutil.copyfile("../_KSApi_Md/KSstruct.cpp",
                    "../_KSApi_Trader/KSstruct.cpp")

    #generate hpp
    f = file("../_KSApi_Md/KSstruct.h", "w")
    f.write("/*" + __doc__ + '*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

#pragma warning(disable : 4996)

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "KSUserApiStructEx.h"
#include "KSCosApiStruct.h"

PyObject * register_struct(PyObject * self, PyObject * args);
""")
    for i in datas:
        generate_hpp(i, datas, f)
    f.write("#endif\n")
    f.close()
    shutil.copyfile("../_KSApi_Md/KSstruct.h", "../_KSApi_Trader/KSstruct.h")
Beispiel #7
0
def generate_interface(locale='utf-8'):
    import parse_struct
    datas, enums = parse_struct.parse(
        "../ctp/api/trade/linux64/public/ThostFtdcUserApiDataType.h",
        '../ctp/api/trade/linux64/public/ThostFtdcUserApiStruct.h', locale)

    #generate python
    f = codecs.open("UserApiStruct.py", "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas:
        generate_py(i, datas, f)

    f.write(u"# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write(u"%s=%s\n" % (i[10:-5], i))

    f.close()
    #generate datatype for python
    f = codecs.open("UserApiType.py", "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for e in enums.values():
        if 'values' in e:
            f.write(u'#%s\n' % e['comment'])
            for (n, v) in e['values'].items():
                f.write(u'%s = %s #%s\n' % (n, v['value'], v['comment']))
    f.close()

    #generate cpp
    f = codecs.open("struct.cpp", "w", "utf-8")
    f.write(u"/*" + __doc__ + '*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""
#include "struct.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""")
    for i in datas:
        generate_cpp(i, datas, f)
    f.close()

    #generate hpp
    f = codecs.open("struct.h", "w", "utf-8")
    f.write(u"/*" + __doc__ + '*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "ThostFtdcUserApiStruct.h"

PyObject * register_struct(PyObject * self, PyObject * args);
""")
    for i in datas:
        generate_hpp(i, datas, f)

    f.write(u"#endif\n")
    f.close()
def generate_interface(locale='utf-8'):
    import parse_struct
    datas,enums = parse_struct.parse("../KSFT_API/inc/KSUserApiDataTypeEx.h","../KSFT_API/inc/KSCosApiDataType.h",
            "../KSFT_API/inc/KSUserApiStructEx.h",'../KSFT_API/inc/KSCosApiStruct.h',locale='gbk')

    
#generate python
    f=file("../Run/KSUserApiStruct.py", "w")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n'+__doc__+'"""\n')
    f.write("""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas: generate_py(i, datas, f)

    f.write("# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write("%s=%s\n" % (i[10:-5],i))
 
    f.close()

#generate datatype for python
    f=file("../Run/KSUserApiType.py", "w")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n'+__doc__+'"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for e in enums.values(): 
        if 'values' in e:
            f.write(u'#%s\n' % e['comment'])
            for (n,v) in e['values'].items():
                f.write(u'%s = %s #%s\n' % (n,v['value'],v['comment']))
    f.close()

#generate cpp
    f=file("../_KSApi_Md/KSstruct.cpp", "w")
    f.write("/*"+__doc__+'*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""
#include "stdafx.h"
#include "KSstruct.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""")
    for i in datas: generate_cpp(i, datas, f)
    f.close()
    shutil.copyfile("../_KSApi_Md/KSstruct.cpp", "../_KSApi_Trader/KSstruct.cpp")

#generate hpp
    f=file("../_KSApi_Md/KSstruct.h", "w")
    f.write("/*"+__doc__+'*/\n')
    f.write("""
//This file is auto generated! Please don't edit directly.
""")
    f.write("""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

#pragma warning(disable : 4996)

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "KSUserApiStructEx.h"
#include "KSCosApiStruct.h"

PyObject * register_struct(PyObject * self, PyObject * args);
""")
    for i in datas: generate_hpp(i, datas, f)
    f.write("#endif\n")
    f.close()
    shutil.copyfile("../_KSApi_Md/KSstruct.h", "../_KSApi_Trader/KSstruct.h")
Beispiel #9
0
def generate_interface(
    h_types,  # .h file that defines types
    h_structs,  # .h file that defines structs
    py_types,  # output file
    py_structs,  # output file
    basename_wrapper,  # the basename of output cpp files. e.g., basename_wrapper = 'struct', then struct.h, struct.cpp will be generated
    locale="utf-8"):
    datas, enums = parse_struct.parse(h_types, h_structs, locale)

    #generate python
    f = codecs.open(py_structs, "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for i in datas:
        generate_py(i, datas, f)

    f.write(u"# Set short name alias for the stupid Hungarian Notation\n")
    for i in datas:
        f.write(u"%s=%s\n" % (i[10:-5], i))

    f.close()
    #generate datatype for python
    f = codecs.open(py_types, "w", "utf-8")
    f.write(u'#-*- coding=utf-8 -*-\n')
    f.write(u'"""\n' + __doc__ + '"""\n')
    f.write(u"""
#This file is auto generated! Please don't edit directly.
""")
    for e in enums.values():
        if 'values' in e:
            f.write(u'#%s\n' % e['comment'])
            for (n, v) in e['values'].items():
                f.write(u'%s = %s #%s\n' % (n, v['value'], v['comment']))
    f.close()

    #generate cpp
    f = codecs.open("%s.cpp" % basename_wrapper, "w", "utf-8")
    f.write(u"/*" + __doc__ + '*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""
#include "%s.h"

static PyObject * mod=NULL;
PyObject * register_struct(PyObject * self, PyObject * args){
  mod = PyTuple_GET_ITEM(args,0);
  Py_INCREF(Py_None);
  return Py_None;
}
""" % basename_wrapper)
    for i in datas:
        generate_cpp(i, datas, f)
    f.close()

    #generate hpp
    f = codecs.open("%s.h" % basename_wrapper, "w", "utf-8")
    f.write(u"/*" + __doc__ + '*/\n')
    f.write(u"""
//This file is auto generated! Please don't edit directly.
""")
    f.write(u"""#ifndef STRUCT_TRADE_H
#define STRUCT_TRADE_H

//#include <Python.h>
#ifdef _DEBUG
#undef _DEBUG   //links to pythonxx.lib
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#endif

#include "%s"

PyObject * register_struct(PyObject * self, PyObject * args);
""" % h_structs)
    for i in datas:
        generate_hpp(i, datas, f)

    f.write(u"#endif\n")
    f.close()