hikyuu2/hikyuu_pywrap/_KRecord.cpp

50 lines
1.7 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _KRecord.cpp
*
* Created on: 2012-9-28
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/serialization/KRecord_serialization.h>
#include "pickle_support.h"
using namespace boost::python;
using namespace hku;
bool (*krecord_eq)(const KRecord&, const KRecord&) = operator==;
void export_KReord() {
2020-07-04 23:54:02 +08:00
class_<KRecord>("KRecord", "K线记录组成K线数据属性可读写", init<>())
2020-07-04 00:15:54 +08:00
.def(init<const Datetime&>())
.def(init<const Datetime&, price_t, price_t, price_t, price_t, price_t, price_t>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
2020-07-04 23:54:02 +08:00
2020-07-12 20:46:34 +08:00
.def_readwrite("datetime", &KRecord::datetime, "时间")
2020-07-04 23:54:02 +08:00
.def_readwrite("open", &KRecord::openPrice, "开盘价")
.def_readwrite("high", &KRecord::highPrice, "最高价")
.def_readwrite("low", &KRecord::lowPrice, "最低价")
.def_readwrite("close", &KRecord::closePrice, "收盘价")
.def_readwrite("amount", &KRecord::transAmount, "成交金额")
.def_readwrite("volume", &KRecord::transCount, "成交量")
2020-07-04 00:15:54 +08:00
.def("__eq__", krecord_eq)
2015-01-07 01:26:14 +08:00
#if HKU_PYTHON_SUPPORT_PICKLE
2020-07-04 00:15:54 +08:00
.def_pickle(normal_pickle_suite<KRecord>())
2015-01-07 01:26:14 +08:00
#endif
2020-07-04 00:15:54 +08:00
;
2015-01-07 01:26:14 +08:00
2020-07-04 00:15:54 +08:00
KRecordList::const_reference (KRecordList::*KRecordList_at)(KRecordList::size_type) const =
&KRecordList::at;
void (KRecordList::*append)(const KRecord&) = &KRecordList::push_back;
2015-01-07 01:26:14 +08:00
class_<KRecordList>("KRecordList")
2020-07-04 00:15:54 +08:00
.def("__iter__", iterator<KRecordList>())
.def("size", &KRecordList::size)
.def("__len__", &KRecordList::size)
.def("__getitem__", KRecordList_at, return_value_policy<copy_const_reference>())
.def("append", append);
register_ptr_to_python<KRecordListPtr>();
2015-01-07 01:26:14 +08:00
}