├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── code ├── base │ ├── Currency.cpp │ ├── Currency.h │ ├── DateTime.cpp │ ├── DateTime.h │ ├── Event.cpp │ ├── Event.h │ ├── EventDispatcher.cpp │ ├── EventDispatcher.h │ ├── EventQueue.cpp │ ├── EventQueue.h │ ├── EventType.h │ ├── Library.cpp │ ├── Library.h │ ├── LogFixtureMgr.cpp │ ├── LogFixtureMgr.h │ ├── MtsLog.cpp │ ├── MtsLog.h │ ├── MtsPath.cpp │ ├── MtsPath.h │ ├── MtsType.cpp │ ├── MtsType.h │ ├── MtsUtils.cpp │ ├── MtsUtils.h │ ├── NotifiableObserver.h │ ├── Resources │ │ └── date_time_zonespec.csv │ ├── Ticks.cpp │ ├── Ticks.h │ ├── Timezone.cpp │ ├── Timezone.h │ ├── UrlPath.cpp │ ├── UrlPath.h │ ├── base.pro │ ├── base.vcxproj │ ├── base.vcxproj.filters │ ├── base_api.h │ ├── enum_ext.h │ ├── number.h │ └── qt_res.qrc ├── clock_real │ ├── ClockReal.cpp │ ├── ClockReal.h │ ├── clock_real.pro │ ├── clock_real.vcxproj │ ├── clock_real.vcxproj.filters │ ├── clock_real_api.h │ └── mts_clock_real.cpp ├── ctp_ext │ ├── CTPClientBase.cpp │ ├── CTPClientBase.h │ ├── CTPClientCommon.h │ ├── CTPCommonField.h │ ├── CTPUtils.cpp │ ├── CTPUtils.h │ ├── TradeUtils.cpp │ ├── TradeUtils.h │ ├── ctp_ext.vcxproj │ ├── ctp_ext.vcxproj.filters │ ├── ctp_ext_api.h │ └── ctp_md.h ├── feeds_real_CTP │ ├── CTPFeedsClient.cpp │ ├── CTPFeedsClient.h │ ├── FeedsReal.cpp │ ├── FeedsReal.h │ ├── QuoteEvent.h │ ├── README.md │ ├── feeds_real_api.h │ ├── mts_feeds_real.cpp │ ├── mts_feeds_real_CTP.vcxproj │ └── mts_feeds_real_CTP.vcxproj.filters ├── mts │ ├── AbsStrategy.cpp │ ├── AbsStrategy.h │ ├── AccountMgr.cpp │ ├── AccountMgr.h │ ├── ClockMgr.cpp │ ├── ClockMgr.h │ ├── CrossThreadNotifier.cpp │ ├── CrossThreadNotifier.h │ ├── MtsMainThread.cpp │ ├── MtsMainThread.h │ ├── MtsMainThreadReal.cpp │ ├── MtsMainThreadReal.h │ ├── MtsProxy.cpp │ ├── MtsProxy.h │ ├── MtsProxyBase.cpp │ ├── MtsProxyBase.h │ ├── OrderFillMgr.cpp │ ├── OrderFillMgr.h │ ├── OrderMgr.cpp │ ├── OrderMgr.h │ ├── OrderMgrBase.cpp │ ├── OrderMgrBase.h │ ├── PositionMgr.cpp │ ├── PositionMgr.h │ ├── PositionPersistence.cpp │ ├── PositionPersistence.h │ ├── QuoteMgr.cpp │ ├── QuoteMgr.h │ ├── StrategyHub.cpp │ ├── StrategyHub.h │ ├── StrategyMgr.cpp │ ├── StrategyMgr.h │ ├── TradingAccountMgr.cpp │ ├── TradingAccountMgr.h │ ├── mts.vcxproj │ ├── mts.vcxproj.filters │ └── mts_api.h ├── mts_agent_python │ ├── PyAccount.cpp │ ├── PyAccount.h │ ├── PyBar.cpp │ ├── PyBar.h │ ├── PyDateTime.cpp │ ├── PyDateTime.h │ ├── PyInstrumentProperty.cpp │ ├── PyInstrumentProperty.h │ ├── PyOrder.cpp │ ├── PyOrder.h │ ├── PyOrderCancelDone.h │ ├── PyOrderCancelReject.h │ ├── PyOrderFill.cpp │ ├── PyOrderFill.h │ ├── PyOrderNewDone.h │ ├── PyOrderNewReject.h │ ├── PyOrderReport.h │ ├── PyPosition.cpp │ ├── PyPosition.h │ ├── PyQuote.cpp │ ├── PyQuote.h │ ├── PyTradingAccount.cpp │ ├── PyTradingAccount.h │ ├── PythonMdouleMain.cpp │ ├── PythonModule.cpp │ ├── PythonStrategy.cpp │ ├── PythonStrategy.h │ ├── PythonStrategyWrap.h │ ├── PythonUtil.cpp │ ├── PythonUtil.h │ ├── config │ │ ├── __init__.py │ │ ├── __init__d.py │ │ └── mts_import.py │ ├── mts_agent_python.vcxproj │ ├── mts_agent_python.vcxproj.filters │ └── mts_agent_python_api.h ├── mts_core │ ├── AbstractConfigParams.cpp │ ├── AbstractConfigParams.h │ ├── Account.cpp │ ├── Account.h │ ├── AccountCallback.h │ ├── Bar.cpp │ ├── Bar.h │ ├── CalcBar.cpp │ ├── CalcBar.h │ ├── Clock.cpp │ ├── Clock.h │ ├── Component.cpp │ ├── Component.h │ ├── ConfigParams.cpp │ ├── ConfigParams.h │ ├── ContinuousSymbolMgr.cpp │ ├── ContinuousSymbolMgr.h │ ├── CoreBar.fbs │ ├── DateCallback.h │ ├── Environment.cpp │ ├── Environment.h │ ├── EnvironmentFactory.cpp │ ├── EnvironmentFactory.h │ ├── ExchOrderSet.cpp │ ├── ExchOrderSet.h │ ├── Feeds.cpp │ ├── Feeds.h │ ├── FeedsCallback.h │ ├── InstrumentId.cpp │ ├── InstrumentId.h │ ├── InstrumentObject.cpp │ ├── InstrumentObject.h │ ├── InstrumentProperty.cpp │ ├── InstrumentProperty.h │ ├── InstrumentPropertyDb.cpp │ ├── InstrumentPropertyDb.h │ ├── MethodDefine.h │ ├── Order.cpp │ ├── Order.h │ ├── OrderAction.cpp │ ├── OrderAction.h │ ├── OrderFillSet.cpp │ ├── OrderFillSet.h │ ├── OrderId.cpp │ ├── OrderId.h │ ├── OrderReport.cpp │ ├── OrderReport.h │ ├── OrderSet.cpp │ ├── OrderSet.h │ ├── OrderType.cpp │ ├── OrderType.h │ ├── ParamsFields.h │ ├── Position.cpp │ ├── Position.h │ ├── PositionVolumeInfo.cpp │ ├── PositionVolumeInfo.h │ ├── Quote.cpp │ ├── Quote.h │ ├── QuoteSet.cpp │ ├── QuoteSet.h │ ├── StrategyInterface.h │ ├── SysConfigParams.cpp │ ├── SysConfigParams.h │ ├── TimerCallback.h │ ├── Trade.cpp │ ├── Trade.h │ ├── TradeCallback.h │ ├── TradingAccount.cpp │ ├── TradingAccount.h │ ├── TradingDateMgr.cpp │ ├── TradingDateMgr.h │ ├── TradingDateMgr24Hour.cpp │ ├── TradingDateMgr24Hour.h │ ├── TradingDateMgrFromFile.cpp │ ├── TradingDateMgrFromFile.h │ ├── const.h │ ├── enums.cpp │ ├── enums.h │ ├── mts_core.vcxproj │ ├── mts_core.vcxproj.filters │ └── mts_core_api.h ├── mts_opensrc.sln └── trade_real_CTP │ ├── AbstractAction.cpp │ ├── AbstractAction.h │ ├── CTPCancelOrderField.cpp │ ├── CTPCancelOrderField.h │ ├── CTPInputOrderField.cpp │ ├── CTPInputOrderField.h │ ├── CTPOrderMgr.cpp │ ├── CTPOrderMgr.h │ ├── CTPTradeClientBase.cpp │ ├── CTPTradeClientBase.h │ ├── OrderIdImplCtp.cpp │ ├── OrderIdImplCtp.h │ ├── QueryAction.h │ ├── QueryFillAction.cpp │ ├── QueryFillAction.h │ ├── QueryInstrumentAction.cpp │ ├── QueryInstrumentAction.h │ ├── QueryOrderAction.cpp │ ├── QueryOrderAction.h │ ├── QueryPositionAction.cpp │ ├── QueryPositionAction.h │ ├── QuerySettlementInfoAction.cpp │ ├── QuerySettlementInfoAction.h │ ├── QueryTradingAccountAction.cpp │ ├── QueryTradingAccountAction.h │ ├── README.md │ ├── TradeEvent.h │ ├── TradeReal.cpp │ ├── TradeReal.h │ ├── mts_trade_real.cpp │ ├── mts_trade_real_CTP.vcxproj │ ├── mts_trade_real_CTP.vcxproj.filters │ └── trade_real_api.h ├── config ├── continuous_contract.json ├── dc_exchs.json ├── instrument_db.json ├── risk_setting.json ├── stk_instrument.json ├── trading_date_cn_fut.txt └── trading_hour.cfg └── doc ├── MTS.md ├── mts-setup.md └── mts_script_manual.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | code/.vs/mts_opensrc/v14/.suo 34 | *.user 35 | 36 | GeneratedFiles/ 37 | x64/ 38 | build/ 39 | *.db 40 | *.test.cpp 41 | code/base/PerfTest.h 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MTS 日内高频量化交易系统 2 | 3 | 针对中小型私募基金公司等量化机构的,易学易用的微内核模块化交易系统。系统运行在用户终端,不存在交易策略泄密问题。 4 | 5 | ### 问题 6 | 7 | 1. 中小型私募基金公司,技术能力不足,只能购买针对个人的功能不足的交易系统或通过挖角的方式非法得到别的公司的交易系统代码,稍加修改后使用。 8 | 2. 大型私募公司大都组建自己的研发团队,各自开发自己的功能重复的交易系统,系统之间无法兼容,浪费资源。 9 | 2. 现有的交易系统要么是针对个人的,无法适应机构的交易需求;是要么大型公司自己开发的需求特制而且不公开。 10 | 1. 交易系统良莠不齐,鱼龙混杂。 11 | 2. 已有的优矿等解决方案适合量化个人或对自己交易策略保密性要求不高的情况。对于机构,交易策略保密性敏感。 12 | 13 | ### 目标 14 | 15 | **让中小型私募基金公司不再需要开发部门,就可以做量化交易和回测。** 16 | 17 | ### 主页 18 | [MTS 官方网站](http://www.mtsquant.com) 19 | -------------------------------------------------------------------------------- /code/base/Currency.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "./Currency.h" 17 | #include 18 | #include 19 | 20 | const char * currencyIdName(CurrencyId currency) { 21 | static const char* names[] = { 22 | CURRENCY_ID_ENUM(SELECT_2_AND_COMMA_IN_3) 23 | }; 24 | if (currency >= 0 && currency < ARRAY_SIZE(names)) { 25 | return names[currency]; 26 | } else { 27 | return names[0]; 28 | } 29 | } 30 | 31 | CurrencyId currencyId(const char * currencyName) { 32 | static QHash map; 33 | if (map.isEmpty()) { 34 | CURRENCY_ID_ENUM(DEFINE_NAME_ENUM_MAP3_KEY_2); 35 | } 36 | return map[currencyName]; 37 | return CurrencyId(); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /code/base/Currency.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | 17 | /***************************************************************************** 18 | * Copyright [2018] [3fellows] 19 | * 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * http://www.apache.org/licenses/LICENSE-2.0 24 | * 25 | * Unless required by applicable law or agreed to in writing, software 26 | * distributed under the License is distributed on an "AS IS" BASIS, 27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 | * See the License for the specific language governing permissions and 29 | * limitations under the License. 30 | *****************************************************************************/ 31 | 32 | #ifndef __Currency_H__ 33 | #define __Currency_H__ 34 | #pragma once 35 | 36 | #include "base_api.h" 37 | #include "enum_ext.h" 38 | 39 | 40 | #define CURRENCY_ID_ENUM(declare) \ 41 | declare(CURRENCY_UNKNOWN , "UNKNOWN", "无效币种") \ 42 | declare(CURRENCY_CNY , "CNY", "人民币") \ 43 | declare(CURRENCY_USD , "USD", "美元") \ 44 | declare(CURRENCY_HKD , "HKD", "港元") \ 45 | declare(CURRENCY_EUR , "EUR", "欧元") \ 46 | declare(CURRENCY_GBP , "GBP", "英镑") 47 | 48 | enum CurrencyId { CURRENCY_ID_ENUM(SELECT_1_AND_COMMA_IN_3) CURRENCY_MAX }; 49 | 50 | BASE_API const char* currencyIdName(CurrencyId currency); 51 | BASE_API CurrencyId currencyId(const char* currencyName); 52 | 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /code/base/Event.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "Event.h" 17 | 18 | 19 | 20 | Event::Event(int type) 21 | :_type(type) 22 | { 23 | } 24 | 25 | 26 | Event::~Event() { 27 | } 28 | 29 | int Event::type() const { 30 | return _type; 31 | } 32 | -------------------------------------------------------------------------------- /code/base/Event.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "base/base_api.h" 19 | 20 | class BASE_API Event { 21 | public: 22 | virtual ~Event(); 23 | int type() const; 24 | protected: 25 | Event(int type); 26 | private: 27 | const int _type; 28 | }; 29 | 30 | typedef QSharedPointer EventPtr; 31 | 32 | 33 | template 34 | class DataEvent :public Event { 35 | public: 36 | DataEvent(const _Ty& data) 37 | :Event(_EvtType), _data(data) 38 | { 39 | } 40 | virtual ~DataEvent() { 41 | 42 | } 43 | 44 | _Ty data() const { 45 | return _data; 46 | } 47 | private: 48 | _Ty _data; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /code/base/EventDispatcher.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "EventDispatcher.h" 17 | #include "EventQueue.h" 18 | 19 | 20 | EventDispatcher::EventDispatcher(EventQueue* queue) 21 | :NotifiableObserver(&EventCallback::onEvent),_queue(queue) 22 | { 23 | } 24 | 25 | 26 | EventDispatcher::~EventDispatcher() { 27 | } 28 | 29 | EventDispatcher * EventDispatcher::defaultDispatcher() { 30 | static EventDispatcher dispatcher(EventQueue::defaultQueue()); 31 | return &dispatcher; 32 | } 33 | 34 | int EventDispatcher::processEvents() { 35 | int i = 0; 36 | while (EventPtr evt = _queue->pop()) { 37 | this->notifyAll(evt); 38 | ++i; 39 | } 40 | return i; 41 | } 42 | -------------------------------------------------------------------------------- /code/base/EventDispatcher.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "NotifiableObserver.h" 19 | #include "Event.h" 20 | 21 | class EventCallback 22 | { 23 | public: 24 | virtual void onEvent(const EventPtr&) = 0; 25 | }; 26 | 27 | class EventQueue; 28 | class BASE_API EventDispatcher :public NotifiableObserver 29 | { 30 | public: 31 | EventDispatcher(EventQueue*); 32 | ~EventDispatcher(); 33 | 34 | static EventDispatcher* defaultDispatcher(); 35 | 36 | int processEvents(); //return processed events count 37 | private: 38 | EventQueue* _queue; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /code/base/EventQueue.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "EventQueue.h" 17 | 18 | 19 | 20 | EventQueue::EventQueue() { 21 | } 22 | 23 | 24 | EventQueue::~EventQueue() { 25 | } 26 | 27 | EventQueue * EventQueue::defaultQueue() { 28 | static EventQueue queue; 29 | return &queue; 30 | } 31 | 32 | 33 | void EventQueue::push(const EventPtr & evt) { 34 | QMutexLocker l(&_mutex); 35 | _pushedQueue.append(evt); 36 | } 37 | 38 | 39 | EventPtr EventQueue::pop() { 40 | if (_popedQueue.isEmpty()) { 41 | QMutexLocker l(&_mutex); 42 | if (!_pushedQueue.isEmpty()) { 43 | _popedQueue.swap(_pushedQueue); 44 | } 45 | } 46 | if (_popedQueue.isEmpty()) { 47 | return EventPtr(); 48 | } else { 49 | EventPtr evt = _popedQueue.front(); 50 | _popedQueue.pop_front(); 51 | return evt; 52 | } 53 | } 54 | 55 | bool EventQueue::isEmpty() const { 56 | if (!_popedQueue.isEmpty()) { 57 | return false; 58 | } 59 | QMutexLocker l(&_mutex); 60 | return _pushedQueue.isEmpty(); 61 | } 62 | -------------------------------------------------------------------------------- /code/base/EventQueue.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include "Event.h" 21 | 22 | 23 | class BASE_API EventQueue 24 | { 25 | public: 26 | EventQueue(); 27 | ~EventQueue(); 28 | 29 | static EventQueue* defaultQueue(); 30 | 31 | void push(const EventPtr& evt); 32 | 33 | EventPtr pop(); 34 | bool isEmpty() const; 35 | 36 | private: 37 | QList _pushedQueue; 38 | QList _popedQueue; 39 | mutable QMutex _mutex; 40 | 41 | 42 | 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /code/base/EventType.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | enum EventType { 19 | EVT_UNKNOWN, 20 | EVT_QUOTE, 21 | EVT_ORDER, 22 | EVT_POSITION, 23 | EVT_RPT_ORDER_NEW_DONE, 24 | EVT_RPT_ORDER_NEW_REJECT, 25 | EVT_RPT_ORDER_FILL, 26 | EVT_RPT_ORDER_CANCEL_DONE, 27 | EVT_RPT_ORDER_CANCEL_REJECT, 28 | 29 | }; -------------------------------------------------------------------------------- /code/base/Library.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "Library.h" 17 | #ifdef _WIN32 18 | #include "MtsUtils.h" 19 | #include 20 | 21 | 22 | Library::Library ( QObject * parent ) 23 | :_dllHandle(nullptr) 24 | { 25 | } 26 | 27 | Library::Library(const QString &fileName, QObject *parent) 28 | :_fileName(fileName), _dllHandle(nullptr) 29 | { 30 | } 31 | 32 | 33 | Library::~Library() { 34 | unload (); 35 | } 36 | 37 | QString Library::errorString () const{ 38 | return _errorString; 39 | } 40 | 41 | QString Library::fileName() const { 42 | return _fileName; 43 | } 44 | 45 | bool Library::isLoaded () const{ 46 | return _dllHandle!=NULL; 47 | } 48 | 49 | bool Library::load() { 50 | const QString nativeFilePath ( QDir::toNativeSeparators ( _fileName ) + ".dll" ); 51 | _dllHandle=LoadLibraryEx( nativeFilePath.toStdWString().c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 52 | if (_dllHandle == NULL) { 53 | _errorString = MtsUtils::getLastErrorMessage (); 54 | return false; 55 | } else { 56 | _errorString.clear (); 57 | return true; 58 | } 59 | 60 | } 61 | 62 | void Library::setFileName(const QString & fn) { 63 | _fileName = fn; 64 | } 65 | 66 | bool Library::unload (){ 67 | if ( _dllHandle ==NULL){ 68 | return false; 69 | } 70 | bool ret= FreeLibrary(_dllHandle); 71 | _dllHandle = NULL; 72 | return ret; 73 | } 74 | 75 | 76 | QFunctionPointer Library::resolve ( const char * symbol ){ 77 | return (QFunctionPointer)GetProcAddress ( _dllHandle , symbol ); 78 | } 79 | 80 | 81 | #endif // 82 | -------------------------------------------------------------------------------- /code/base/Library.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "base/base_api.h" 20 | #ifdef _WIN32 21 | #include 22 | 23 | class BASE_API Library 24 | { 25 | public: 26 | Library ( QObject *parent = Q_NULLPTR ); 27 | Library(const QString &fileName, QObject *parent = Q_NULLPTR); 28 | ~Library(); 29 | 30 | QString errorString() const; 31 | QString fileName() const; 32 | bool isLoaded() const; 33 | bool load(); 34 | QFunctionPointer resolve(const char* symbol); 35 | void setFileName(const QString&); 36 | bool unload (); 37 | 38 | private: 39 | QString _fileName; 40 | QString _errorString; 41 | HMODULE _dllHandle; 42 | }; 43 | 44 | #else 45 | #include 46 | 47 | typedef QLibrary Library; 48 | 49 | #endif -------------------------------------------------------------------------------- /code/base/LogFixtureMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | 21 | class LogFixtureMgr 22 | { 23 | public: 24 | static LogFixtureMgr* instance(const QString& logPath = QString()); 25 | FILE* getLogFile(); 26 | FILE* getLogFile(const QString& prefix); 27 | bool closeLogFile(const QString& prefix); 28 | private: 29 | LogFixtureMgr(const QString& logPath); 30 | QMutex _mutex; 31 | const QString _logPath; 32 | QHash _logFiles; 33 | FILE* _defaultLogFile; 34 | }; 35 | -------------------------------------------------------------------------------- /code/base/MtsType.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "base/base_api.h" 19 | #include "base/enum_ext.h" 20 | #ifndef _WIN32 21 | #include 22 | #endif 23 | 24 | namespace mts 25 | { 26 | class BASE_API Double 27 | { 28 | public: 29 | static bool isDoubleMax(double v); 30 | static bool isValidPrice(double v); 31 | static bool isZero(double); 32 | static QString toReadableString(double v,int prec=10); 33 | static QString toString(double v, int prec); 34 | static bool isEqual(double v1, double v2); 35 | static bool isGreaterThan(double v1, double v2); 36 | static bool isLessThan(double v1, double v2); 37 | static bool isGreaterThanOrEqual(double v1, double v2); 38 | static bool isLessThanOrEqual(double v1, double v2); 39 | static double floor(double val,int precision); 40 | static double ceil(double val, int precision); 41 | static int getPrecision(double val, int precision); 42 | }; 43 | 44 | 45 | 46 | #define INSTRUMENT_ID_ENUM(declare) \ 47 | declare(TYPE_UNKNOWN,"UNKNOWN","无效标的类型") \ 48 | declare(TYPE_STK_SPOT,"STK","股票") \ 49 | declare(TYPE_FUTR,"FUT","期货") \ 50 | declare(TYPE_OPTION,"OPT","期权") \ 51 | declare(TYPE_HUOBI,"HUOBI","火币现货") \ 52 | declare(TYPE_BITMEX,"BITMEX","BitMEX") \ 53 | declare(TYPE_OKEX,"OKEX","OKEX") 54 | 55 | enum InstrumentType { INSTRUMENT_ID_ENUM(SELECT_1_AND_COMMA_IN_3) INSTRUMENT_TYPE_MAX }; 56 | 57 | BASE_API const char* instrumentTypeName(InstrumentType); 58 | BASE_API InstrumentType instrumentType(const char*); 59 | BASE_API const char* instrumentTypeDescription(InstrumentType); 60 | 61 | BASE_API int prec(InstrumentType); 62 | } 63 | -------------------------------------------------------------------------------- /code/base/Timezone.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "Timezone.h" 17 | #include 18 | #include 19 | 20 | 21 | 22 | 23 | const char * timezoneShortName(TimezoneCode timezone) { 24 | static const char* names[] = { 25 | TIMEZONE_CODE_ENUM(SELECT_2_AND_COMMA_IN_4) 26 | }; 27 | if (timezone >= 0 && timezone < ARRAY_SIZE(names)) { 28 | return names[timezone]; 29 | } else { 30 | return names[0]; 31 | } 32 | } 33 | 34 | const char * timezoneLongName(TimezoneCode timezone) { 35 | static const char* names[] = { 36 | TIMEZONE_CODE_ENUM(SELECT_3_AND_COMMA_IN_4) 37 | }; 38 | if (timezone >= 0 && timezone < ARRAY_SIZE(names)) { 39 | return names[timezone]; 40 | } else { 41 | return names[0]; 42 | } 43 | } 44 | 45 | const char * timezoneSessionName(TimezoneCode timezone) { 46 | static const char* names[] = { 47 | TIMEZONE_CODE_ENUM(SELECT_4_AND_COMMA_IN_4) 48 | }; 49 | if (timezone >= 0 && timezone < ARRAY_SIZE(names)) { 50 | return names[timezone]; 51 | } else { 52 | return names[0]; 53 | } 54 | } 55 | 56 | 57 | TimezoneCode timezoneCodeFromShortName(const char * timezoneShortName) { 58 | static QHash map; 59 | if (map.isEmpty()) { 60 | TIMEZONE_CODE_ENUM(DEFINE_NAME_ENUM_MAP4_KEY_2); 61 | } 62 | return map[timezoneShortName]; 63 | } 64 | 65 | TimezoneCode timezoneCodeFromSessiontName(const char * timezoneSessionName) { 66 | static QHash map; 67 | if (map.isEmpty()) { 68 | TIMEZONE_CODE_ENUM(DEFINE_NAME_ENUM_MAP4_KEY_4); 69 | } 70 | return map[timezoneSessionName]; 71 | } 72 | 73 | 74 | -------------------------------------------------------------------------------- /code/base/Timezone.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef __FeCountry_H__ 17 | #define __FeCountry_H__ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include "Currency.h" 23 | #include "base_api.h" 24 | 25 | 26 | #define TIMEZONE_CODE_ENUM(declare) \ 27 | declare(TIMEZONE_UNKNOWN , "UNKNOWN", "无效时区","UNKNOWN") \ 28 | declare(TIMEZONE_CST , "CST", "中国标准时间","Asia/Shanghai") \ 29 | declare(TIMEZONE_EST , "EST", "美国东部时间", "America/New_York") \ 30 | declare(TIMEZONE_UTC , "UTC", "格林威治时间", "Atlantic/Reykjavik") 31 | 32 | enum TimezoneCode { TIMEZONE_CODE_ENUM(SELECT_1_AND_COMMA_IN_4) COUNTRY_MAX }; 33 | 34 | BASE_API const char* timezoneShortName(TimezoneCode); 35 | BASE_API const char* timezoneLongName(TimezoneCode); 36 | BASE_API const char* timezoneSessionName(TimezoneCode); 37 | BASE_API TimezoneCode timezoneCodeFromShortName(const char* timezoneShortName); 38 | BASE_API TimezoneCode timezoneCodeFromSessiontName(const char* timezoneSessionName); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /code/base/UrlPath.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | #include 20 | #include "base/base_api.h" 21 | 22 | class BASE_API UrlPath 23 | { 24 | public: 25 | UrlPath(); 26 | UrlPath(const QString& url); 27 | ~UrlPath(); 28 | 29 | QString schema () const; 30 | bool isValid () const; 31 | QString toString () const; 32 | QString userName () const; 33 | QString password () const; 34 | 35 | QString setUserPassword(const QString& user, const QString& password); 36 | QString clearUserPassword(); 37 | QString toLocalPath () const; 38 | QVariantMap queryItems () const; 39 | 40 | bool operator==( const UrlPath& ) const; 41 | 42 | static UrlPath fromLocalPath(const QString&); 43 | private: 44 | QString _url; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /code/base/base.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-06-14T21:46:07 4 | # 5 | #------------------------------------------------- 6 | DEFINES += RIGHTS_END_DATE=20190601 7 | 8 | 9 | QT -= gui 10 | 11 | TARGET = base 12 | TEMPLATE = lib 13 | 14 | DEFINES += BASE_LIB 15 | 16 | # The following define makes your compiler emit warnings if you use 17 | # any feature of Qt which as been marked as deprecated (the exact warnings 18 | # depend on your compiler). Please consult the documentation of the 19 | # deprecated API in order to know how to port your code away from it. 20 | DEFINES += QT_DEPRECATED_WARNINGS 21 | 22 | # You can also make your code fail to compile if you use deprecated APIs. 23 | # In order to do so, uncomment the following line. 24 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 25 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 26 | 27 | 28 | SOURCES += \ 29 | Currency.cpp \ 30 | Timezone.cpp \ 31 | DateTime.cpp \ 32 | Event.cpp \ 33 | EventDispatcher.cpp \ 34 | EventQueue.cpp \ 35 | MtsLog.cpp \ 36 | MtsUtils.cpp \ 37 | UrlPath.cpp \ 38 | LogFixtureMgr.cpp \ 39 | MtsPath.cpp \ 40 | Library.cpp \ 41 | MtsType.cpp \ 42 | 43 | HEADERS += \ 44 | base_api.h \ 45 | Currency.h \ 46 | enum_ext.h \ 47 | Timezone.h \ 48 | DateTime.h \ 49 | NotifiableObserver.h \ 50 | Event.h \ 51 | EventDispatcher.h \ 52 | EventQueue.h \ 53 | EventType.h \ 54 | MtsLog.h \ 55 | MtsUtils.h \ 56 | number.h \ 57 | PerfTest.h \ 58 | UrlPath.h \ 59 | LogFixtureMgr.h \ 60 | MtsPath.h \ 61 | Library.h \ 62 | MtsType.h \ 63 | 64 | unix { 65 | target.path = /usr/lib 66 | INSTALLS += target 67 | } 68 | 69 | RESOURCES += \ 70 | qt_res.qrc 71 | 72 | include (../global.pri) 73 | LIBS += -lz 74 | -------------------------------------------------------------------------------- /code/base/base_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef BASE_GLOBAL_H 17 | #define BASE_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef BASE_LIB 22 | # define BASE_API Q_DECL_EXPORT 23 | #else 24 | # define BASE_API Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // BASE_GLOBAL_H 28 | -------------------------------------------------------------------------------- /code/base/number.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #define Nan -99999 19 | #define isNan(v) (v==Nan) 20 | #define PRICE_TINY 0.0000000001 -------------------------------------------------------------------------------- /code/base/qt_res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/date_time_zonespec.csv 4 | 5 | 6 | -------------------------------------------------------------------------------- /code/clock_real/ClockReal.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "base/DateTime.h" 18 | #include "mts_core/Clock.h" 19 | #include 20 | 21 | 22 | namespace mts 23 | { 24 | 25 | class ClockTimerReal :public QTimer 26 | { 27 | Q_OBJECT 28 | public: 29 | ClockTimerReal(int id,TimerCallback*, QObject * parent = 0); 30 | virtual ~ClockTimerReal(); 31 | 32 | private Q_SLOTS: 33 | void onTimeout(); 34 | private: 35 | const int _id; 36 | TimerCallback* _callback; 37 | }; 38 | 39 | 40 | class ClockReal :public Clock 41 | { 42 | Q_OBJECT 43 | public: 44 | ClockReal(void); 45 | virtual ~ClockReal(void); 46 | 47 | virtual DateTime now() const override; 48 | virtual int currentTradingDay () const override; 49 | protected: 50 | virtual QObject* doCreateTimer(int id, qint64 beginTicks, int interval, TimerCallback*) override; 51 | virtual bool doDestroyTimer(QObject*) override; 52 | 53 | virtual bool initialize(const QVariantMap & params) override; 54 | private Q_SLOTS: 55 | void onTimeout(); 56 | private: 57 | qint64 getNextBeginTimeInterval() const; 58 | }; 59 | 60 | } -------------------------------------------------------------------------------- /code/clock_real/clock_real.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-06-15T20:49:18 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= gui 8 | 9 | TARGET = clock_real 10 | TEMPLATE = lib 11 | 12 | DEFINES += CLOCK_REAL_LIBRARY 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | SOURCES += \ 26 | ClockReal.cpp \ 27 | mts_clock_real.cpp 28 | 29 | HEADERS += \ 30 | ClockReal.h \ 31 | clock_real_api.h 32 | 33 | unix { 34 | target.path = /usr/lib 35 | INSTALLS += target 36 | } 37 | 38 | MY_LIB_LIST = base mts_core 39 | include (../global.pri) 40 | #LIBS += -lz 41 | -------------------------------------------------------------------------------- /code/clock_real/clock_real_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef MTS_CLOCK_REAL_GLOBAL_H 17 | #define MTS_CLOCK_REAL_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef MTS_CLOCK_REAL_LIB 22 | # define MTS_CLOCK_REAL_API Q_DECL_EXPORT 23 | #else 24 | # define MTS_CLOCK_REAL_API Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // MTS_CLOCK_REAL_GLOBAL_H 28 | -------------------------------------------------------------------------------- /code/clock_real/mts_clock_real.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "clock_real_api.h" 17 | #include "ClockReal.h" 18 | #include "mts_core/enums.h" 19 | 20 | extern "C" { 21 | MTS_CLOCK_REAL_API mts::Clock* createClock(mts::EnvironmentMode mode) { 22 | if (mode != mts::ENVIR_REAL) { 23 | return nullptr; 24 | } 25 | return new mts::ClockReal(); 26 | } 27 | 28 | MTS_CLOCK_REAL_API void releaseClock(mts::Clock* clock) { 29 | delete clock; 30 | } 31 | } -------------------------------------------------------------------------------- /code/ctp_ext/CTPClientBase.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | 20 | #ifdef _WIN32 21 | #include "../../api/win64/CTP/ThostFtdcUserApiStruct.h" 22 | #include "../../api/win64/CTP/ThostFtdcTraderApi.h" 23 | #include "../../api/win64/CTP/ThostFtdcMdApi.h" 24 | #else 25 | #include "../../api/linux64/CTP/ThostFtdcUserApiStruct.h" 26 | #include "../../api/linux64/CTP/ThostFtdcTraderApi.h" 27 | #include "../../api/linux64/CTP/ThostFtdcMdApi.h" 28 | #include 29 | #endif 30 | 31 | #include "base/MtsLog.h" 32 | #include "base/MtsUtils.h" 33 | #include "ctp_ext_api.h" 34 | 35 | 36 | class CTP_EXT_API CTPClientBase 37 | { 38 | public: 39 | CTPClientBase(const QString& address, const QString& brokerId, const QString& userId, const QString& password); 40 | virtual ~CTPClientBase(); 41 | 42 | static QString returnValue2String(int ret); 43 | static bool processQryRet(const QString& queryName, int ret); 44 | static bool processRspInfoField(CThostFtdcRspInfoField* rspInfo, const QString& action); 45 | static void printCThostFtdcRspUserLoginField(CThostFtdcRspUserLoginField* loginRsp); 46 | protected: 47 | const QString _ADDRESS; 48 | const QString _BROKER_ID; 49 | const QString _USER_ID; 50 | const QString _PASSWORD; 51 | 52 | int nextRequestId(); 53 | private: 54 | int _requestId; 55 | 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /code/ctp_ext/ctp_ext_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef CTP_EXT_GLOBAL_H 17 | #define CTP_EXT_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef CTP_EXT_LIB 22 | # define CTP_EXT_API Q_DECL_EXPORT 23 | #else 24 | # define CTP_EXT_API Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // CTP_EXT_GLOBAL_H 28 | -------------------------------------------------------------------------------- /code/ctp_ext/ctp_md.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | 19 | #ifdef _WIN32 20 | #include "../../api/win64/CTP/ThostFtdcUserApiStruct.h" 21 | #include "../../api/win64/CTP/ThostFtdcMdApi.h" 22 | #else 23 | #include "../../api/linux64/CTP/ThostFtdcUserApiStruct.h" 24 | #include "../../api/linux64/CTP/ThostFtdcMdApi.h" 25 | #include 26 | #endif 27 | -------------------------------------------------------------------------------- /code/feeds_real_CTP/FeedsReal.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "mts_core/Feeds.h" 19 | #include "CTPFeedsClient.h" 20 | 21 | #include "base/EventDispatcher.h" 22 | 23 | 24 | namespace mts 25 | { 26 | 27 | class FeedsReal :public Feeds, public EventCallback 28 | { 29 | Q_OBJECT 30 | public: 31 | FeedsReal(); 32 | virtual ~FeedsReal(); 33 | 34 | virtual bool initialize(const QVariantMap & params) override; 35 | 36 | virtual int subscribe(const QList&) override; 37 | virtual int unsubscribe(const QList&) override; 38 | private: 39 | CTPFeedsClient* _feedsClient; 40 | virtual void onEvent(const EventPtr&) override; 41 | }; 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /code/feeds_real_CTP/QuoteEvent.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "base/Event.h" 18 | #include "mts_core/Quote.h" 19 | 20 | #include "base/EventType.h" 21 | 22 | 23 | typedef DataEvent QuoteEvent; 24 | typedef QSharedPointer QuoteEventPtr; 25 | -------------------------------------------------------------------------------- /code/feeds_real_CTP/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtsquant/MTS/ab7ecab0f88c844289b5c81e5627326fe36e682f/code/feeds_real_CTP/README.md -------------------------------------------------------------------------------- /code/feeds_real_CTP/feeds_real_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | #ifdef MTS_FEEDS_REAL_LIB 20 | # define MTS_FEEDS_REAL_API Q_DECL_EXPORT 21 | #else 22 | # define MTS_FEEDS_REAL_API Q_DECL_IMPORT 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /code/feeds_real_CTP/mts_feeds_real.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "feeds_real_api.h" 17 | #include "FeedsReal.h" 18 | #include "mts_core/enums.h" 19 | 20 | using namespace mts; 21 | 22 | 23 | extern "C" { 24 | MTS_FEEDS_REAL_API mts::FeedsBase* createFeeds(mts::EnvironmentMode mode) { 25 | if (mode != ENVIR_REAL) { 26 | return nullptr; 27 | } 28 | return new mts::FeedsReal(); 29 | } 30 | 31 | MTS_FEEDS_REAL_API void releaseFeeds(mts::Feeds* feeds) { 32 | delete feeds; 33 | } 34 | 35 | MTS_FEEDS_REAL_API QList* supportExchs() { 36 | static QList exchs = QList() << EXCH_SHFE 37 | << EXCH_DCE 38 | << EXCH_CZCE 39 | << EXCH_CFFEX 40 | << EXCH_INE; 41 | return &exchs; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /code/mts/AbsStrategy.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "./AbsStrategy.h" 17 | #include "mts/StrategyMgr.h" 18 | #include "mts/CrossThreadNotifier.h" 19 | 20 | AbsStrategy::AbsStrategy(const std::string& name , int strategyId, const std::string& strategyPath) 21 | :QObject() , _notifier(new mts::CrossThreadNotifier(name,strategyId,strategyPath)) 22 | { 23 | _notifier->connectSignalInitializedl(this); 24 | StrategyMgr::instance()->registerStrategy(_notifier); 25 | } 26 | 27 | 28 | AbsStrategy::~AbsStrategy() 29 | { 30 | StrategyMgr::instance()->unregisterStrategy(_notifier); 31 | delete _notifier; 32 | _notifier = nullptr; 33 | } 34 | 35 | 36 | int AbsStrategy::newTimer(int beginTime, int interval) { 37 | return StrategyMgr::instance()->newTimer(_notifier, beginTime, interval); 38 | } 39 | 40 | int AbsStrategy::newOnceTimer(int beginTime) { 41 | return StrategyMgr::instance()->newOnceTimer(_notifier, beginTime); 42 | } 43 | 44 | bool AbsStrategy::removeTimer(int id) { 45 | return StrategyMgr::instance()->removeTimer(_notifier, id); 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /code/mts/AccountMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "AccountMgr.h" 17 | 18 | namespace mts { 19 | 20 | AccountMgr * mts::AccountMgr::instance() 21 | { 22 | static AccountMgr accountMgr; 23 | return &accountMgr; 24 | } 25 | 26 | void AccountMgr::setStrategy(StrategyInterface * notify) 27 | { 28 | _notify = notify; 29 | } 30 | 31 | AccountMgr::AccountMgr() 32 | :_notify(nullptr) 33 | { 34 | } 35 | 36 | 37 | AccountMgr::~AccountMgr() 38 | { 39 | } 40 | 41 | void AccountMgr::onEnvirInitialized() { 42 | _notify->onEnvirInitialized(); 43 | } 44 | 45 | void AccountMgr::onInitialized(Account *) 46 | { 47 | Account account; 48 | _notify->onInitialized(&account); 49 | } 50 | 51 | 52 | } -------------------------------------------------------------------------------- /code/mts/AccountMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/StrategyInterface.h" 18 | 19 | namespace mts { 20 | class AccountMgr:public AccountCallback 21 | { 22 | public: 23 | static AccountMgr* instance(); 24 | void setStrategy(StrategyInterface* notify); 25 | 26 | virtual void onEnvirInitialized() override; 27 | virtual void onInitialized(Account *) override; 28 | 29 | private: 30 | AccountMgr(); 31 | virtual ~AccountMgr(); 32 | 33 | StrategyInterface* _notify; 34 | 35 | 36 | 37 | }; 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /code/mts/ClockMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "ClockMgr.h" 17 | #include "mts_core/Environment.h" 18 | #include "MtsMainThread.h" 19 | 20 | namespace mts 21 | { 22 | 23 | 24 | ClockMgr::ClockMgr() { 25 | assert(Environment::instance()->isCurrentMtsThread()); 26 | } 27 | 28 | 29 | ClockMgr::~ClockMgr() { 30 | } 31 | 32 | ClockMgr * ClockMgr::instance() { 33 | static ClockMgr mgr; 34 | return &mgr; 35 | } 36 | 37 | bool ClockMgr::destoryTimer(int timerId){ 38 | return Environment::instance()->clock()->destroyTimer(timerId); 39 | } 40 | 41 | DateTime ClockMgr::now() const { 42 | return Environment::instance()->clock()->now(); 43 | } 44 | 45 | int ClockMgr::currentTradingDay () const{ 46 | return Environment::instance ()->clock ()->currentTradingDay(); 47 | } 48 | 49 | 50 | int ClockMgr::createTimer(int beginTime, int interval, TimerCallback * callback) { 51 | return Environment::instance()->clock()->createTimer(beginTime,interval,callback); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /code/mts/ClockMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core/TimerCallback.h" 19 | #include "base/DateTime.h" 20 | 21 | namespace mts 22 | { 23 | 24 | class ClockMgr :public QObject 25 | { 26 | Q_OBJECT 27 | ClockMgr(); 28 | ~ClockMgr(); 29 | public: 30 | static ClockMgr* instance(); 31 | 32 | 33 | public Q_SLOTS: 34 | int createTimer(int beginTime,int interval, TimerCallback*); 35 | bool destoryTimer(int timerId); 36 | DateTime now () const; 37 | int currentTradingDay () const; 38 | }; 39 | 40 | } -------------------------------------------------------------------------------- /code/mts/MtsMainThread.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "mts_core/enums.h" 20 | 21 | namespace mts 22 | { 23 | class MtsMainThread; 24 | typedef boost::function InitFuntorInThread; 25 | typedef boost::function ThreadCreator; 26 | class MtsMainThread 27 | { 28 | public: 29 | static MtsMainThread* instance(EnvironmentMode mode); 30 | virtual bool init(const QVariantMap & params,const InitFuntorInThread& initFunInThread) ; 31 | virtual void enterEventLoop() = 0; 32 | virtual void exitEventLoop()=0; 33 | protected: 34 | bool initMgrs(const QVariantMap & params); 35 | 36 | private: 37 | InitFuntorInThread _initFunInThread; 38 | 39 | public: 40 | static int registerThread(EnvironmentMode mode, const ThreadCreator&); 41 | 42 | }; 43 | 44 | 45 | 46 | 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /code/mts/MtsMainThreadReal.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "./MtsMainThread.h" 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | namespace mts 24 | { 25 | 26 | class MtsMainThreadReal :public MtsMainThread, protected QThread { 27 | public: 28 | MtsMainThreadReal(); 29 | virtual ~MtsMainThreadReal(); 30 | virtual bool init(const QVariantMap & params, const InitFuntorInThread& initFunInThread) override; 31 | virtual void enterEventLoop() override; 32 | virtual void exitEventLoop() override; 33 | 34 | private: 35 | void waitForEnterEventLoop(); 36 | 37 | private: 38 | virtual void run() override; 39 | QMutex _enterEventLoopMutex; 40 | QVariantMap _params; 41 | bool _initDone; 42 | QAtomicInt _quitFlag; 43 | }; 44 | 45 | 46 | } -------------------------------------------------------------------------------- /code/mts/MtsProxy.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "MtsProxy.h" 17 | 18 | namespace mts{ 19 | MtsProxy * MtsProxy::instance() { 20 | static MtsProxy proxy; 21 | return &proxy; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /code/mts/MtsProxy.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "MtsProxyBase.h" 18 | 19 | namespace mts { 20 | 21 | class MtsProxy :public MtsProxyBase 22 | { 23 | public: 24 | static MtsProxy * instance(); 25 | 26 | }; 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /code/mts/OrderFillMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "OrderFillMgr.h" 17 | 18 | namespace mts 19 | { 20 | OrderFillMgr* OrderFillMgr::_instance = nullptr; 21 | OrderFillMgr::OrderFillMgr() 22 | { 23 | } 24 | 25 | 26 | OrderFillMgr::~OrderFillMgr() 27 | { 28 | } 29 | 30 | OrderFillMgr* OrderFillMgr::instance() 31 | { 32 | if (_instance == nullptr) { 33 | _instance = new OrderFillMgr; 34 | } 35 | return _instance; 36 | } 37 | 38 | QList OrderFillMgr::allFills() const 39 | { 40 | return _fillSet.allFills(); 41 | } 42 | 43 | OrderReportFill* OrderFillMgr::getFill(const QString& fillId, DirectionSide side, ExchId exch) const 44 | { 45 | return _fillSet.getFill(fillId, side, exch); 46 | } 47 | 48 | void OrderFillMgr::updateFill(OrderReportFill* fill) 49 | { 50 | _fillSet.updateFill(fill); 51 | } 52 | } -------------------------------------------------------------------------------- /code/mts/OrderFillMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "mts_core/OrderFillSet.h" 20 | 21 | namespace mts { 22 | class OrderFillMgr:public QObject 23 | { 24 | Q_OBJECT 25 | public: 26 | static OrderFillMgr* instance(); 27 | public Q_SLOTS: 28 | QList allFills()const; 29 | OrderReportFill* getFill(const QString& fillId, DirectionSide side, ExchId exch) const; 30 | void updateFill(OrderReportFill*); 31 | private: 32 | OrderFillMgr(); 33 | virtual ~OrderFillMgr(); 34 | OrderFillSet _fillSet; 35 | static OrderFillMgr* _instance; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /code/mts/OrderMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "OrderMgr.h" 17 | 18 | namespace mts { 19 | 20 | OrderMgr* OrderMgr::_instance = nullptr; 21 | 22 | OrderMgr * OrderMgr::instance() { 23 | if (_instance == nullptr) { 24 | _instance = new OrderMgr; 25 | } 26 | return _instance; 27 | } 28 | 29 | OrderMgr::OrderMgr() 30 | { 31 | } 32 | 33 | OrderMgr::~OrderMgr() 34 | { 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /code/mts/OrderMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "OrderMgrBase.h" 18 | 19 | namespace mts { 20 | 21 | class OrderMgr :public OrderMgrBase 22 | { 23 | public: 24 | static OrderMgr* instance(); 25 | 26 | private: 27 | OrderMgr(); 28 | virtual ~OrderMgr(); 29 | static OrderMgr* _instance; 30 | }; 31 | 32 | } -------------------------------------------------------------------------------- /code/mts/PositionMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include "mts_core/const.h" 21 | #include "mts_core/InstrumentId.h" 22 | #include "mts_core/Environment.h" 23 | #include "mts/mts_api.h" 24 | 25 | 26 | namespace mts 27 | { 28 | 29 | class Position; 30 | class PosInnerMgr; 31 | class MTS_API PositionMgr:public QObject 32 | { 33 | Q_OBJECT 34 | public: 35 | static PositionMgr* instance(); 36 | static QString getStrategyKey(int instanceId = Environment::instance()->instanceId(), int strategyId = DEFAULT_STRATEGY_ID); 37 | void businessDateChanged(int businessDate); 38 | public Q_SLOTS: 39 | Position* getPosition(const InstrumentId& id, GetMode = GM_GET); 40 | Position* getPosition(const InstrumentId& id,int instanceId, int strategyId, GetMode = GM_GET); 41 | QList getStrategyPositions(const InstrumentId& id) const; 42 | void clear(); 43 | QList allPositions(int strategyId= DEFAULT_STRATEGY_ID) const; 44 | QList allValidPositions(int strategyId = DEFAULT_STRATEGY_ID) const; 45 | private: 46 | PositionMgr(); 47 | ~PositionMgr(); 48 | typedef QHash PosHash; 49 | PosHash _posHash; 50 | static PositionMgr* _mgr; 51 | }; 52 | 53 | } -------------------------------------------------------------------------------- /code/mts/PositionPersistence.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | class QFile; 19 | namespace mts 20 | { 21 | class Position; 22 | class PositionPersistence 23 | { 24 | public: 25 | PositionPersistence(const QString& strategyKey, const QString& dir); 26 | ~PositionPersistence(); 27 | QList getYesterdayPos()const; 28 | void updateTodayPosition(Position*); 29 | private: 30 | QString getYesterdayFile() const; 31 | void closeWrite(); 32 | const QString _strategyKey; 33 | const QString _dir; 34 | QFile* _write; 35 | int _tradingDay; 36 | }; 37 | } -------------------------------------------------------------------------------- /code/mts/QuoteMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core/InstrumentId.h" 19 | 20 | #include "mts_core/StrategyInterface.h" 21 | #include "mts_api.h" 22 | 23 | namespace mts 24 | { 25 | class QuoteSet; 26 | class QuoteMgr :public QObject,public FeedsCallback 27 | { 28 | Q_OBJECT; 29 | QuoteMgr(); 30 | virtual ~QuoteMgr(); 31 | public: 32 | static QuoteMgr* instance(); 33 | void setStrategy(StrategyInterface* notify); 34 | public Q_SLOTS: 35 | int subscribe(const QList&); 36 | int unsubscribe(const QList&); 37 | Quote* getQuote(const InstrumentId&); 38 | 39 | int subscribedInstrumentCount() const; 40 | virtual void onQuoteUpdate(QuotePtr) override; 41 | virtual void onBusinessDateChanged(int businessDate) override; 42 | virtual void onBarUpdate(CalcBarPtr) override; 43 | private: 44 | QuoteSet* _quoteSet; 45 | StrategyInterface* _notify; 46 | 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /code/mts/StrategyMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "StrategyMgr.h" 17 | 18 | namespace mts { 19 | 20 | StrategyMgr* StrategyMgr::_instance = nullptr; 21 | 22 | StrategyMgr * StrategyMgr::instance() { 23 | if (StrategyMgr::_instance == nullptr) { 24 | StrategyMgr::_instance = new StrategyMgr(); 25 | } 26 | return StrategyMgr::_instance; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /code/mts/StrategyMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "StrategyHub.h" 18 | 19 | 20 | namespace mts { 21 | 22 | class MTS_API StrategyMgr :public StrategyHub 23 | { 24 | public: 25 | static StrategyMgr* instance(); 26 | 27 | private: 28 | static StrategyMgr* _instance; 29 | 30 | }; 31 | 32 | } -------------------------------------------------------------------------------- /code/mts/TradingAccountMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "TradingAccountMgr.h" 17 | 18 | namespace mts 19 | { 20 | TradingAccountMgr* TradingAccountMgr::_instance = nullptr; 21 | TradingAccountMgr::TradingAccountMgr() 22 | { 23 | } 24 | 25 | 26 | TradingAccountMgr::~TradingAccountMgr() 27 | { 28 | qDeleteAll(_accounts); 29 | } 30 | 31 | TradingAccountMgr* TradingAccountMgr::instance() 32 | { 33 | if (_instance == nullptr) { 34 | _instance = new TradingAccountMgr; 35 | } 36 | return _instance; 37 | } 38 | 39 | QList TradingAccountMgr::allTradingAccount() const 40 | { 41 | return _accounts.values(); 42 | } 43 | 44 | TradingAccount* TradingAccountMgr::getTradingAccount(const TradingAccountId& id) const 45 | { 46 | auto it = _accounts.constFind(id.key()); 47 | if (it != _accounts.cend()) { 48 | return it.value(); 49 | } 50 | return nullptr; 51 | } 52 | 53 | void TradingAccountMgr::updateTradingAccount(TradingAccount* ta) 54 | { 55 | TradingAccount* last = _accounts[ta->accountId().key()]; 56 | if (last != nullptr) { 57 | *last=*ta; 58 | } 59 | else { 60 | _accounts[ta->accountId().key()] = new TradingAccount(*ta); 61 | } 62 | } 63 | 64 | TradingAccount * TradingAccountMgr::getTradingAccount(CurrencyId currency) const { 65 | for (auto it = _accounts.constBegin(), itEnd = _accounts.constEnd(); it != itEnd; ++it) { 66 | TradingAccount* account = it.value(); 67 | if (account->accountId().currency == currency) { 68 | return account; 69 | } 70 | } 71 | 72 | return nullptr; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /code/mts/TradingAccountMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "mts_core/TradingAccount.h" 20 | 21 | namespace mts 22 | { 23 | class TradingAccountMgr :public QObject 24 | { 25 | Q_OBJECT 26 | public: 27 | static TradingAccountMgr* instance(); 28 | public Q_SLOTS: 29 | QList allTradingAccount()const; 30 | TradingAccount* getTradingAccount(const TradingAccountId& fillId) const; 31 | void updateTradingAccount(TradingAccount*); 32 | TradingAccount* getTradingAccount(CurrencyId currency)const; 33 | private: 34 | TradingAccountMgr(); 35 | ~TradingAccountMgr(); 36 | static TradingAccountMgr* _instance; 37 | QHash _accounts; 38 | }; 39 | 40 | } -------------------------------------------------------------------------------- /code/mts/mts_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef MTS_GLOBAL_H 17 | #define MTS_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef MTS_LIB 22 | # define MTS_API Q_DECL_EXPORT 23 | #else 24 | # define MTS_API Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // MTS_GLOBAL_H 28 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyAccount.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyAccount.h" 17 | 18 | 19 | 20 | PyAccount::PyAccount (const mts::Account& account, const boost::python::list& activeOrders, const boost::python::list& positions) 21 | :mts::Account(account),_activeOrders(activeOrders),_positions(positions) 22 | { 23 | } 24 | 25 | 26 | PyAccount::~PyAccount () 27 | { 28 | } 29 | 30 | PyInstrumentProperty PyAccount::findInstrumentProperty ( const std::string & symbol ){ 31 | auto* ip=dynamic_cast(this->find ( symbol.c_str () )); 32 | if ( ip == nullptr ){ 33 | return PyInstrumentProperty (); 34 | } else{ 35 | return PyInstrumentProperty ( *ip ); 36 | } 37 | } 38 | 39 | boost::python::list PyAccount::allActiveOrders() const { 40 | return _activeOrders; 41 | } 42 | 43 | boost::python::list PyAccount::allPositions() const { 44 | return _positions; 45 | } 46 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyAccount.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/Account.h" 18 | #include 19 | #include "PyInstrumentProperty.h" 20 | 21 | 22 | 23 | 24 | class PyAccount : public mts::Account 25 | { 26 | public: 27 | PyAccount (const mts::Account &,const boost::python::list& activeOrders, const boost::python::list& positions); 28 | virtual ~PyAccount (); 29 | 30 | PyInstrumentProperty findInstrumentProperty ( const std::string& symbol ); 31 | boost::python::list allActiveOrders() const; 32 | 33 | boost::python::list allPositions() const; 34 | private: 35 | boost::python::list _activeOrders; 36 | boost::python::list _positions; 37 | }; 38 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyBar.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyBar.h" 17 | #include "mts_core/InstrumentPropertyDb.h" 18 | 19 | 20 | 21 | PyBar::PyBar ( const mts::CalcBar & bar) 22 | :mts::CalcBar(bar) 23 | { 24 | } 25 | 26 | 27 | PyBar::~PyBar () 28 | { 29 | } 30 | 31 | 32 | std::string PyBar::pySymbol () const{ 33 | return TO_UTF8_STD_STR(this->symbol()); 34 | } 35 | 36 | std::string PyBar::pyMtsSymbol () const{ 37 | return TO_UTF8_STD_STR(this->mtsSymbol()); 38 | } 39 | 40 | std::string PyBar::pyExchId () const{ 41 | return TO_UTF8_STD_STR(this->exchId()); 42 | } 43 | 44 | PyDateTime PyBar::pyBeginDateTime () const{ 45 | return PyDateTime ( this->beginTicksSinceEpoch () ); 46 | } 47 | 48 | PyDateTime PyBar::pyEndDateTime() const { 49 | return PyDateTime(this->endTicksSinceEpoch()); 50 | } 51 | 52 | std::string PyBar::toString () const{ 53 | return TO_UTF8_STD_STR(this->toJsonString()); 54 | } 55 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyBar.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/CalcBar.h" 18 | #include "PyDateTime.h" 19 | 20 | class PyBar:public mts::CalcBar 21 | { 22 | public: 23 | PyBar (const mts::CalcBar &); 24 | ~PyBar (); 25 | 26 | std::string pySymbol () const; 27 | std::string pyMtsSymbol () const; 28 | std::string pyExchId () const; 29 | PyDateTime pyBeginDateTime () const; 30 | PyDateTime pyEndDateTime() const; 31 | 32 | std::string toString () const; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyDateTime.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyDateTime.h" 17 | 18 | PyDateTime::PyDateTime(qint64 utcMillisecsSinceEpoch) 19 | :DateTime(utcMillisecsSinceEpoch) { 20 | } 21 | 22 | PyDateTime::PyDateTime(const DateTime & dt) 23 | : DateTime(dt) { 24 | } 25 | 26 | PyDateTime::PyDateTime(int date, int time) 27 | :DateTime(time,date) 28 | { 29 | 30 | } 31 | 32 | std::string PyDateTime::toString() const { 33 | return DateTime::toLocalString().toStdString(); 34 | } 35 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyDateTime.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "base/DateTime.h" 18 | 19 | 20 | class PyDateTime :public DateTime 21 | { 22 | public: 23 | PyDateTime(qint64 utcMillisecsSinceEpoch); 24 | PyDateTime(const DateTime& dt); 25 | PyDateTime(int date, int time); 26 | std::string toString() const; 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyInstrumentProperty.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyInstrumentProperty.h" 17 | 18 | PyInstrumentProperty::PyInstrumentProperty () 19 | :mts::InstrumentProperty() 20 | { 21 | } 22 | 23 | PyInstrumentProperty::PyInstrumentProperty(const mts::InstrumentProperty & p) 24 | :mts::InstrumentProperty(p) { 25 | 26 | } 27 | 28 | std::string PyInstrumentProperty::pyName() const { 29 | return TO_UTF8_STD_STR(mts::InstrumentBaseProperty::name()); 30 | } 31 | 32 | std::string PyInstrumentProperty::pyMtsSymbol() const { 33 | return TO_UTF8_STD_STR(mts::InstrumentBaseProperty::mtsSymbol()); 34 | } 35 | 36 | std::string PyInstrumentProperty::toString() const { 37 | return TO_UTF8_STD_STR(mts::InstrumentBaseProperty::toJsonString()); 38 | } 39 | 40 | std::string PyInstrumentProperty::pySymbol() const { 41 | return TO_UTF8_STD_STR(mts::InstrumentBaseProperty::instrumentId().symbol); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyInstrumentProperty.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/InstrumentProperty.h" 18 | 19 | 20 | class PyInstrumentProperty :public mts::InstrumentProperty 21 | { 22 | public: 23 | PyInstrumentProperty (); //null 24 | PyInstrumentProperty(const mts::InstrumentProperty &p); 25 | std::string pyName() const; 26 | std::string pySymbol() const; 27 | std::string pyMtsSymbol() const; 28 | std::string toString() const; 29 | }; -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrder.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyOrder.h" 17 | 18 | 19 | 20 | PyOrder::PyOrder(const mts::Order& order) 21 | :PyOrderReportTpl(order) 22 | { 23 | } 24 | 25 | 26 | PyOrder::~PyOrder() { 27 | } 28 | 29 | std::string PyOrder::pyStatusString() const { 30 | return TO_UTF8_STD_STR(this->statusString()); 31 | } 32 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrder.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "PyOrderReport.h" 18 | #include "mts_core/Order.h" 19 | 20 | class PyOrder:public PyOrderReportTpl 21 | { 22 | public: 23 | PyOrder(const mts::Order&); 24 | ~PyOrder(); 25 | 26 | std::string pyStatusString() const; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderCancelDone.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "PyOrderReport.h" 19 | 20 | typedef PyOrderReportTpl PyOrderCancelDone; 21 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderCancelReject.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "PyOrderReport.h" 19 | 20 | typedef PyOrderReportTpl PyOrderCancelReject; 21 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderFill.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyOrderFill.h" 17 | 18 | 19 | 20 | PyOrderFill::PyOrderFill (const mts::OrderReportFill & fill) 21 | :PyOrderReportTpl(fill) 22 | { 23 | } 24 | 25 | 26 | PyOrderFill::~PyOrderFill (){ 27 | } 28 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderFill.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "PyOrderReport.h" 18 | 19 | class PyOrderFill:public PyOrderReportTpl 20 | { 21 | public: 22 | PyOrderFill (const mts::OrderReportFill &); 23 | ~PyOrderFill (); 24 | 25 | std::string pyFillId () const{ 26 | return TO_UTF8_STD_STR(this->fillId()) ; 27 | } 28 | 29 | PyDateTime pyFillDateTime () const{ 30 | return PyDateTime ( this->fillTicksSinceEpoch () ); 31 | } 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderNewDone.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "PyOrderReport.h" 19 | 20 | typedef PyOrderReportTpl PyOrderNewDone; 21 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderNewReject.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "PyOrderReport.h" 19 | 20 | typedef PyOrderReportTpl PyOrderNewReject; 21 | 22 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyOrderReport.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "mts_core/OrderReport.h" 19 | #include "PyDateTime.h" 20 | #include "mts_core/InstrumentPropertyDb.h" 21 | 22 | template 23 | class PyOrderReportTpl :public _TP 24 | { 25 | public: 26 | PyOrderReportTpl ( const _TP& report) 27 | :_TP(report) 28 | { 29 | } 30 | 31 | ~PyOrderReportTpl () 32 | { 33 | } 34 | 35 | std::string pySymbol () const{ 36 | return TO_UTF8_STD_STR(this->symbol()); 37 | } 38 | std::string pyMtsSymbol () const{ 39 | return TO_UTF8_STD_STR(this->mtsSymbol()); 40 | } 41 | std::string pyExchId () const{ 42 | return TO_UTF8_STD_STR(this->exchId()); 43 | } 44 | PyDateTime pyCreatedDateTime () const{ 45 | return PyDateTime ( this->createTicksSinceEpoch () ); 46 | } 47 | std::string pyOrderExchId () const{ 48 | return TO_UTF8_STD_STR(this->orderExchId()); 49 | } 50 | std::string pyNote () const{ 51 | return TO_UTF8_STD_STR(this->note()); 52 | } 53 | std::string pyPerfNote()const 54 | { 55 | return TO_UTF8_STD_STR(this->perfNote()); 56 | } 57 | std::string pyCreateSrc () const{ 58 | return TO_UTF8_STD_STR(this->createSrc()) ; 59 | } 60 | std::string toString () const{ 61 | return TO_UTF8_STD_STR(this->toJsonString()); 62 | } 63 | std::string referenceId2String()const { 64 | return TO_UTF8_STD_STR(this->referenceId()); 65 | } 66 | }; 67 | 68 | typedef PyOrderReportTpl PyOrderReport; -------------------------------------------------------------------------------- /code/mts_agent_python/PyPosition.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyPosition.h" 17 | #include "mts_core/InstrumentPropertyDb.h" 18 | 19 | 20 | PyPosition::PyPosition() 21 | { 22 | } 23 | 24 | PyPosition::PyPosition(const mts::Position& pos) 25 | :mts::Position(pos) 26 | { 27 | } 28 | 29 | 30 | PyPosition::~PyPosition() 31 | { 32 | } 33 | 34 | 35 | std::string PyPosition::pySymbol() const { 36 | return TO_UTF8_STD_STR(this->symbol()); 37 | } 38 | 39 | std::string PyPosition::pyMtsSymbol() const { 40 | return TO_UTF8_STD_STR(this->mtsSymbol()); 41 | } 42 | 43 | std::string PyPosition::pyExchId() const { 44 | return TO_UTF8_STD_STR(this->exchId()); 45 | } 46 | 47 | std::string PyPosition::toString() const { 48 | return TO_UTF8_STD_STR(this->toJsonString()); 49 | } 50 | 51 | PyInstrumentProperty PyPosition::pyAttribute() const { 52 | auto* p = dynamic_cast(this->attribute()); 53 | if (p) { 54 | return PyInstrumentProperty(*p); 55 | } else { 56 | return PyInstrumentProperty(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyPosition.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/Position.h" 18 | #include "PyInstrumentProperty.h" 19 | 20 | class PyPosition:public mts::Position 21 | { 22 | public: 23 | PyPosition(); 24 | PyPosition(const mts::Position&); 25 | ~PyPosition(); 26 | 27 | std::string pySymbol() const; 28 | std::string pyMtsSymbol() const; 29 | std::string pyExchId() const; 30 | std::string toString() const; 31 | PyInstrumentProperty pyAttribute() const; 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyQuote.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyQuote.h" 17 | #include "mts_core/InstrumentPropertyDb.h" 18 | #include 19 | 20 | 21 | PyQuote::PyQuote() 22 | :mts::QuoteSnapshot (), _us(0) 23 | { 24 | #ifdef MTS_LOG_DISABLED 25 | _us = DateTime::nowToUTCMicrosecsSinceEpoch(); 26 | #endif 27 | } 28 | 29 | PyQuote::PyQuote(const mts::QuoteSnapshot& qt) 30 | :mts::QuoteSnapshot (qt), _us(0) 31 | { 32 | #ifdef MTS_LOG_DISABLED 33 | _us = DateTime::nowToUTCMicrosecsSinceEpoch(); 34 | #endif 35 | } 36 | 37 | 38 | PyQuote::~PyQuote() 39 | { 40 | } 41 | 42 | std::string PyQuote::pySymbol() const { 43 | return TO_UTF8_STD_STR(this->symbol()); 44 | } 45 | 46 | std::string PyQuote::pyMtsSymbol() const { 47 | return TO_UTF8_STD_STR(this->mtsSymbol()); 48 | } 49 | 50 | std::string PyQuote::pyExchId() const { 51 | return TO_UTF8_STD_STR(this->exchId()); 52 | } 53 | 54 | PyDateTime PyQuote::pyDateTime() const { 55 | return PyDateTime(this->ticksSinceEpoch()); 56 | } 57 | 58 | std::string PyQuote::toString() const { 59 | return TO_UTF8_STD_STR(this->toJsonString()); 60 | } 61 | 62 | mts::QuoteSnapshot * PyQuote::clone() const { 63 | return nullptr; 64 | } 65 | 66 | qint64 PyQuote::cppRevMicrosecond() const 67 | { 68 | return _us; 69 | } 70 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyQuote.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/Quote.h" 18 | #include "PyDateTime.h" 19 | 20 | class PyQuote:public mts::QuoteSnapshot 21 | { 22 | public: 23 | PyQuote(); 24 | PyQuote(const mts::QuoteSnapshot& qt); 25 | ~PyQuote(); 26 | 27 | std::string pySymbol() const; 28 | std::string pyMtsSymbol() const; 29 | std::string pyExchId() const; 30 | PyDateTime pyDateTime() const; 31 | std::string toString() const; 32 | 33 | virtual mts::QuoteSnapshot* clone() const override; 34 | qint64 cppRevMicrosecond()const; 35 | private: 36 | qint64 _us; 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyTradingAccount.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "PyTradingAccount.h" 17 | 18 | 19 | 20 | PyTradingAccount::PyTradingAccount(const mts::TradingAccount& account) 21 | :mts::TradingAccount(account) 22 | { 23 | } 24 | 25 | 26 | PyTradingAccount::~PyTradingAccount() { 27 | } 28 | 29 | std::string PyTradingAccount::pyId() const { 30 | return TO_UTF8_STD_STR(this->accountId().key()); 31 | } 32 | -------------------------------------------------------------------------------- /code/mts_agent_python/PyTradingAccount.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | class PyTradingAccount:public mts::TradingAccount 20 | { 21 | public: 22 | PyTradingAccount(const mts::TradingAccount& account); 23 | ~PyTradingAccount(); 24 | 25 | std::string pyId() const; 26 | 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /code/mts_agent_python/config/__init__.py: -------------------------------------------------------------------------------- 1 | #import signal 2 | import sys 3 | import os 4 | import time 5 | 6 | from .mts_agent_python import * 7 | from .mts_import import * 8 | 9 | setGlobals(globals()) 10 | 11 | Strategy=genMtsStratgyClass() 12 | -------------------------------------------------------------------------------- /code/mts_agent_python/config/__init__d.py: -------------------------------------------------------------------------------- 1 | #import signal 2 | import sys 3 | import os 4 | 5 | from .mts_agent_python_d import * 6 | from .mts_import import * 7 | 8 | setGlobals(globals()) 9 | 10 | Strategy=genMtsStratgyClass() -------------------------------------------------------------------------------- /code/mts_agent_python/mts_agent_python_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef MTS_AGENT_PYTHON_GLOBAL_H 17 | #define MTS_AGENT_PYTHON_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef MTS_AGENT_PYTHON_LIB 22 | # define MTS_AGENT_PYTHON_API Q_DECL_EXPORT 23 | #elif defined MTS_UNIT_TEST 24 | #define MTS_AGENT_PYTHON_API 25 | #else 26 | # define MTS_AGENT_PYTHON_API Q_DECL_IMPORT 27 | #endif 28 | 29 | #endif // MTS_AGENT_PYTHON_GLOBAL_H 30 | -------------------------------------------------------------------------------- /code/mts_core/AbstractConfigParams.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core/mts_core_api.h" 19 | #include "mts_core/enums.h" 20 | #include "base/MtsLog.h" 21 | #include "ParamsFields.h" 22 | 23 | namespace mts 24 | { 25 | class MTS_CORE_API AbstractConfigParams 26 | { 27 | protected: 28 | AbstractConfigParams(); 29 | virtual ~AbstractConfigParams(); 30 | public: 31 | static QVariantMap expendAllSections(const QVariantMap& params); 32 | 33 | bool load(const QVariantMap & params) ; 34 | EnvironmentMode mode() const; 35 | EnvironmentMode componentMode(MtsComponent) const; 36 | int instanceId() const; 37 | int strategyPosCheck() const; 38 | bool positionPersistenceEnable() const; 39 | 40 | QVariant value(const QString& key, const QVariant& defaultValue=QVariant()) const; 41 | QStringList keys() const; 42 | QVariantMap rawParams() const; 43 | protected: 44 | virtual bool doLoad(const QVariantMap & params); 45 | private: 46 | EnvironmentMode _mode; 47 | int _instanceId; 48 | int _strategyPosCheck; 49 | bool _positionPersistenceEnable; 50 | 51 | QVariantMap _allValues; 52 | }; 53 | 54 | 55 | } -------------------------------------------------------------------------------- /code/mts_core/Account.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "Account.h" 17 | #include "mts_core/InstrumentPropertyDb.h" 18 | 19 | namespace mts 20 | { 21 | 22 | Account::Account() { 23 | } 24 | 25 | Account::Account(const Account & a) 26 | { 27 | } 28 | 29 | 30 | Account::~Account() { 31 | } 32 | 33 | Account * Account::clone() const{ 34 | return new Account(*this); 35 | } 36 | 37 | InstrumentBaseProperty * Account::find ( const QString& symbol ) const{ 38 | auto id = InstrumentPropertyDb::instance ()->findInstrumentId ( symbol ); 39 | if ( id.isNull () ){ 40 | return nullptr; 41 | } 42 | return InstrumentPropertyDb::instance ()->find ( id ); 43 | } 44 | 45 | void Account::registerMetaType() { 46 | qRegisterMetaType("Account"); 47 | qRegisterMetaType("AccountPtr"); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /code/mts_core/Account.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/mts_core_api.h" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "Position.h" 23 | #include "mts_core/InstrumentId.h" 24 | #include "mts_core/InstrumentProperty.h" 25 | 26 | namespace mts 27 | { 28 | class MTS_CORE_API Account 29 | { 30 | public: 31 | Account(); 32 | Account(const Account&); 33 | ~Account(); 34 | 35 | Account* clone() const; 36 | 37 | InstrumentBaseProperty* find ( const QString& symbol) const; 38 | 39 | static void registerMetaType(); 40 | private: 41 | 42 | }; 43 | 44 | typedef QSharedPointer AccountPtr; 45 | 46 | } 47 | Q_DECLARE_METATYPE(mts::AccountPtr); 48 | -------------------------------------------------------------------------------- /code/mts_core/AccountCallback.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/Account.h" 18 | 19 | 20 | namespace mts 21 | { 22 | class AccountCallback 23 | { 24 | public: 25 | virtual void onEnvirInitialized() = 0; 26 | virtual void onInitialized(Account*) = 0; 27 | 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /code/mts_core/Clock.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "Component.h" 19 | #include "base/DateTime.h" 20 | #include "TimerCallback.h" 21 | #include "DateCallback.h" 22 | 23 | namespace mts 24 | { 25 | class MTS_CORE_API Clock:public Component 26 | { 27 | public: 28 | Clock(void); 29 | virtual ~Clock(void); 30 | virtual DateTime now() const = 0; 31 | virtual int currentTradingDay () const= 0; 32 | 33 | int createTimer(int beginTime,int interval, TimerCallback*); //if failed return 0 34 | bool destroyTimer(int id); 35 | 36 | void addDateCallback(DateCallback*); 37 | protected: 38 | virtual QObject* doCreateTimer(int id, qint64 beginTicks, int interval, TimerCallback*) = 0; 39 | virtual bool doDestroyTimer(QObject*) = 0; 40 | void clear(); 41 | void notifyBusinessDateChanged(int newBuseinssDate); 42 | private: 43 | QList _ids; 44 | QList _dateCallbacks; 45 | #ifdef MTS_UNIT_TEST 46 | public: 47 | #endif 48 | qint64 calcBeginUTCTicks(int beginTime, int interval) const; 49 | }; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /code/mts_core/Component.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "Component.h" 17 | 18 | 19 | 20 | Component::Component() 21 | :QObject(),_initialized(false) 22 | { 23 | } 24 | 25 | 26 | Component::~Component() { 27 | } 28 | 29 | bool Component::isInitialized() const { 30 | return _initialized; 31 | } 32 | 33 | void Component::emitInitializeDone() { 34 | this->_initialized = true; 35 | Q_EMIT initializeDone(); 36 | } 37 | 38 | void Component::emitInitializeError(const QString& err) { 39 | this->_initialized = false; 40 | Q_EMIT initializeError(err); 41 | } 42 | -------------------------------------------------------------------------------- /code/mts_core/Component.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core_api.h" 19 | 20 | class MTS_CORE_API Component:public QObject 21 | { 22 | Q_OBJECT 23 | public: 24 | Component(); 25 | virtual ~Component(); 26 | 27 | virtual bool initialize(const QVariantMap& params)=0; 28 | bool isInitialized() const; 29 | 30 | public Q_SLOTS: 31 | void emitInitializeDone(); 32 | void emitInitializeError(const QString& err); 33 | 34 | Q_SIGNALS: 35 | void initializeDone(); 36 | void initializeError(const QString& err); 37 | 38 | private: 39 | bool _initialized; 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /code/mts_core/ContinuousSymbolMgr.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/mts_core_api.h" 18 | #include 19 | #include 20 | #include 21 | #include "mts_core/InstrumentId.h" 22 | 23 | namespace mts 24 | { 25 | class MTS_CORE_API ContinuousSymbolMgr 26 | { 27 | private: 28 | ContinuousSymbolMgr(); 29 | public: 30 | ~ContinuousSymbolMgr(); 31 | static ContinuousSymbolMgr* instance(); 32 | bool init(const QString& configFilePath); 33 | std::string getSymbol(const std::string& mkt, int date) const; 34 | QStringList allMainSymbols (int date) const; 35 | QStringList allContinuousSymbols ( ) const; //return AG888... 36 | QString getSymbolFromContinuous ( const QString& symbol /* AG888*/ , int date ); 37 | private: 38 | typedef std::map DateSymMap; 39 | QMap _mktDateSymMap; 40 | 41 | std::string getSymbol ( const DateSymMap& dateSymMap , int date ) const; 42 | }; 43 | } -------------------------------------------------------------------------------- /code/mts_core/CoreBar.fbs: -------------------------------------------------------------------------------- 1 | // CoreBar schema file 2 | 3 | namespace mts; 4 | 5 | table CoreBar { 6 | endTicksSinceEpoch :long; //end time 7 | openPrice :double; 8 | highPrice :double; 9 | lowPrice :double; 10 | closePrice :double; 11 | volume :long; //TODO check double 12 | turnover :double; //vwap=turnover/volume/volumeMultiple 13 | openInterest :double; 14 | fairPrice :double; //last 15 | midPrice :double; //last 16 | spread :double; //last 17 | bidAskDepth :int; //last 18 | } 19 | 20 | root_type CoreBar; 21 | -------------------------------------------------------------------------------- /code/mts_core/DateCallback.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | 19 | namespace mts 20 | { 21 | class DateCallback 22 | { 23 | public: 24 | virtual ~DateCallback(){} 25 | virtual void onBusinessDateChanged(int businessDate) = 0; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /code/mts_core/EnvironmentFactory.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "base/Library.h" 18 | #include "mts_core/enums.h" 19 | 20 | 21 | namespace mts { 22 | class Environment; 23 | class Clock; 24 | class Feeds; 25 | class Trade; 26 | class MTS_CORE_API EnvironmentFactory 27 | { 28 | public: 29 | static QString getLibraryFileName(const QString& componentName, const QString& mode); 30 | 31 | 32 | EnvironmentFactory(const QString& libraryPath); 33 | ~EnvironmentFactory(void); 34 | 35 | bool loadTo(Environment*, EnvironmentMode); 36 | 37 | private: 38 | const QString _libraryPath; 39 | 40 | private: 41 | Clock* createClockComponent(EnvironmentMode); 42 | Feeds* createFeedsComponent(EnvironmentMode); 43 | Trade* createTradeComponent(EnvironmentMode); 44 | 45 | Library _clockLib; 46 | Library _feedsLib; 47 | Library _tradeLib; 48 | }; 49 | } -------------------------------------------------------------------------------- /code/mts_core/ExchOrderSet.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "ExchOrderSet.h" 17 | #include "mts_core/Order.h" 18 | 19 | namespace mts { 20 | ExchOrderSet::ExchOrderSet() 21 | { 22 | _fillId = 1000; 23 | _exchId = 1000; 24 | } 25 | ExchOrderSet::~ExchOrderSet() 26 | { 27 | 28 | } 29 | 30 | QString ExchOrderSet::genExchId(const InstrumentId& id) const 31 | { 32 | return QString("sim_%1").arg(_exchId++); 33 | } 34 | 35 | QString ExchOrderSet::genFillId(const InstrumentId& id) const 36 | { 37 | return QString("fill_%1").arg(_fillId++); 38 | } 39 | } -------------------------------------------------------------------------------- /code/mts_core/ExchOrderSet.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include "mts_core/InstrumentId.h" 21 | #include "mts_core/OrderSet.h" 22 | 23 | namespace mts{ 24 | class Order; 25 | 26 | class ExchOrderSet:public OrderSet 27 | { 28 | public: 29 | ExchOrderSet(); 30 | virtual ~ExchOrderSet(); 31 | 32 | QString genExchId(const InstrumentId&) const; 33 | QString genFillId(const InstrumentId&) const; 34 | private: 35 | mutable QAtomicInt _fillId; 36 | mutable QAtomicInt _exchId; 37 | }; 38 | } -------------------------------------------------------------------------------- /code/mts_core/Feeds.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "Component.h" 20 | #include "mts_core/InstrumentId.h" 21 | #include "FeedsCallback.h" 22 | #include "DateCallback.h" 23 | 24 | namespace mts 25 | { 26 | class FeedsNotifier; 27 | class MTS_CORE_API FeedsBase :public Component 28 | { 29 | public: 30 | FeedsBase(); 31 | virtual ~FeedsBase(); 32 | virtual int subscribe(const QList&) = 0; 33 | virtual int unsubscribe(const QList&) = 0; 34 | 35 | 36 | virtual int addCallback(FeedsCallback* cb) =0; 37 | virtual int addFrontCallback(FeedsCallback* cb) = 0; //just for simu trade for add the match model 38 | virtual int findCallback(FeedsCallback* cb) = 0; 39 | virtual bool hasCallback(FeedsCallback* cb) = 0; 40 | virtual bool removeCallback(FeedsCallback* cb) =0; 41 | 42 | }; 43 | 44 | class MTS_CORE_API Feeds :public FeedsBase,public DateCallback 45 | { 46 | public: 47 | Feeds(); 48 | virtual ~Feeds(void); 49 | 50 | virtual int addCallback(FeedsCallback* cb) override; 51 | virtual int addFrontCallback(FeedsCallback* cb) override; //just for simu trade for add the match model 52 | virtual int findCallback(FeedsCallback* cb) override; 53 | virtual bool hasCallback(FeedsCallback* cb) override; 54 | virtual bool removeCallback(FeedsCallback* cb) override; 55 | 56 | protected: 57 | virtual void onBusinessDateChanged(int businessDate) override; 58 | void notifyAll(QuotePtr qt); 59 | virtual void notifyAll(CalcBarPtr bar); 60 | void notifyOne(int callbackIdx, CalcBarPtr bar); 61 | int callbacksCount() const; 62 | private: 63 | QList _callbacks; 64 | }; 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /code/mts_core/FeedsCallback.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "Quote.h" 18 | #include "mts_core/CalcBar.h" 19 | #include "DateCallback.h" 20 | 21 | namespace mts 22 | { 23 | class BarFeedsCallback 24 | { 25 | public: 26 | virtual ~BarFeedsCallback() {} 27 | virtual void onBarUpdate(CalcBarPtr) = 0; 28 | }; 29 | 30 | 31 | class FeedsCallback:virtual public DateCallback,public BarFeedsCallback 32 | { 33 | public: 34 | virtual ~FeedsCallback(){} 35 | virtual void onQuoteUpdate(QuotePtr) = 0; 36 | }; 37 | 38 | 39 | class FeedsSnapshotCallback :virtual public DateCallback 40 | { 41 | public: 42 | virtual ~FeedsSnapshotCallback(){} 43 | virtual void onQuoteSnapshotUpdate(QuoteSnapshotPtr) = 0; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /code/mts_core/InstrumentId.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "enums.h" 18 | #include 19 | #include 20 | #include "mts_core_api.h" 21 | 22 | namespace mts 23 | {//暂时还只要symbol与type,因为行情不一定有Exch(郑州和大连商品交易所) 24 | class MTS_CORE_API InstrumentId 25 | { 26 | public: 27 | InstrumentId(); 28 | InstrumentId(const QString& symbol, InstrumentType/*, ExchId*/); 29 | InstrumentId(const QString& symbol, InstrumentType type,ExchId exchId); 30 | InstrumentId(const InstrumentId&, const QString& newSymbol); //use new symbol to gen an new InstrumentId 31 | ~InstrumentId(); 32 | QString symbol;//商品代码 33 | InstrumentType typeId;//商品类别 34 | ExchId exchId;//交易市场 35 | 36 | QString toString() const; 37 | bool fromString(const QString& idStr); 38 | bool isNull() const; 39 | 40 | static QString toProduct(const QString& symbol); 41 | static QString toContinuousSymbol(const QString& symbol); 42 | static bool isContinuousSymbol(const QString& symbol); 43 | 44 | }; 45 | MTS_CORE_API bool operator==(const InstrumentId& e1, const InstrumentId& e2); 46 | MTS_CORE_API uint qHash(const InstrumentId& key, uint seed=0); 47 | } 48 | -------------------------------------------------------------------------------- /code/mts_core/InstrumentObject.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "InstrumentObject.h" 17 | #include "InstrumentPropertyDb.h" 18 | 19 | namespace mts 20 | { 21 | 22 | InstrumentObject::InstrumentObject() { 23 | } 24 | 25 | InstrumentObject::InstrumentObject(const InstrumentId & id) 26 | :_instrumentId(id) 27 | { 28 | } 29 | 30 | 31 | InstrumentObject::~InstrumentObject() { 32 | } 33 | 34 | QString InstrumentObject::symbol() const { 35 | return _instrumentId.symbol; 36 | } 37 | 38 | QString InstrumentObject::mtsSymbol() const { 39 | if (auto* prop = InstrumentPropertyDb::instance()->find(this->_instrumentId)) { 40 | return prop->mtsSymbol(); 41 | } else { 42 | return ""; 43 | } 44 | } 45 | 46 | QString InstrumentObject::exchId() const { 47 | return mts::exchIdName(this->instrumentId().exchId); 48 | } 49 | 50 | 51 | } -------------------------------------------------------------------------------- /code/mts_core/InstrumentObject.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "InstrumentId.h" 18 | #include "mts_core/MethodDefine.h" 19 | 20 | namespace mts 21 | { 22 | class MTS_CORE_API InstrumentObject 23 | { 24 | public: 25 | InstrumentObject(); 26 | InstrumentObject(const InstrumentId&); 27 | virtual ~InstrumentObject(); 28 | 29 | MemberMethodDefine(InstrumentId, instrumentId, setInstrumentId); 30 | public: 31 | QString symbol() const; 32 | QString mtsSymbol() const; 33 | QString exchId() const; 34 | private: 35 | 36 | }; 37 | 38 | } -------------------------------------------------------------------------------- /code/mts_core/InstrumentPropertyDb.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include "InstrumentProperty.h" 21 | 22 | 23 | namespace mts 24 | { 25 | class MTS_CORE_API InstrumentPropertyDb :public QObject 26 | { 27 | Q_OBJECT 28 | public: 29 | InstrumentPropertyDb(); 30 | ~InstrumentPropertyDb(); 31 | static InstrumentPropertyDb* instance(); 32 | 33 | InstrumentId findInstrumentId(const QString& symbol) const; //from exch symbol 34 | bool hasMtsSymbol(const QString& mtsSym); 35 | 36 | bool insert(InstrumentBaseProperty*); //The class will own the pointer,you do not delete it 37 | InstrumentBaseProperty* find(const InstrumentId& id) const; 38 | int size() const; 39 | bool dumpTo(const QString& filePath) const; 40 | bool loadFrom(const QString& filePath); 41 | 42 | 43 | public Q_SLOTS: 44 | QList instrumentIds(int beginDate , int endDate) const; //return all valid contract ids between beginDate and endDate 45 | QList instrumentIds()const; 46 | 47 | private: 48 | InstrumentId findInstrumentIdFromMtsSymbol(const QString& mtsSymbol, bool continuousSymbolRpl = true) const; 49 | void doInsert(InstrumentBaseProperty * prop); 50 | typedef QHash InstrumentPropertySet; 51 | typedef QHash SymPropertySet; 52 | 53 | mutable QMutex _locker; 54 | InstrumentPropertySet _instrumentProperties; 55 | SymPropertySet _symbolProperties; 56 | SymPropertySet _mtsSymbolProperties; //mts format symbol (AByyyy) , 品种大小,年份月份采用四位表示 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /code/mts_core/MethodDefine.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | #define MemberMethodDefine(Type,name,setName) public:\ 20 | const Type& name() const{return _##name;};\ 21 | void setName(const Type& t){_##name=t;}\ 22 | const char* name##FieldName() const {return #name;} \ 23 | private:\ 24 | Type _##name; 25 | 26 | #define MemberCopyMethodDefine(Type,name,setName) public:\ 27 | Type name() const{return _##name;};\ 28 | void setName(const Type& t){_##name=t;}\ 29 | const char* name##FieldName() const {return #name;} \ 30 | void name##ToJson(QJsonObject& jsonObj) const {jsonObj.insert(#name,_##name);} \ 31 | private:\ 32 | Type _##name; 33 | -------------------------------------------------------------------------------- /code/mts_core/Order.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "OrderReport.h" 18 | #include "TradingAccount.h" 19 | 20 | namespace mts { 21 | class MTS_CORE_API Order:public OrderReportNewDone 22 | { 23 | public: 24 | Order(); 25 | Order(const Order&); 26 | virtual ~Order(); 27 | virtual double leftVolume() const; //TODO check double 28 | int status()const; 29 | bool isFinished() const; 30 | 31 | void setStatus(int); 32 | 33 | virtual void processOrderActionNew(OrderActionNew*); 34 | virtual void processOrderReportNewDone(OrderReportNewDone*); 35 | virtual void processOrderReportNewReject(OrderReportNewReject*); 36 | 37 | virtual void processOrderActionCancel(OrderActionCancel*); 38 | virtual void processOrderReportCancelDone(OrderReportCancelDone*); 39 | virtual void processOrderReportCancelReject(OrderReportCancelReject*); 40 | 41 | 42 | virtual void processOrderReportFill(OrderReportFill* fillrpt,OrderReportFill* lastFillrpt); 43 | virtual Order* clone() const override; 44 | virtual QJsonObject& toJson(QJsonObject& jsonObj) const override; 45 | void copyTo(OrderReport*) const; 46 | void copyTo(Order*) const; 47 | void copyTo(OrderActionCancel*) const; 48 | QString statusString() const; 49 | static void registerMetaType(); 50 | 51 | void setLastCancelSinceEpoch(qint64); 52 | qint64 lastCancelSinceEpoch()const; 53 | 54 | void setNotifyToStrategy(bool v); 55 | bool needNotifyToStrategy() const; 56 | private: 57 | bool _notifyToStrategy; 58 | int _status; 59 | qint64 _lastCxlTimestamp; 60 | 61 | }; 62 | 63 | typedef QSharedPointer OrderPtr; 64 | 65 | } 66 | 67 | Q_DECLARE_METATYPE(mts::OrderPtr); 68 | -------------------------------------------------------------------------------- /code/mts_core/OrderFillSet.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "OrderFillSet.h" 17 | 18 | namespace mts 19 | { 20 | OrderFillSet::OrderFillSet() 21 | { 22 | } 23 | 24 | 25 | OrderFillSet::~OrderFillSet() 26 | { 27 | clear(); 28 | } 29 | 30 | QList OrderFillSet::allFills() const 31 | { 32 | return _fillrpts.values(); 33 | } 34 | 35 | QString fillidString(const QString& id, DirectionSide side, ExchId exch) { 36 | return QString("%1@%2@%3").arg(id).arg(side).arg(exch); 37 | } 38 | 39 | OrderReportFill* OrderFillSet::getFill(const QString& fillId, DirectionSide side, ExchId exch) const 40 | { 41 | QString key = fillidString(fillId,side,exch); 42 | auto it = _fillrpts.constFind(key); 43 | if (it != _fillrpts.cend()) { 44 | return it.value(); 45 | } 46 | return nullptr; 47 | } 48 | 49 | void OrderFillSet::updateFill(OrderReportFill* fill) 50 | { 51 | QString key= fillidString(fill->fillId(),fill->directionSide(),fill->instrumentId().exchId); 52 | OrderReportFill* lastFillrpt =_fillrpts[key]; 53 | if (lastFillrpt != nullptr) { 54 | lastFillrpt->setFillAmount(fill->fillAmount()); 55 | lastFillrpt->setFillVolume(fill->fillVolume()); 56 | lastFillrpt->setFillTicksSinceEpoch(fill->fillTicksSinceEpoch()); 57 | } 58 | else { 59 | _fillrpts[key] = new OrderReportFill(*fill); 60 | } 61 | } 62 | 63 | void OrderFillSet::clear() 64 | { 65 | qDeleteAll(_fillrpts); 66 | _fillrpts.clear(); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /code/mts_core/OrderFillSet.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "mts_core/OrderReport.h" 20 | 21 | namespace mts { 22 | class MTS_CORE_API OrderFillSet 23 | { 24 | public: 25 | OrderFillSet(); 26 | ~OrderFillSet(); 27 | QList allFills()const; 28 | OrderReportFill* getFill(const QString& fillId, DirectionSide side, ExchId exch) const; 29 | void updateFill(OrderReportFill*); 30 | void clear(); 31 | private: 32 | QHash _fillrpts; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /code/mts_core/OrderId.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "OrderId.h" 17 | #include "mts_core/Environment.h" 18 | 19 | namespace mts 20 | { 21 | OrderId::OrderId() 22 | { 23 | } 24 | 25 | OrderId::OrderId(const OrderId & id) 26 | :_id(id._id) 27 | { 28 | } 29 | 30 | OrderId::OrderId(const QString & idStr) 31 | :_id(idStr) 32 | { 33 | } 34 | 35 | 36 | OrderId::~OrderId() 37 | { 38 | 39 | } 40 | 41 | bool OrderId::isValid() const { 42 | return !_id.isEmpty(); 43 | } 44 | 45 | bool OrderId::isMtsOrder() const { 46 | return Environment::instance()->trade()->isMtsOrder(_id); 47 | } 48 | 49 | QString OrderId::toString() const { 50 | return _id; 51 | } 52 | 53 | /*bool OrderId::fromString(const QString & idStr) { 54 | _id=Environment::instance()->trade()->parseOrderId(idStr)._id; 55 | return isValid(); 56 | }*/ 57 | 58 | bool OrderId::operator==(const OrderId& id) const { 59 | return _id == id._id; 60 | } 61 | 62 | bool OrderId::operator>(const OrderId& id) const { 63 | return _id > id._id; 64 | } 65 | 66 | bool OrderId::operator<(const OrderId& id) const { 67 | return _id < id._id; 68 | } 69 | 70 | uint OrderId::hashCode() const { 71 | return qHash(_id); 72 | } 73 | 74 | uint qHash(const OrderId &id) { 75 | return id.hashCode(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /code/mts_core/OrderId.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "mts_core/mts_core_api.h" 20 | #include "mts_core/OrderType.h" 21 | 22 | namespace mts 23 | { 24 | 25 | class MTS_CORE_API OrderId 26 | { 27 | public: 28 | OrderId(); 29 | OrderId(const OrderId&); 30 | explicit OrderId(const QString&); //any string 31 | 32 | ~OrderId(); 33 | 34 | bool isValid() const; 35 | bool isMtsOrder() const; 36 | 37 | QString toString() const; 38 | 39 | bool operator==(const OrderId& id) const; 40 | bool operator>(const OrderId& id) const; 41 | bool operator<(const OrderId& id) const; 42 | uint hashCode() const; 43 | private: 44 | QString _id; 45 | }; 46 | MTS_CORE_API uint qHash(const mts::OrderId& id); 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /code/mts_core/OrderSet.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "mts_core/OrderReport.h" 22 | #include "mts_core/StrategyInterface.h" 23 | 24 | namespace mts { 25 | class Trade; 26 | class Order; 27 | 28 | class MTS_CORE_API OrderSet 29 | { 30 | public: 31 | OrderSet(); 32 | virtual ~OrderSet(); 33 | 34 | Order* getOrder(const QString& referentId, bool createIfNotExist = false); 35 | Order* getOrder(const QString& exchId, ExchId exch); 36 | QList allOrders() const; 37 | QList allActiveOrders(const InstrumentId&) const; 38 | void updateOrder(Order*, OrderReportType); 39 | void clear(); 40 | 41 | private: 42 | QHash _orders; 43 | QHash _exchOrders; 44 | QHash > _activeOrders; 45 | }; 46 | 47 | 48 | class MTS_CORE_API OrderSetSingleton :public OrderSet 49 | { 50 | public: 51 | static OrderSet* instance(); 52 | private: 53 | OrderSetSingleton(); 54 | ~OrderSetSingleton(); 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /code/mts_core/OrderType.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "OrderType.h" 17 | #include 18 | #include "base/enum_ext.h" 19 | 20 | 21 | 22 | /* 23 | #define ORDER_TYPE_MODE_ENUM(declare) \ 24 | declare(OT_UNKNOWN,"UNKNOWN","无效报单类型") \ 25 | declare(OT_DIRECT,"direct","直接发单") \ 26 | declare(OT_SMART,"smart","开平仓自转")\ 27 | declare(OT_SMARTER,"smarter","开平自转可拆分") 28 | 29 | enum OrderType { ORDER_TYPE_MODE_ENUM(SELECT_1_AND_COMMA_IN_3) OT_NAX }; 30 | 31 | const char* orderTypeName(OrderType type) { 32 | static const char* names[] = { 33 | ORDER_TYPE_MODE_ENUM(SELECT_2_AND_COMMA_IN_3) 34 | }; 35 | if (type >= 0 && type < ARRAY_SIZE(names)) { 36 | return names[type]; 37 | } 38 | return names[0]; 39 | } 40 | 41 | OrderType orderType(const char* typeName) { 42 | static QHash map; 43 | if (map.isEmpty()) { 44 | ORDER_TYPE_MODE_ENUM(DEFINE_NAME_ENUM_MAP3_KEY_2); 45 | } 46 | return map[typeName]; 47 | } 48 | 49 | const char* orderTypeDescription(OrderType type) { 50 | static const char* names[] = { 51 | ORDER_TYPE_MODE_ENUM(SELECT_3_AND_COMMA_IN_3) 52 | }; 53 | if (type >= 0 && type < ARRAY_SIZE(names)) { 54 | return names[type]; 55 | } else { 56 | return names[0]; 57 | } 58 | } 59 | */ 60 | 61 | enum 62 | { 63 | MAX_INSTANCE_ID = 999, 64 | MAX_STRATEGY_ID = 9, 65 | MAX_ORDER_TYPE = 9 66 | }; 67 | 68 | 69 | bool MTS_CORE_API mts::isInstanceIdValid(int instanceId) { 70 | return instanceId > 0 && instanceId <= MAX_INSTANCE_ID; 71 | } 72 | 73 | bool MTS_CORE_API mts::isStrategyIdValid(int strategyId) { 74 | return strategyId > 0 && strategyId <= MAX_STRATEGY_ID; 75 | } 76 | -------------------------------------------------------------------------------- /code/mts_core/OrderType.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core_api.h" 18 | 19 | #define OT_UNKNOWN 0 20 | #define OT_DIRECT 1 21 | #define OT_NET 2 22 | #define OT_BOX 3 23 | 24 | 25 | 26 | #define OT_LAST OT_BOX 27 | 28 | 29 | namespace mts 30 | { 31 | bool MTS_CORE_API isInstanceIdValid(int instanceId); 32 | bool MTS_CORE_API isStrategyIdValid(int strategyId); 33 | } -------------------------------------------------------------------------------- /code/mts_core/ParamsFields.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | 19 | #define MODE_PARAM_NAME "mode" 20 | #define INSTANCE_ID "instance_id" 21 | #define STRATEGY_POS_CHECK "strategy_pos_check" 22 | #define POS_PERSISTENCE_ENABLE "pos_persistence_enable" 23 | #define MTS_VERSION "mts_version" 24 | #define MTS_OS "mts_os" 25 | 26 | #define LIB_DIR "library_path" 27 | #define CONFIG_DIR "config_dir" 28 | #define DOC_DIR "doc_dir" 29 | #define LOG_FILE "log_file" 30 | #define CONTINUOUS_CONTRACT "continuous_contract" 31 | #define RISK_SETTING "risk_setting" 32 | 33 | #define FEEDS_FRONT "feeds_front" 34 | #define TRADE_FRONT "trade_front" 35 | #define FEEDS_GRADE "feeds_grade" 36 | #define CONTINUOUS_SUBSCRIBED "continuous_subscribed" 37 | #define INDICATOR_FILE "indicator_library" 38 | #define TAG_TRADE_FRONT_PROTOCOL "trade_front_protocol" 39 | #define TAG_FEEDS_FRONT_PROTOCOL "feeds_front_protocol" 40 | 41 | #define MARKET_TRADING_TIME_TYPE "trading_time" /*'24H' or other for CN fut*/ 42 | 43 | #define BROKER "broker" 44 | #define FEEDS_SERVER_NAME "feeds_name" 45 | #define FEEDS_SERVER_TYPE "feeds_type" 46 | #define FEEDS_USER_NAME "feeds_user" 47 | #define FEEDS_BROKER "feeds_broker" 48 | 49 | #define TRADE_SERVER_NAME "trade_name" 50 | #define TRADE_SERVER_TYPE "trade_type" 51 | #define TRADE_USER_NAME "trade_user" 52 | #define TRADE_BROKER "trade_broker" 53 | 54 | 55 | 56 | #define SIMU_MATCH_MODEL "match_model" 57 | #define SIMU_BEING_DATE "clock_begin_date" 58 | #define SIMU_END_DATE "clock_end_date" 59 | #define SIMU_FEEDS_BEGIN_TIME "feeds_begin_time" 60 | -------------------------------------------------------------------------------- /code/mts_core/PositionVolumeInfo.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core_api.h" 19 | 20 | namespace mts { 21 | 22 | class MTS_CORE_API PositionVolumeInfo 23 | { 24 | public: 25 | PositionVolumeInfo(); 26 | ~PositionVolumeInfo(); 27 | 28 | void clear(); 29 | void businessDateChanged(int businessDate); 30 | QString toString() const; 31 | void toJson(QJsonObject& obj)const; 32 | void fromJson(const QJsonObject& obj); 33 | 34 | double open; //TODO check double 35 | double current; //TODO check double 36 | double active; //TODO check double 37 | double close;//平仓数量 //TODO check double 38 | double activeClose; //TODO check double 39 | double closeYesterdayVolume;//上期:平昨仓数量;其它为优先记作平昨仓 //TODO check double 40 | double activeCloseYesterdayVolume; //TODO check double 41 | double fillVolume; //TODO check double 42 | double fillAmount; 43 | double openPnl; 44 | double fillPnl; 45 | 46 | }; 47 | 48 | } -------------------------------------------------------------------------------- /code/mts_core/QuoteSet.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QuoteSet.h" 17 | 18 | namespace mts 19 | { 20 | 21 | QuoteSet::QuoteSet() 22 | { 23 | } 24 | 25 | 26 | QuoteSet::~QuoteSet() 27 | { 28 | } 29 | 30 | QuoteSnapshotPtr QuoteSet::updateQuote(QuotePtr qt) { 31 | QuoteSnapshotPtr& cacheQt = _quotes[qt->instrumentId()]; 32 | if (cacheQt == nullptr) { 33 | cacheQt = QuoteSnapshotPtr(new QuoteSnapshot(*qt)); 34 | } else { 35 | cacheQt->merge(qt.data()); 36 | } 37 | return cacheQt; 38 | } 39 | 40 | QuoteSnapshotPtr QuoteSet::getQuote(const InstrumentId & instrumentId) { 41 | return _quotes[instrumentId]; 42 | } 43 | 44 | int QuoteSet::size() const { 45 | return _quotes.size(); 46 | } 47 | 48 | void QuoteSet::clear() 49 | { 50 | _quotes.clear(); 51 | } 52 | 53 | 54 | QuoteSet * QuoteSetSingleton::instance() { 55 | static QuoteSet* quotes = nullptr; 56 | if (quotes == nullptr) { 57 | quotes = new QuoteSetSingleton; 58 | } 59 | return quotes; 60 | } 61 | 62 | QuoteSetSingleton::QuoteSetSingleton() 63 | :QuoteSet() 64 | { 65 | } 66 | 67 | QuoteSetSingleton::~QuoteSetSingleton() 68 | { 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /code/mts_core/QuoteSet.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "mts_core/InstrumentId.h" 19 | #include "Quote.h" 20 | 21 | namespace mts 22 | { 23 | 24 | class MTS_CORE_API QuoteSet 25 | { 26 | public: 27 | QuoteSet(); 28 | virtual ~QuoteSet(); 29 | 30 | QuoteSnapshotPtr updateQuote(QuotePtr); //return quote snapshot 31 | QuoteSnapshotPtr getQuote(const InstrumentId& instrumentId); 32 | int size() const; 33 | void clear(); 34 | private: 35 | QHash _quotes; 36 | 37 | }; 38 | 39 | 40 | class MTS_CORE_API QuoteSetSingleton :public QuoteSet 41 | { 42 | public: 43 | static QuoteSet* instance(); 44 | private: 45 | QuoteSetSingleton(); 46 | ~QuoteSetSingleton(); 47 | }; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /code/mts_core/StrategyInterface.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include 19 | #include "TimerCallback.h" 20 | #include "TradeCallback.h" 21 | #include "AccountCallback.h" 22 | #include "mts_core/Position.h" 23 | #include "FeedsCallback.h" 24 | 25 | 26 | namespace mts 27 | { 28 | class StrategyInterface:public TimerCallback, public AccountCallback, public FeedsSnapshotCallback, public BarFeedsCallback, public TradeCallback 29 | { 30 | public: 31 | virtual std::string name() const = 0; 32 | virtual std::string strategyPath() const { return std::string(); }; 33 | virtual int strategyId () const = 0; /*一个进程内多个Strategy时用来区分不同Strategy (1-9),最多9个Strategies 在一个进程中*/ 34 | }; 35 | 36 | } -------------------------------------------------------------------------------- /code/mts_core/SysConfigParams.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "AbstractConfigParams.h" 19 | 20 | namespace mts 21 | { 22 | 23 | class MTS_CORE_API SysConfigParams :public AbstractConfigParams 24 | { 25 | protected: 26 | SysConfigParams(); 27 | virtual ~SysConfigParams(); 28 | 29 | virtual bool doLoad(const QVariantMap & params) override; 30 | public: 31 | 32 | QString configDir() const; 33 | QString docDir() const; 34 | QString mtsDir() const; 35 | 36 | QString logFile() const; 37 | QString continuousContractFile() const; 38 | QString instrumentDbFile() const; 39 | QString riskSettingFile() const; 40 | 41 | 42 | QString logDir() const; 43 | private: 44 | QString _configDir; 45 | QString _docDir; 46 | QString _mtsDir; 47 | 48 | QString _logFile; 49 | QString _continuousContractFile; 50 | QString _riskSettingFile; 51 | }; 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /code/mts_core/TimerCallback.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | namespace mts 19 | { 20 | class TimerCallback 21 | { 22 | public: 23 | virtual ~TimerCallback(){} 24 | virtual void onTimeout(int timerId) = 0; 25 | }; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /code/mts_core/Trade.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "Component.h" 19 | #include "base/NotifiableObserver.h" 20 | #include "mts_core/OrderAction.h" 21 | #include "mts_core/OrderReport.h" 22 | #include "mts_core/Order.h" 23 | #include "TradeCallback.h" 24 | 25 | namespace mts 26 | { 27 | 28 | class TradeNotifier; 29 | class MTS_CORE_API TradeBase:public Component 30 | { 31 | public: 32 | TradeBase(); 33 | virtual ~TradeBase(); 34 | virtual int subscribe(const QList&) { return 0; }; 35 | virtual QString createOrderId(int instanceId, int strategyId, int orderType, int directionSide, int priceType, const InstrumentId& instrumentId) = 0; 36 | virtual bool isMtsOrder(const QString& idStr) = 0; 37 | 38 | virtual int addCallback(TradeCallback*)=0; 39 | 40 | virtual bool sendOrderNewAction(OrderActionNew*) = 0; 41 | virtual bool sendOrderCancelAction(OrderActionCancel*) = 0; 42 | 43 | virtual bool sendOrderOtherAction(OrderAction*) = 0; 44 | }; 45 | 46 | 47 | class MTS_CORE_API Trade : public TradeBase 48 | { 49 | Q_OBJECT 50 | public: 51 | Trade(); 52 | virtual ~Trade(); 53 | 54 | virtual int addCallback(TradeCallback*) override; 55 | 56 | protected Q_SLOTS: 57 | void notifyAll(mts::OrderReportNewDone*); 58 | void notifyAll(mts::OrderReportNewReject*); 59 | void notifyAll(mts::OrderReportFill*); 60 | void notifyAll(mts::OrderReportCancelDone*); 61 | void notifyAll(mts::OrderReportCancelReject*); 62 | void notifyAll(mts::Order*); 63 | void notifyAll(mts::Position*); 64 | void notifyAll(mts::TradingAccount*); 65 | private: 66 | QList _callbacks; 67 | 68 | }; 69 | 70 | } 71 | -------------------------------------------------------------------------------- /code/mts_core/TradeCallback.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/OrderReport.h" 18 | #include "mts_core/Order.h" 19 | #include "mts_core/Position.h" 20 | #include "DateCallback.h" 21 | 22 | namespace mts 23 | { 24 | class TradeCallback:virtual public DateCallback 25 | { 26 | public: 27 | virtual ~TradeCallback(){} 28 | virtual void onOrderNewDone(OrderReportNewDone*) = 0; 29 | virtual void onOrderNewReject(OrderReportNewReject*) = 0; 30 | virtual void onOrderFill(OrderReportFill*) = 0; 31 | 32 | virtual void onOrderCancelDone(OrderReportCancelDone*) = 0; 33 | virtual void onOrderCancelReject(OrderReportCancelReject*) = 0; 34 | 35 | 36 | virtual void onOrderOtherReport(OrderReport*) = 0; 37 | 38 | virtual void onOrderUpdate(Order*) = 0; 39 | 40 | virtual void onPositionUpdate(Position*) = 0; 41 | virtual void onTradingAccountUpdate(TradingAccount*) {}; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /code/mts_core/TradingDateMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "TradingDateMgr.h" 17 | #include "TradingDateMgrFromFile.h" 18 | #include "TradingDateMgr24Hour.h" 19 | 20 | 21 | namespace mts 22 | { 23 | 24 | TradingDateMgr* TradingDateMgr::_instance = nullptr; 25 | 26 | bool TradingDateMgr::init(const QString & configDir, bool is24H) { 27 | if (_instance != nullptr) { 28 | return true; 29 | } 30 | if (is24H) { 31 | _instance = new TradingDateMgr24Hour(); 32 | return true; 33 | }else { 34 | TradingDateMgrFromFile* tdm = new TradingDateMgrFromFile(); 35 | if (!tdm->initialize(configDir)) { 36 | delete tdm; 37 | return false; 38 | } 39 | _instance = tdm; 40 | return true; 41 | } 42 | } 43 | 44 | mts::TradingDateMgr* TradingDateMgr::instance() 45 | { 46 | assert(TradingDateMgr::_instance); 47 | return TradingDateMgr::_instance; 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /code/mts_core/TradingDateMgr24Hour.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "mts_core/TradingDateMgr.h" 18 | 19 | namespace mts { 20 | 21 | class TradingDateMgr24Hour : public TradingDateMgr 22 | { 23 | public: 24 | TradingDateMgr24Hour(); 25 | virtual ~TradingDateMgr24Hour(); 26 | 27 | virtual int nextDate(int dt) const override; 28 | virtual int prevDate(int dt) const override; 29 | virtual int forceToDate(int dt) const override; 30 | virtual int tradingDate(const DateTime & realDateTime) const override; 31 | virtual bool isTradingDate(int dt) const override; 32 | virtual bool isHalfTradingDate(int dt) const override; 33 | virtual bool isTradingDateTime(const DateTime & dt, TradingDateTimeCheckMode = TCM_EXACT) const override; 34 | virtual int realDate(int tradingDate, int realTime) const override; 35 | virtual int nextNDate(int dt, int n) const override; 36 | virtual int countTradingDay(int begDt, int endDt) override; 37 | virtual int openTradingTime(int dt) const override; 38 | virtual int closeTradingTime(int dt ) const override; 39 | virtual DateTime nextTime(int futureTime, const DateTime& baseTime) const override; 40 | virtual bool is24Hour() const override { return true; }; 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /code/mts_core/mts_core_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef MTS_CORE_GLOBAL_H 17 | #define MTS_CORE_GLOBAL_H 18 | 19 | #include 20 | 21 | #ifdef MTS_CORE_LIB 22 | # define MTS_CORE_API Q_DECL_EXPORT 23 | #else 24 | # define MTS_CORE_API Q_DECL_IMPORT 25 | #endif 26 | 27 | #endif // MTS_CORE_GLOBAL_H 28 | -------------------------------------------------------------------------------- /code/trade_real_CTP/AbstractAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "AbstractAction.h" 17 | #include "ctp_ext/CTPUtils.h" 18 | #include "base/MtsUtils.h" 19 | 20 | AbstractAction::AbstractAction() 21 | { 22 | } 23 | 24 | 25 | AbstractAction::~AbstractAction() { 26 | } 27 | 28 | int AbstractAction::request(CThostFtdcTraderApi* userApi, int requestId) { 29 | _reqId = requestId; 30 | return doRequest(userApi,requestId); 31 | } 32 | 33 | int AbstractAction::requestId() const { 34 | return _reqId; 35 | } 36 | 37 | 38 | void AbstractAction::emitActionError(CThostFtdcRspInfoField * pRspInfo, OwnerLevel ol) { 39 | if (pRspInfo == nullptr) { 40 | Q_EMIT actionError(-1, "Unknown Error",ol); 41 | } else { 42 | Q_EMIT actionError(pRspInfo->ErrorID, MtsUtils::toUtf8(pRspInfo->ErrorMsg), ol); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /code/trade_real_CTP/AbstractAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #ifndef ABSTRACTACTION_H 17 | #define ABSTRACTACTION_H 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef _WIN32 27 | #include "../../api/win64/CTP/ThostFtdcTraderApi.h" 28 | #else 29 | #include "../../api/linux64/CTP/ThostFtdcTraderApi.h" 30 | #include 31 | #endif 32 | #include "base/MtsLog.h" 33 | #include "mts_core/const.h" 34 | 35 | 36 | 37 | 38 | /*static void asyncQueueCallback(uv_async_t* handle) { 39 | AsyncActiveQueue* queue = (AsyncActiveQueue*)(handle->data); 40 | queue->processAllData(); 41 | }*/ 42 | 43 | class AbstractAction:public QObject, public CThostFtdcTraderSpi//,private AsyncActiveQueue > 44 | { 45 | Q_OBJECT 46 | public: 47 | AbstractAction(); 48 | virtual ~AbstractAction(); 49 | 50 | int request(CThostFtdcTraderApi*,int requestId); 51 | int requestId() const; 52 | 53 | Q_SIGNALS: 54 | void actionError(int errorId, const QString& errorMsg, OwnerLevel); 55 | 56 | protected Q_SLOTS: 57 | virtual void onProcessResult(int actionId, const QByteArray& data) = 0; 58 | 59 | protected: 60 | virtual int doRequest(CThostFtdcTraderApi* tradeApi,int requestId) = 0; 61 | void emitActionError(CThostFtdcRspInfoField* pRspInfo, OwnerLevel); 62 | private: 63 | int _reqId; 64 | 65 | }; 66 | 67 | #endif // ABSTRACTACTION_H 68 | -------------------------------------------------------------------------------- /code/trade_real_CTP/CTPCancelOrderField.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "CTPCancelOrderField.h" 17 | 18 | 19 | 20 | CTPCancelOrderField::CTPCancelOrderField(const QString& brokerId, const QString& investorId, const QString& userId) 21 | :CTPCommonField(brokerId, investorId, userId) 22 | { 23 | this->ActionFlag = THOST_FTDC_AF_Delete; 24 | 25 | } 26 | 27 | 28 | CTPCancelOrderField::~CTPCancelOrderField() { 29 | } 30 | 31 | void CTPCancelOrderField::initFromOrder(const CThostFtdcOrderField & order) { 32 | this->setInstrumentID(order.InstrumentID); //必填 33 | this->setThostLevelId(order.FrontID, order.SessionID, order.OrderRef); 34 | if (strlen(order.OrderSysID) > 0) { 35 | this->setExchangeLevelId(order.ExchangeID, order.OrderSysID); 36 | } 37 | } 38 | 39 | 40 | 41 | 42 | void CTPCancelOrderField::setExchangeLevelId(const QString & exchangeId, const QString & orderSysId) { 43 | strcpy(this->ExchangeID, qPrintable(exchangeId)); 44 | strcpy(this->OrderSysID, qPrintable(orderSysId)); 45 | 46 | } 47 | 48 | void CTPCancelOrderField::setThostLevelId(int frontId, int sessionId, const QString & orderRef) { 49 | this->FrontID = frontId; // 指向委托单的FrontID; 50 | this->SessionID = sessionId; // 指向委托单的SessionID; 51 | this->setOrderRef(orderRef); //必填 52 | } 53 | -------------------------------------------------------------------------------- /code/trade_real_CTP/CTPCancelOrderField.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "ctp_ext/CTPCommonField.h" 18 | #include "mts_core/const.h" 19 | 20 | class CTPCancelOrderField:public CTPCommonField 21 | { 22 | public: 23 | CTPCancelOrderField(const QString& brokerId, const QString& investorId, const QString& userId); 24 | virtual ~CTPCancelOrderField(); 25 | 26 | void initFromOrder(const CThostFtdcOrderField& activeOrder); 27 | 28 | private: 29 | void setExchangeLevelId(const QString& exchangeId, const QString& orderSysId); 30 | void setThostLevelId(int frontId, int sessionId, const QString& orderRef); 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /code/trade_real_CTP/CTPInputOrderField.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "ctp_ext/CTPCommonField.h" 19 | #include "mts_core/const.h" 20 | #include "mts_core/enums.h" 21 | 22 | class CTPInputOrderField :public CTPCommonField 23 | { 24 | public: 25 | CTPInputOrderField(const QString& brokerId, const QString& investorId, const QString& userId); 26 | ~CTPInputOrderField(); 27 | 28 | void setLimitPrice(double price); //price=0 means market order 29 | void setDirection(mts::DirectionSide); 30 | void setCombOffsetFlag(int offsetFlag); 31 | virtual QJsonObject toJson() const; 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /code/trade_real_CTP/OrderIdImplCtp.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | namespace mts 20 | { 21 | 22 | class OrderIdImplCtp 23 | { 24 | public: 25 | OrderIdImplCtp(); 26 | OrderIdImplCtp(int frontId, int sessionId, int instanceId, int strategyId, int orderType,int index); 27 | OrderIdImplCtp( int frontId , int sessionId , qint64); 28 | OrderIdImplCtp(const QString& id); 29 | ~OrderIdImplCtp(); 30 | 31 | int orderType() const; 32 | int instanceId() const; 33 | int strategyId() const; 34 | bool isMtsOrder() const; 35 | QString toString() const; 36 | bool fromString(const QString & idStr); 37 | QString ctpOrderReferenceId() const; 38 | QString id()const; 39 | private: 40 | int _frontId; 41 | int _sessionId; 42 | qint64 _refId; 43 | 44 | 45 | 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryFillAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QueryFillAction.h" 17 | 18 | 19 | static const int CThostFtdcTradeFieldId = qRegisterMetaType("CThostFtdcTradeField"); 20 | static const int CThostFtdcTradeFieldListId = qRegisterMetaType>("QList"); 21 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryFillAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "QueryAction.h" 18 | 19 | class QueryFillAction :public QueryAction 20 | { 21 | Q_OBJECT 22 | public: 23 | QueryFillAction(const CThostFtdcQryTradeField& qryTradeField) 24 | :QueryAction(qryTradeField, &CThostFtdcTraderApi::ReqQryTrade) 25 | { 26 | } 27 | virtual ~QueryFillAction() {} 28 | 29 | Q_SIGNALS: 30 | void responseQueryFills(const QList& fills); 31 | 32 | public: 33 | virtual void OnRspQryTrade(CThostFtdcTradeField *pTrade, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 34 | this->onResponse(pTrade, pRspInfo, bIsLast); 35 | } 36 | protected: 37 | virtual void emitResponseQueryResults(const QList& results) override { 38 | Q_EMIT responseQueryFills(results); 39 | } 40 | 41 | }; 42 | 43 | Q_DECLARE_METATYPE(CThostFtdcTradeField); 44 | Q_DECLARE_METATYPE(QList); 45 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryInstrumentAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QueryInstrumentAction.h" 17 | 18 | 19 | static const int CThostFtdcInstrumentFieldId = qRegisterMetaType("CThostFtdcInstrumentField"); 20 | static const int CThostFtdcInstrumentFieldListId = qRegisterMetaType>("QList"); -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryInstrumentAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "QueryAction.h" 18 | 19 | class QueryInstrumentAction:public QueryAction 20 | { 21 | Q_OBJECT 22 | public: 23 | QueryInstrumentAction(const CThostFtdcQryInstrumentField& qryField) 24 | :QueryAction(qryField,&CThostFtdcTraderApi::ReqQryInstrument) 25 | { 26 | } 27 | 28 | virtual ~QueryInstrumentAction() {} 29 | Q_SIGNALS: 30 | void responseQueryInstruments(const QList&); 31 | public: 32 | virtual void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 33 | this->onResponse(pInstrument, pRspInfo, bIsLast); 34 | } 35 | 36 | protected: 37 | virtual void emitResponseQueryResults(const QList& results) override { 38 | Q_EMIT responseQueryInstruments(results); 39 | } 40 | }; 41 | 42 | Q_DECLARE_METATYPE(CThostFtdcInstrumentField); 43 | Q_DECLARE_METATYPE(QList); -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryOrderAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QueryOrderAction.h" 17 | 18 | static const int CThostFtdcOrderFieldId = qRegisterMetaType("CThostFtdcOrderField"); 19 | static const int CThostFtdcOrderFieldListId = qRegisterMetaType>("QList"); 20 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryOrderAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "QueryAction.h" 19 | 20 | class QueryOrderAction :public QueryAction 21 | { 22 | Q_OBJECT 23 | public: 24 | QueryOrderAction(const CThostFtdcQryOrderField & field) 25 | :QueryAction(field, &CThostFtdcTraderApi::ReqQryOrder) 26 | { 27 | } 28 | virtual ~QueryOrderAction() {} 29 | 30 | Q_SIGNALS: 31 | void responseQueryOrders(const QList& orders); 32 | 33 | public: 34 | virtual void OnRspQryOrder(CThostFtdcOrderField *pOrder, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 35 | this->onResponse(pOrder, pRspInfo, bIsLast); 36 | } 37 | protected: 38 | virtual void emitResponseQueryResults(const QList& results) override { 39 | Q_EMIT responseQueryOrders(results); 40 | } 41 | }; 42 | 43 | Q_DECLARE_METATYPE(CThostFtdcOrderField); 44 | Q_DECLARE_METATYPE(QList); -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryPositionAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QueryPositionAction.h" 17 | 18 | 19 | static const int CThostFtdcInvestorPositionFieldId = qRegisterMetaType("CThostFtdcInvestorPositionField"); 20 | static const int CThostFtdcInvestorPositionFieldListId = qRegisterMetaType>("QList"); 21 | 22 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryPositionAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | #include "QueryAction.h" 19 | 20 | #include 21 | 22 | class QueryPositionAction :public QueryAction 23 | { 24 | Q_OBJECT 25 | public: 26 | QueryPositionAction(const CThostFtdcQryInvestorPositionField& qryPositionField) 27 | :QueryAction(qryPositionField, &CThostFtdcTraderApi::ReqQryInvestorPosition) 28 | { 29 | } 30 | virtual ~QueryPositionAction() {} 31 | Q_SIGNALS: 32 | void responseQueryPositions(const QList& positions); 33 | 34 | public: 35 | virtual void OnRspQryInvestorPosition(CThostFtdcInvestorPositionField *pInvestorPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 36 | this->onResponse(pInvestorPosition, pRspInfo, bIsLast); 37 | } 38 | protected: 39 | virtual void emitResponseQueryResults(const QList& results) override { 40 | Q_EMIT responseQueryPositions(results); 41 | } 42 | }; 43 | 44 | Q_DECLARE_METATYPE(CThostFtdcInvestorPositionField); 45 | Q_DECLARE_METATYPE(QList); 46 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QuerySettlementInfoAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QuerySettlementInfoAction.h" 17 | 18 | 19 | static const int CThostFtdcSettlementInfoConfirmFieldId = qRegisterMetaType("CThostFtdcSettlementInfoConfirmField"); 20 | static const int CThostFtdcSettlementInfoConfirmFieldListId = qRegisterMetaType >("QList"); 21 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QuerySettlementInfoAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "QueryAction.h" 18 | 19 | class QuerySettlementInfoAction:public QueryAction 20 | { 21 | Q_OBJECT 22 | public: 23 | QuerySettlementInfoAction(const CThostFtdcSettlementInfoConfirmField& qrySettlementField) 24 | :QueryAction(qrySettlementField, &CThostFtdcTraderApi::ReqSettlementInfoConfirm) 25 | { 26 | } 27 | virtual ~QuerySettlementInfoAction() {} 28 | 29 | Q_SIGNALS: 30 | void responseQuerySettlementInfo(const QList& settlementInfos); 31 | 32 | public : 33 | virtual void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfo, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 34 | this->onResponse(pSettlementInfo, pRspInfo, bIsLast); 35 | } 36 | protected: 37 | virtual void emitResponseQueryResults(const QList& results) override { 38 | Q_EMIT responseQuerySettlementInfo(results); 39 | } 40 | 41 | }; 42 | 43 | 44 | Q_DECLARE_METATYPE(CThostFtdcSettlementInfoConfirmField); 45 | Q_DECLARE_METATYPE(QList); 46 | 47 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryTradingAccountAction.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "QueryTradingAccountAction.h" 17 | 18 | static const int CThostFtdcTradingAccountFieldId = qRegisterMetaType("CThostFtdcTradingAccountField"); 19 | static const int CThostFtdcTradingAccountFieldListId = qRegisterMetaType>("QList"); 20 | -------------------------------------------------------------------------------- /code/trade_real_CTP/QueryTradingAccountAction.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "QueryAction.h" 19 | 20 | class QueryTradingAccountAction :public QueryAction 21 | { 22 | Q_OBJECT 23 | public: 24 | QueryTradingAccountAction(const CThostFtdcQryTradingAccountField& qryTradingAccountField) 25 | :QueryAction(qryTradingAccountField, &CThostFtdcTraderApi::ReqQryTradingAccount) 26 | { 27 | } 28 | virtual ~QueryTradingAccountAction() {} 29 | 30 | Q_SIGNALS: 31 | void responseQueryTradingAccount(const QList& settlementInfos); 32 | 33 | public: 34 | virtual void OnRspQryTradingAccount(CThostFtdcTradingAccountField *pTradingAccount, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) override { 35 | this->onResponse(pTradingAccount, pRspInfo, bIsLast); 36 | } 37 | protected: 38 | virtual void emitResponseQueryResults(const QList& results) override { 39 | Q_EMIT responseQueryTradingAccount(results); 40 | } 41 | 42 | }; 43 | 44 | 45 | Q_DECLARE_METATYPE(CThostFtdcTradingAccountField); 46 | Q_DECLARE_METATYPE(QList); 47 | 48 | -------------------------------------------------------------------------------- /code/trade_real_CTP/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtsquant/MTS/ab7ecab0f88c844289b5c81e5627326fe36e682f/code/trade_real_CTP/README.md -------------------------------------------------------------------------------- /code/trade_real_CTP/TradeEvent.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include "base/Event.h" 18 | #include "base/EventType.h" 19 | #include "mts_core/Trade.h" 20 | 21 | 22 | 23 | typedef DataEvent OrderNewDoneEvent; 24 | 25 | typedef DataEvent OrderNewRejectEvent; 26 | typedef DataEvent OrderFillEvent; 27 | typedef DataEvent OrderCancelDoneEvent; 28 | typedef DataEvent OrderCancelRejectEvent; 29 | typedef DataEvent OrderEvent; 30 | typedef DataEvent PositionEvent; 31 | 32 | -------------------------------------------------------------------------------- /code/trade_real_CTP/TradeReal.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | 18 | #include "mts_core/Trade.h" 19 | 20 | #include "base/EventDispatcher.h" 21 | 22 | class CTPOrderMgr; 23 | namespace mts 24 | { 25 | class TradeReal :public Trade//,public EventCallback 26 | { 27 | public: 28 | TradeReal(); 29 | virtual ~TradeReal(); 30 | 31 | virtual bool initialize(const QVariantMap & params) override; 32 | 33 | virtual bool sendOrderNewAction(OrderActionNew*) override; 34 | virtual bool sendOrderCancelAction(OrderActionCancel*) override; 35 | virtual bool sendOrderOtherAction(OrderAction*) override; 36 | 37 | virtual QString createOrderId(int instanceId, int strategyId, int orderType, int directionSide, int priceType, const InstrumentId& instrumentId) override; 38 | virtual bool isMtsOrder(const QString&) override; 39 | 40 | private: 41 | CTPOrderMgr* _tradeOrderClient; 42 | 43 | }; 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /code/trade_real_CTP/mts_trade_real.cpp: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #include "trade_real_api.h" 17 | #include "TradeReal.h" 18 | 19 | extern "C" { 20 | MTS_TRADE_REAL_API mts::Trade* createTrade() { 21 | return new mts::TradeReal(); 22 | } 23 | 24 | MTS_TRADE_REAL_API void releaseTrade(mts::Trade* trade) { 25 | delete trade; 26 | } 27 | } -------------------------------------------------------------------------------- /code/trade_real_CTP/trade_real_api.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************************** 3 | * Copyright [2017-2019] [MTSQuant] 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *****************************************************************************/ 16 | #pragma once 17 | #include 18 | 19 | #ifdef MTS_TRADE_REAL_LIB 20 | # define MTS_TRADE_REAL_API Q_DECL_EXPORT 21 | #else 22 | # define MTS_TRADE_REAL_API Q_DECL_IMPORT 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /config/dc_exchs.json: -------------------------------------------------------------------------------- 1 | { 2 | "BN":"Binance", 3 | "BT":"Bittrex", 4 | "BB":"Bibox", 5 | "CS":"Coinsuper", 6 | "OB":"OOOBTC", 7 | "BS":"Bitstamp", 8 | "BR":"BitFlyer", 9 | "SS":"Sistemkoin", 10 | "IX":"IDAX", 11 | "FB":"Fatbtc", 12 | "LA":"LATOKEN", 13 | "HB":"Huobi", 14 | "HT":"Hitbtc", 15 | "KK":"Kraken", 16 | "UB":"Upbit", 17 | "OE":"OEX", 18 | "UE":"UEX", 19 | "BK":"Bitbank", 20 | "BM":"BitMart", 21 | "CX":"C2CX", 22 | "PO":"Poloniex", 23 | "BX":"BitMEX", 24 | "OK":"OKEX", 25 | "GA":"Gate", 26 | "BC":"BCEX", 27 | "CB":"CoinbasePro", 28 | "BH":"Bithumb", 29 | "CE":"CoinBene", 30 | "CT":"CoinTiger", 31 | "ID":"IDCM", 32 | "EX":"EXMO", 33 | "BY":"BitBay", 34 | "CRP":"Cryptopia", 35 | "BF":"Bitfnex", 36 | "ZB":"ZB.COM", 37 | "AB":"Anybits", 38 | "RB":"RightBTC", 39 | "CR":"Cryptonex", 40 | "CK":"CoinsBank", 41 | "ER":"Extrates", 42 | "CG":"CoinEgg", 43 | "LC":"Livecoin", 44 | "IC":"InfinityCoin", 45 | "CRB":"Crytobridge", 46 | "FC":"FCoin", 47 | "BZ":"Bit-z", 48 | "DF":"DigiFinex", 49 | "SI":"Simex", 50 | "AC":"Allcoin", 51 | "YB":"YoBit", 52 | "KR":"Kryptono", 53 | "GE":"Gemini", 54 | "DR":"DragonEX", 55 | "B2":"B2BX", 56 | "ACX":"ACX" 57 | } -------------------------------------------------------------------------------- /config/risk_setting.json: -------------------------------------------------------------------------------- 1 | { 2 | "*":{ 3 | "order_size_limit_open": 1000, 4 | "order_size_limit_close": 1000, 5 | "order_amount_limit_open": 100000, 6 | "order_amount_limit_close": 10000000, 7 | "pos_long_soft_limit":3500, 8 | "pos_long_hard_limit":4000, 9 | "pos_short_soft_limit":3500, 10 | "pos_short_hard_limit":4000, 11 | "account_margin_soft_limit_rate":80.0, 12 | "account_margin_hard_limit_rate":100.0 13 | }, 14 | "ag":{ 15 | "order_size_limit_open": 1000, 16 | "order_size_limit_close": 1000, 17 | "order_amount_limit_open": 100000, 18 | "order_amount_limit_close": 10000000, 19 | "pos_long_soft_limit":150, 20 | "pos_long_hard_limit":200, 21 | "pos_short_soft_limit":150, 22 | "pos_short_hard_limit":200 23 | }, 24 | "ag1801":{ 25 | "order_size_limit_open": 100, 26 | "order_size_limit_close": 1000, 27 | "order_amount_limit_open": 100000, 28 | "order_amount_limit_close": 10000000, 29 | "pos_long_soft_limit":150, 30 | "pos_long_hard_limit":200, 31 | "pos_short_soft_limit":150, 32 | "pos_short_hard_limit":200 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /config/trading_hour.cfg: -------------------------------------------------------------------------------- 1 | exchg=DCE,CZCE,SHFE|session=DS|trdtime=09:00:00-10:15:00,10:30:00-11:30:00,13:30:00-15:00:00 2 | market=IF,IH,IC|session=DS|trdtime=09:30:00-11:30:00,13:00:00-15:00:00 3 | market=T,TF|session=DS|trdtime=09:15:00-11:30:00,13:00:00-15:15:00 4 | exchg=DCE|market=A,B,I,J,JM,M,P,Y|session=NS|begdate=20150101|enddate=20150510|trdtime=02:30:00 5 | exchg=DCE|market=A,B,I,J,JM,M,P,Y|session=NS|begdate=20150511|trdtime=21:00:00-23:30:00 6 | exchg=CZCE|market=CF,FG,MA,OI,RM,SR,TA,ZC,CY|session=NS|begdate=20150901|trdtime=21:00:00-23:30:00 7 | exchg=SHFE|market=AG,AU|session=NS|begdate=20150901|trdtime=21:00:00-02:30:00 8 | exchg=SHFE|market=AL,CU,NI,PB,SN,ZN|session=NS|begdate=20150901|trdtime=21:00:00-01:00:00 9 | exchg=SHFE|market=BU,HC,RB|session=NS|begdate=20150901|enddate=20160502|trdtime=21:00:00-01:00:00 10 | exchg=SHFE|market=BU,HC,RB|session=NS|begdate=20160503|trdtime=21:00:00-23:00:00 11 | exchg=SHFE|market=RU|session=NS|begdate=20150901|trdtime=21:00:00-23:00:00 12 | -------------------------------------------------------------------------------- /doc/mts-setup.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # MTS 安装手册 4 | 5 | MTS 提供多个系统平台版本,以满足不同用户的需要 6 | 7 | ## Windows 版本 8 | 9 | ### 系统需求 10 | 1. 64 位 windows (7 SP1 ,8,10) 11 | 1. Microsoft Visual Studio 2015 x64 运行时 12 | 13 | ### 安装步骤 14 | 1. 安装 Anaconda2 x64 15 | 请注意更改默认安装路径到 `C:\Anaconda2`。 16 | 如果系统已经安装有别的版本的python 2(必须是64位版本),可以使用mklink 建立符号连接到 C:\Anaconda2 17 | 1. 安装MTS 18 | 当前版本暂时不可以选择安装路径,自动安装到系统C盘。 19 | 20 | ### MTS说明 21 | 安装MTS后,会在系统中产生: 22 | 1. MTS python 库`(C:\Anaconda2\lib\MTS)`,供MTS python 策略调用。 23 | 1. MTS 可执行组件Cindy和Julia(`C:\MTS`),分别提供实盘模拟盘监控以及策略研发环境。 24 | 25 | *** 26 | 27 | ## linux 版本 28 | 29 | ### 敬请期待 30 | 31 | *** 32 | 33 | ## docker 版本 34 | 35 | ### 系统需求 36 | 1. 64 位Ubuntu 系统 37 | 2. docker ce 环境 38 | 39 | ### 安装步骤 40 | 1. 拉取镜像 41 | ```bash 42 | sudo docker pull registry.cn-hangzhou.aliyuncs.com/mts/mts:20180314 43 | ``` 44 | 2. 运行测试 45 | ```bash 46 | sudo docker run --rm registry.cn-hangzhou.aliyuncs.com/mts/mts:20180314 47 | ``` 48 | 此时屏幕上将出现不断滚动的行情更新信息,表示工作正常 49 | 50 | ### 运行方式 51 | 1. 运行当前目录下的策略脚本 52 | ```bash 53 | #假设运行当前目录下的tactic1.py策略脚本 54 | sudo docker run -it --rm -v "$PWD":/root/dev/MTS/workspace/tactic1 mts:20180314 python /root/dev/MTS/workspace/tactic1/tactic1.py 55 | ``` 56 | *** 57 | 58 | ## 在线 Web 版本 59 | 60 | ### 敬请期待 61 | 62 | 63 | 64 | --------------------------------------------------------------------------------