├── .gitignore ├── CtpApi ├── CtpAny.cs ├── CtpApi.csproj ├── CtpDataType.cs ├── CtpDelegate.cs ├── CtpErrorMsg.cs ├── CtpErrorType.cs ├── CtpHelper.cs ├── CtpMdApi.cs ├── CtpMdNative.cs ├── CtpMdSpi.cs ├── CtpMessageType.cs ├── CtpRequest.cs ├── CtpResponse.cs ├── CtpResumeType.cs ├── CtpSpi.cs ├── CtpStartInfo.cs ├── CtpTraderApi.cs ├── CtpTraderNative.cs ├── CtpTraderSpi.cs ├── ICtpRequestHandler.cs ├── ICtpResponseHandler.cs └── Properties │ └── AssemblyInfo.cs ├── Ctp_C ├── .gitignore ├── CtpseSfit_C │ ├── CtpseSfit_C.vcxproj │ ├── CtpseSfit_C.vcxproj.filters │ ├── ctp_md.cpp │ ├── ctp_trader.cpp │ ├── data_collect.cpp │ ├── dllmain.cpp │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── Ctpse_C.sln ├── Readme.md └── external-bin │ └── ctpse │ ├── DataCollect.h │ ├── TfseMdApi.h │ ├── TfseTraderApi.h │ ├── ThostFtdcMdApi.h │ ├── ThostFtdcTraderApi.h │ ├── ThostFtdcUserApiDataType.h │ ├── ThostFtdcUserApiStruct.h │ ├── error.dtd │ └── error.xml ├── LICENSE ├── OpenQuantCompatibility ├── Helper.cs ├── OpenQuantCompatibility.csproj └── Properties │ └── AssemblyInfo.cs ├── QuantBox.Ctpse ├── Properties │ └── AssemblyInfo.cs ├── QuantBox.Ctpse.csproj ├── QuantBoxCtpse.cs ├── app.config └── packages.config ├── QuantBox ├── AccountPosition.cs ├── ChainDataSimulation.cs ├── ConnectManager.cs ├── ConnectionInfo.cs ├── Convertor.cs ├── Data.Compression │ ├── BarCompressor.cs │ ├── BarDataEnumerator.cs │ ├── CompressedBarEventArgs.cs │ ├── DataEntry.cs │ ├── DataEntryEnumerator.cs │ ├── DataSeriesEnumerator.cs │ ├── PriceSizeItem.cs │ ├── TickDataEnumerator.cs │ └── TimeBarCompressor.cs ├── DataEventMapper.cs ├── DataManagerExtensions.cs ├── DatabaseOrderServer.cs ├── DatabasePortfolioServer.cs ├── DataflowHelper.cs ├── DealProcessor.cs ├── Design │ ├── ApiSettingsConverter.cs │ ├── ApiTypeSelectorEditor.cs │ ├── ComboBoxItemTypeConverter.cs │ ├── DisplayNamePropertyDescriptor.cs │ ├── FolderBrowser2.cs │ ├── FolderNameEditor2.cs │ ├── InstrumentProviderConverter.cs │ ├── ProviderTypeConverter.cs │ ├── RPropertyGrid.Designer.cs │ ├── RPropertyGrid.ReadOnlyConverter.cs │ ├── RPropertyGrid.ReadOnlyPropertyDescriptor.cs │ ├── RPropertyGrid.ReadOnlyWrapper.cs │ ├── RPropertyGrid.cs │ ├── ServerInfoConverter.cs │ ├── ServerSelectorConverter.cs │ ├── TimeSpanEditor.cs │ ├── UserInfoConverter.cs │ ├── UserSelectorConverter.cs │ ├── XApiSettingsDialog.Designer.cs │ ├── XApiSettingsDialog.cs │ ├── XApiSettingsDialog.resx │ └── XApiSettingsTypeEditor.cs ├── DualPosition.cs ├── EventPipe.cs ├── ExecutionCommandSerializer.cs ├── ExecutionReportSerializer.cs ├── FrameworkExtensions.cs ├── Helper.cs ├── ICustomStatisticsType.cs ├── IdGenerator.cs ├── IgnoreSerializerContractResolver.cs ├── InstTradingRules.cs ├── JsonOrderServer.cs ├── MarketDataClient.cs ├── NoTypeConverterJsonConverter.cs ├── OnAutoConnect.cs ├── OnAutoDisconnect.cs ├── OnClientConnected.cs ├── OnClientDisconnected.cs ├── OptionChainData.cs ├── OptionChainDataType.cs ├── OptionStrategy.cs ├── OrderAdjust.cs ├── OrderExtensions.cs ├── OrderMap.cs ├── OrderOffsetFlag.cs ├── OrderProxy │ ├── EmptyDataProvider.cs │ ├── OrderAgent.cs │ ├── OrderAgentInfo.cs │ └── OrderProcessor.cs ├── OrderRecord.cs ├── OrderRegister.cs ├── PortfolioSerializer.cs ├── PositionManager.cs ├── PositionRecord.cs ├── PriceHelper.cs ├── Properties │ └── AssemblyInfo.cs ├── QBCommissionProvider.cs ├── QBExecutionSimulator.cs ├── QBHelper.cs ├── QBOptimizeBarFilter.cs ├── QBTimeBarFactoryItem.cs ├── QuantBox.csproj ├── QuantBoxConst.cs ├── QuantBoxOrderInfo.cs ├── QuoteExtensions.cs ├── ServerInfo.cs ├── StackTraceHelper.cs ├── StatisticsManagerExtensions.cs ├── StopExtensions.cs ├── StopSerializer.cs ├── StopStrategy.cs ├── StrategyExtensions.cs ├── StrategyServer.cs ├── SubscribeManager.cs ├── TickFilter.cs ├── TickSizeSlippageProvider.cs ├── TimeRange.cs ├── TimeSeriesExtensions.cs ├── TimedTask.cs ├── TraderClient.cs ├── TradesCost.cs ├── TradingCalendar.cs ├── TradingTimeRangeSelector.cs ├── UserInfo.cs ├── XApiClient.cs ├── XApiEventType.cs ├── XEventType.cs ├── XProvider.EventEmitter.cs ├── XProvider.cs ├── XProviderEventType.cs ├── XProviderSettings.cs ├── app.config └── packages.config ├── README.md ├── SfitCtpseQuote ├── CtpMdClient.cs ├── CtpQuote.cs ├── Properties │ └── AssemblyInfo.cs ├── SfitCtpseQuote.csproj ├── packages.config ├── sfit_ctpse_x64.dll ├── thostmduserapi_se.dll └── thosttraderapi_se.dll ├── SfitCtpseTrader ├── CtpConvert.cs ├── CtpDealProcessor.cs ├── CtpQueryManager.cs ├── CtpTradeClient.cs ├── CtpTrader.cs ├── OrderMap.cs ├── Properties │ └── AssemblyInfo.cs ├── SfitCtpseTrader.csproj ├── StatusPublisher.cs ├── packages.config ├── sfit_ctpse_x64.dll ├── thostmduserapi_se.dll └── thosttraderapi_se.dll ├── TALib ├── Properties │ └── AssemblyInfo.cs ├── TA4OpenQuant.cs ├── TACore.cs ├── TAFunc │ ├── TA_Acos.cs │ ├── TA_Ad.cs │ ├── TA_AdOsc.cs │ ├── TA_Add.cs │ ├── TA_Adx.cs │ ├── TA_Adxr.cs │ ├── TA_Apo.cs │ ├── TA_Aroon.cs │ ├── TA_AroonOsc.cs │ ├── TA_Asin.cs │ ├── TA_Atan.cs │ ├── TA_Atr.cs │ ├── TA_AvgPrice.cs │ ├── TA_Bbands.cs │ ├── TA_Beta.cs │ ├── TA_Bop.cs │ ├── TA_Cci.cs │ ├── TA_Cdl2Crows.cs │ ├── TA_Cdl3BlackCrows.cs │ ├── TA_Cdl3Inside.cs │ ├── TA_Cdl3LineStrike.cs │ ├── TA_Cdl3Outside.cs │ ├── TA_Cdl3StarsInSouth.cs │ ├── TA_Cdl3WhiteSoldiers.cs │ ├── TA_CdlAbandonedBaby.cs │ ├── TA_CdlAdvanceBlock.cs │ ├── TA_CdlBeltHold.cs │ ├── TA_CdlBreakaway.cs │ ├── TA_CdlClosingMarubozu.cs │ ├── TA_CdlConcealBabysWall.cs │ ├── TA_CdlCounterAttack.cs │ ├── TA_CdlDarkCloudCover.cs │ ├── TA_CdlDoji.cs │ ├── TA_CdlDojiStar.cs │ ├── TA_CdlDragonflyDoji.cs │ ├── TA_CdlEngulfing.cs │ ├── TA_CdlEveningDojiStar.cs │ ├── TA_CdlEveningStar.cs │ ├── TA_CdlGapSideSideWhite.cs │ ├── TA_CdlGravestoneDoji.cs │ ├── TA_CdlHammer.cs │ ├── TA_CdlHangingMan.cs │ ├── TA_CdlHarami.cs │ ├── TA_CdlHaramiCross.cs │ ├── TA_CdlHignWave.cs │ ├── TA_CdlHikkake.cs │ ├── TA_CdlHikkakeMod.cs │ ├── TA_CdlHomingPigeon.cs │ ├── TA_CdlIdentical3Crows.cs │ ├── TA_CdlInNeck.cs │ ├── TA_CdlInvertedHammer.cs │ ├── TA_CdlKicking.cs │ ├── TA_CdlKickingByLength.cs │ ├── TA_CdlLadderBottom.cs │ ├── TA_CdlLongLeggedDoji.cs │ ├── TA_CdlLongLine.cs │ ├── TA_CdlMarubozu.cs │ ├── TA_CdlMatHold.cs │ ├── TA_CdlMatchingLow.cs │ ├── TA_CdlMorningDojiStar.cs │ ├── TA_CdlMorningStar.cs │ ├── TA_CdlOnNeck.cs │ ├── TA_CdlPiercing.cs │ ├── TA_CdlRickshawMan.cs │ ├── TA_CdlRiseFall3Methods.cs │ ├── TA_CdlSeperatingLines.cs │ ├── TA_CdlShootingStar.cs │ ├── TA_CdlShortLine.cs │ ├── TA_CdlSpinningTop.cs │ ├── TA_CdlStalledPattern.cs │ ├── TA_CdlStickSandwhich.cs │ ├── TA_CdlTakuri.cs │ ├── TA_CdlTasukiGap.cs │ ├── TA_CdlThrusting.cs │ ├── TA_CdlTristar.cs │ ├── TA_CdlUnique3River.cs │ ├── TA_CdlUpsideGap2Crows.cs │ ├── TA_CdlXSideGap3Methods.cs │ ├── TA_Ceil.cs │ ├── TA_Cmo.cs │ ├── TA_Correl.cs │ ├── TA_Cos.cs │ ├── TA_Cosh.cs │ ├── TA_Dema.cs │ ├── TA_Div.cs │ ├── TA_Dx.cs │ ├── TA_Ema.cs │ ├── TA_Exp.cs │ ├── TA_Floor.cs │ ├── TA_HtDcPeriod.cs │ ├── TA_HtDcPhase.cs │ ├── TA_HtPhasor.cs │ ├── TA_HtSine.cs │ ├── TA_HtTrendMode.cs │ ├── TA_HtTrendline.cs │ ├── TA_Kama.cs │ ├── TA_LinearReg.cs │ ├── TA_LinearRegAngle.cs │ ├── TA_LinearRegIntercept.cs │ ├── TA_LinearRegSlope.cs │ ├── TA_Ln.cs │ ├── TA_Log10.cs │ ├── TA_Macd.cs │ ├── TA_MacdExt.cs │ ├── TA_MacdFix.cs │ ├── TA_Mama.cs │ ├── TA_Max.cs │ ├── TA_MaxIndex.cs │ ├── TA_MedPrice.cs │ ├── TA_Mfi.cs │ ├── TA_MidPoint.cs │ ├── TA_MidPrice.cs │ ├── TA_Min.cs │ ├── TA_MinIndex.cs │ ├── TA_MinMax.cs │ ├── TA_MinMaxIndex.cs │ ├── TA_MinusDI.cs │ ├── TA_MinusDM.cs │ ├── TA_Mom.cs │ ├── TA_MovingAverage.cs │ ├── TA_MovingAverageVariablePeriod.cs │ ├── TA_Mult.cs │ ├── TA_Natr.cs │ ├── TA_Obv.cs │ ├── TA_PlusDI.cs │ ├── TA_PlusDM.cs │ ├── TA_Ppo.cs │ ├── TA_Roc.cs │ ├── TA_RocP.cs │ ├── TA_RocR.cs │ ├── TA_RocR100.cs │ ├── TA_Rsi.cs │ ├── TA_Sar.cs │ ├── TA_SarExt.cs │ ├── TA_Sin.cs │ ├── TA_Sinh.cs │ ├── TA_Sma.cs │ ├── TA_Sqrt.cs │ ├── TA_StdDev.cs │ ├── TA_Stoch.cs │ ├── TA_StochF.cs │ ├── TA_StochRsi.cs │ ├── TA_Sub.cs │ ├── TA_Sum.cs │ ├── TA_T3.cs │ ├── TA_Tan.cs │ ├── TA_Tanh.cs │ ├── TA_Tema.cs │ ├── TA_Trima.cs │ ├── TA_Trix.cs │ ├── TA_TrueRange.cs │ ├── TA_Tsf.cs │ ├── TA_TypPrice.cs │ ├── TA_UltOsc.cs │ ├── TA_Variance.cs │ ├── TA_WclPrice.cs │ ├── TA_WillR.cs │ └── TA_Wma.cs ├── TALib.csproj ├── TaIndicators.cs └── Utility.cs ├── XApiSharp ├── AccountField.cs ├── ApiType.cs ├── AssemblyResolver.cs ├── BarDataField.cs ├── BarType.cs ├── BusinessType.cs ├── ConnectionStatus.cs ├── DataObjetType.cs ├── DepthField.cs ├── DepthLevelType.cs ├── DepthMarketDataField.cs ├── EnterReasonType.cs ├── ErrorField.cs ├── ExchangeType.cs ├── ExecType.cs ├── HedgeFlagType.cs ├── IXApi.cs ├── IXSpi.cs ├── IdCardType.cs ├── InstLifePhaseType.cs ├── InstrumentField.cs ├── InstrumentStatusField.cs ├── InstrumentStatusType.cs ├── InstrumentType.cs ├── InternalDepthMarketDataField.cs ├── InternalErrorField.cs ├── InternalLogField.cs ├── InternalRspUserLoginField.cs ├── InternalSettlementInfoField.cs ├── InvestorField.cs ├── LogField.cs ├── LogLevel.cs ├── ManagedApiLoader.cs ├── ManagedManager.cs ├── Native │ ├── PInvokeUtility.cs │ ├── ResponseData.cs │ ├── SubscribedList.cs │ ├── UnixInvoke.cs │ ├── UnmanagedOrders.cs │ ├── UnmanagedPtr.cs │ ├── WindowsInvoke.cs │ ├── XApi.cs │ ├── XApiInvoke.cs │ └── XApiInvokeProxy.cs ├── OpenCloseType.cs ├── OptimizedEnum.cs ├── OrderField.cs ├── OrderIDType.cs ├── OrderSide.cs ├── OrderStatus.cs ├── OrderType.cs ├── PositionField.cs ├── PositionSide.cs ├── Properties │ └── AssemblyInfo.cs ├── PutCall.cs ├── QueryManager.cs ├── QueryType.cs ├── ReqQueryField.cs ├── RequestType.cs ├── ResponseType.cs ├── ResumeType.cs ├── RspUserLoginField.cs ├── ServerInfoField.cs ├── SettlementInfoField.cs ├── TimeInForce.cs ├── TradeField.cs ├── TradingPhaseType.cs ├── UserInfoField.cs ├── XApiHelper.cs ├── XApiSharp.csproj ├── XSpi.cs └── XTradingApi.cs ├── XProviders.sln └── libs ├── CSharpHdf.dll └── Skyline.Core.dll /CtpApi/CtpDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QuantBox.Sfit.Api 8 | { 9 | public delegate void CtpEventHandler4(object sender, T response, CtpRspInfo rspInfo, int requestID, bool isLast); 10 | public delegate void CtpEventHandler3(object sender, CtpRspInfo rspInfo, int requestID, bool isLast); 11 | public delegate void CtpEventHandler2(object sender, T response, CtpRspInfo rspInfo); 12 | public delegate void CtpEventHandler(object sender, T response); 13 | public delegate void CtpEventHandler(object sender); 14 | } 15 | -------------------------------------------------------------------------------- /CtpApi/CtpErrorMsg.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/CtpApi/CtpErrorMsg.cs -------------------------------------------------------------------------------- /CtpApi/CtpRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QuantBox.Sfit.Api 8 | { 9 | public struct CtpRequest 10 | { 11 | public readonly byte[] ClientID; 12 | public byte TypeId; 13 | public CtpAny Args; 14 | public int RequestID; 15 | 16 | public CtpRequest(byte[] clientID, byte id) 17 | { 18 | ClientID = clientID; 19 | TypeId = id; 20 | RequestID = 0; 21 | Args = new CtpAny(0); 22 | } 23 | 24 | public CtpRequest(byte id, int data, int requestID) 25 | : this(null, id) 26 | { 27 | Args = new CtpAny(data); 28 | RequestID = requestID; 29 | } 30 | 31 | public CtpRequest(byte id, object data, int requestID) 32 | : this(null, id) 33 | { 34 | Args = new CtpAny(data); 35 | RequestID = requestID; 36 | } 37 | 38 | public CtpRequest(byte[] clientID, byte id, int data) 39 | : this(clientID, id) 40 | { 41 | Args = new CtpAny(data); 42 | } 43 | 44 | public CtpRequest(byte[] clientID, byte id, object data) 45 | : this(clientID, id) 46 | { 47 | Args = new CtpAny(data); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CtpApi/CtpResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QuantBox.Sfit.Api 8 | { 9 | public struct CtpResponse 10 | { 11 | public CtpResponse(byte[] clientID, byte id) 12 | { 13 | ClientID = clientID; 14 | TypeId = id; 15 | Item1 = new CtpAny(0); 16 | Item2 = null; 17 | RequestID = 0; 18 | IsLast = true; 19 | UserID = ""; 20 | } 21 | 22 | public CtpResponse(byte[] clientID, byte id, object objValue, CtpRspInfo rspInfo = null) 23 | : this(clientID, id) 24 | { 25 | Item1 = new CtpAny(objValue); 26 | Item2 = rspInfo; 27 | UserID = ""; 28 | } 29 | 30 | public CtpResponse(byte[] clientID, byte id, int intValue, CtpRspInfo rspInfo = null) 31 | : this(clientID, id) 32 | { 33 | Item1 = new CtpAny(intValue); 34 | Item2 = rspInfo; 35 | } 36 | 37 | public CtpResponse(string userID, byte id, object objValue, CtpRspInfo rspInfo = null) 38 | : this(null, id) 39 | { 40 | Item1 = new CtpAny(objValue); 41 | Item2 = rspInfo; 42 | UserID = userID; 43 | } 44 | 45 | public CtpResponse(string userID, byte id, int intValue, CtpRspInfo rspInfo = null) 46 | : this(null, id) 47 | { 48 | Item1 = new CtpAny(intValue); 49 | Item2 = rspInfo; 50 | UserID = userID; 51 | } 52 | 53 | public string UserID; 54 | public byte[] ClientID; 55 | public byte TypeId; 56 | public CtpAny Item1; 57 | public CtpRspInfo Item2; 58 | public int RequestID; 59 | public bool IsLast; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CtpApi/CtpResumeType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QuantBox.Sfit.Api 8 | { 9 | public enum CtpResumeType : int 10 | { 11 | Restart = 0, 12 | Resume, 13 | Quick 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CtpApi/CtpSpi.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.Sfit.Api 2 | { 3 | public abstract class CtpSpi : ICtpResponseHandler 4 | { 5 | public abstract void SetResponseHandler(byte type, CtpResponseAction handler); 6 | public abstract void ProcessResponse(ref CtpResponse rsp); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /CtpApi/CtpStartInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace QuantBox.Sfit.Api 8 | { 9 | public class CtpStartInfo 10 | { 11 | public CtpResumeType ResumeType; 12 | public string FrontAddress = string.Empty; 13 | public string FlowPath = string.Empty; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CtpApi/ICtpRequestHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * User: hetao 3 | * Date: 2014/5/26 星期一 4 | * Time: 9:10 5 | * 6 | */ 7 | using System; 8 | using System.Security; 9 | 10 | namespace QuantBox.Sfit.Api 11 | { 12 | public delegate int CtpRequestFunc(ref CtpRequest req); 13 | public interface ICtpRequestHandler 14 | { 15 | int ProcessRequest(ref CtpRequest req); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CtpApi/ICtpResponseHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * User: hetao 3 | * Date: 2014/5/26 星期一 4 | * Time: 9:14 5 | * 6 | */ 7 | using System; 8 | 9 | namespace QuantBox.Sfit.Api 10 | { 11 | public delegate void CtpResponseAction(ref CtpResponse rsp); 12 | /// 13 | /// Description of ICtpResponseHandler. 14 | /// 15 | public interface ICtpResponseHandler 16 | { 17 | void SetResponseHandler(byte type, CtpResponseAction handler); 18 | void ProcessResponse(ref CtpResponse rsp); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CtpApi/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("QuantBox.Sfit.Api")] 9 | [assembly: AssemblyDescription("CtpApi For CSharp")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("QuantBox")] 12 | [assembly: AssemblyProduct("CtpApi For CSharp")] 13 | [assembly: AssemblyCopyright("Copyright © QuantBox 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("34817d68-9043-42b0-8bff-e4948bfde6ff")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("6.3.6.0")] 36 | [assembly: AssemblyFileVersion("6.3.6.0")] 37 | -------------------------------------------------------------------------------- /Ctp_C/.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 3 | ################################################################################ 4 | 5 | .vs 6 | Debug 7 | Release 8 | bin 9 | CtpseOutput -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/CtpseSfit_C.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/data_collect.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | 5 | #define DLL __declspec(dllexport) 6 | #ifdef __cplusplus 7 | extern "C" 8 | { 9 | #endif 10 | ///获取AES加密和RSA加密的终端信息 11 | ///@pSystemInfo 出参 空间需要调用者自己分配 至少270个字节 12 | ///@nLen 出参 获取到的采集信息的长度 13 | ///采集信息内可能含有‘\0’ 建议调用者使用内存复制 14 | DLL int CALLBACK CtpGetSystemInfo(char* pSystemInfo,int& nLen) 15 | { 16 | return CTP_GetSystemInfo(pSystemInfo, nLen); 17 | } 18 | #ifdef __cplusplus 19 | } 20 | #endif -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/dllmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/CtpseSfit_C/dllmain.cpp -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/CtpseSfit_C/stdafx.cpp -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/CtpseSfit_C/stdafx.h -------------------------------------------------------------------------------- /Ctp_C/CtpseSfit_C/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/CtpseSfit_C/targetver.h -------------------------------------------------------------------------------- /Ctp_C/Ctpse_C.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2009 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CtpseSfit_C", "CtpseSfit_C\CtpseSfit_C.vcxproj", "{5CD7C235-2E50-4169-B0C9-CD94A419AD7A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|Mixed Platforms = Debug|Mixed Platforms 12 | Debug|Win32 = Debug|Win32 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|ARM = Release|ARM 16 | Release|Mixed Platforms = Release|Mixed Platforms 17 | Release|Win32 = Release|Win32 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|ARM.ActiveCfg = Debug|Win32 23 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 24 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 25 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|Win32.ActiveCfg = Debug|Win32 26 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|Win32.Build.0 = Debug|Win32 27 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|x64.ActiveCfg = Debug|x64 28 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|x64.Build.0 = Debug|x64 29 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|x86.ActiveCfg = Debug|Win32 30 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Debug|x86.Build.0 = Debug|Win32 31 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|ARM.ActiveCfg = Release|Win32 32 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 33 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|Mixed Platforms.Build.0 = Release|Win32 34 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|Win32.ActiveCfg = Release|Win32 35 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|Win32.Build.0 = Release|Win32 36 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|x64.ActiveCfg = Release|x64 37 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|x64.Build.0 = Release|x64 38 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|x86.ActiveCfg = Release|Win32 39 | {5CD7C235-2E50-4169-B0C9-CD94A419AD7A}.Release|x86.Build.0 = Release|Win32 40 | EndGlobalSection 41 | GlobalSection(SolutionProperties) = preSolution 42 | HideSolutionNode = FALSE 43 | EndGlobalSection 44 | GlobalSection(ExtensibilityGlobals) = postSolution 45 | SolutionGuid = {F29BF163-46F6-4EC4-846F-B7DC761D9C25} 46 | EndGlobalSection 47 | EndGlobal 48 | -------------------------------------------------------------------------------- /Ctp_C/Readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/Readme.md -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/DataCollect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/DataCollect.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/TfseMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/TfseMdApi.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/TfseTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/TfseTraderApi.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/ThostFtdcMdApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/ThostFtdcMdApi.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/ThostFtdcTraderApi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/ThostFtdcTraderApi.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/ThostFtdcUserApiStruct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/ThostFtdcUserApiStruct.h -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/error.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /Ctp_C/external-bin/ctpse/error.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/Ctp_C/external-bin/ctpse/error.xml -------------------------------------------------------------------------------- /OpenQuantCompatibility/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("OpenQuant Compatibility")] 9 | [assembly: AssemblyDescription("兼容不同版本OpenQuant函数库")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("quantbox")] 12 | [assembly: AssemblyProduct("OpenQuant Compatibility")] 13 | [assembly: AssemblyCopyright("Copyright © quantbox 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("6ad35d65-bd88-4fc5-a61a-8818a6981e43")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.5.0")] 36 | [assembly: AssemblyFileVersion("1.0.5.0")] 37 | -------------------------------------------------------------------------------- /QuantBox.Ctpse/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("QauntBox.Ctpse")] 8 | [assembly: AssemblyDescription("QauntBox CTPSE Provider")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("QauntBox")] 11 | [assembly: AssemblyProduct("QauntBox.Ctpse")] 12 | [assembly: AssemblyCopyright("Copyright © QauntBox 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("30bec3ca-59e4-4b45-9f73-0ae18f1b9a7b")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.1706")] 36 | -------------------------------------------------------------------------------- /QuantBox.Ctpse/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /QuantBox.Ctpse/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /QuantBox/AccountPosition.cs: -------------------------------------------------------------------------------- 1 | using QuantBox.XApi; 2 | 3 | namespace QuantBox 4 | { 5 | public class AccountPosition 6 | { 7 | public string ExchangeId { get; private set; } 8 | 9 | public string InstrumentId { get; private set; } 10 | 11 | public double Qty => LongQty + ShortQty; 12 | 13 | public PositionField Long { get; private set; } 14 | 15 | public double LongQty { 16 | get { 17 | if (Long != null) { 18 | return Long.Position; 19 | } 20 | return 0; 21 | } 22 | } 23 | 24 | public PositionField Short { get; private set; } 25 | 26 | public double ShortQty { 27 | get { 28 | if (Short != null) { 29 | return Short.Position; 30 | } 31 | return 0; 32 | } 33 | } 34 | 35 | public void AddPosition(PositionField position) 36 | { 37 | if (string.IsNullOrEmpty(InstrumentId)) { 38 | ExchangeId = position.ExchangeID; 39 | InstrumentId = position.InstrumentID; 40 | } 41 | 42 | if (position.Side == PositionSide.Long) { 43 | Long = position; 44 | } 45 | else { 46 | Short = position; 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /QuantBox/ConnectionInfo.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Drawing.Design; 3 | using System.Runtime.Serialization; 4 | #if NETFRAMEWORK 5 | using System.Windows.Forms.Design; 6 | using QuantBox.Design; 7 | #endif 8 | using QuantBox.XApi; 9 | 10 | namespace QuantBox 11 | { 12 | [DataContract] 13 | public class ConnectionInfo 14 | { 15 | private const string CategoryInfo = "Information"; 16 | private const string CategoryType = "Type"; 17 | #if NETFRAMEWORK 18 | [Editor(typeof(FileNameEditor), typeof(UITypeEditor))] 19 | #endif 20 | [DataMember] 21 | public string ApiPath { get; set; } 22 | 23 | [Category(CategoryInfo)] 24 | [ReadOnly(true)] 25 | [DataMember] 26 | public string Name { get; set; } 27 | 28 | [Category(CategoryInfo)] 29 | [ReadOnly(true)] 30 | [DataMember] 31 | public string Version { get; set; } 32 | 33 | #if NETFRAMEWORK 34 | [TypeConverter(typeof(UserSelectorConverter))] 35 | #endif 36 | [DataMember] 37 | public int User { get; set; } 38 | 39 | #if NETFRAMEWORK 40 | [TypeConverter(typeof(ServerSelectorConverter))] 41 | #endif 42 | [DataMember] 43 | public int Server { get; set; } 44 | 45 | [DataMember] 46 | public string LogPrefix { get; set; } 47 | 48 | [DataMember] 49 | public bool Active { get; set; } 50 | 51 | [Category(CategoryType)] 52 | [ReadOnly(true)] 53 | [DataMember] 54 | public ApiType Type { get; set; } 55 | 56 | [Category(CategoryType)] 57 | #if NETFRAMEWORK 58 | [Editor(typeof(ApiTypeSelectorEditor), typeof(UITypeEditor))] 59 | #endif 60 | [DataMember] 61 | public ApiType UseType { get; set; } 62 | 63 | public override string ToString() 64 | { 65 | return $"LogPrefix={LogPrefix};UseType={UseType};Name={Name}"; 66 | } 67 | 68 | public ConnectionInfo Clone() 69 | { 70 | return (ConnectionInfo)MemberwiseClone(); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /QuantBox/Data.Compression/BarDataEnumerator.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox.Data.Compression 4 | { 5 | internal class BarDataEnumerator : DataEntryEnumerator 6 | { 7 | private readonly BarSeries _series; 8 | 9 | public override DataEntry Current 10 | { 11 | get { 12 | var bar = _series[index]; 13 | 14 | return new DataEntry(bar.OpenDateTime, TimeRangeSelector.Get(bar.DateTime), new PriceSizeItem[4] { 15 | new PriceSizeItem(bar.Open, 0), 16 | new PriceSizeItem(bar.High, 0), 17 | new PriceSizeItem(bar.Low, 0), 18 | new PriceSizeItem(bar.Close, (int)bar.Volume, (int)bar.OpenInt, bar.GetTurnover()) 19 | }); 20 | } 21 | } 22 | 23 | public BarDataEnumerator(BarSeries series) 24 | : base(series.Count) 25 | { 26 | _series = series; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /QuantBox/Data.Compression/CompressedBarEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using SmartQuant; 3 | 4 | namespace QuantBox.Data.Compression 5 | { 6 | internal class CompressedBarEventArgs : EventArgs 7 | { 8 | public Bar Bar 9 | { 10 | get; 11 | private set; 12 | } 13 | 14 | public CompressedBarEventArgs(Bar bar) 15 | { 16 | Bar = bar; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /QuantBox/Data.Compression/DataEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Skyline; 3 | 4 | namespace QuantBox.Data.Compression 5 | { 6 | internal class DataEntry 7 | { 8 | public readonly TradingTimeRange TimeRanges; 9 | public readonly DateTime DateTime; 10 | public readonly PriceSizeItem[] Items; 11 | 12 | public DataEntry(DateTime datetime, TradingTimeRange timeRanges, PriceSizeItem[] items) 13 | { 14 | DateTime = datetime; 15 | TimeRanges = timeRanges; 16 | Items = items; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /QuantBox/Data.Compression/DataEntryEnumerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace QuantBox.Data.Compression 6 | { 7 | internal abstract class DataEntryEnumerator : IEnumerator, IDisposable, IEnumerator 8 | { 9 | protected int index; 10 | internal TimeRangeSelector TimeRangeSelector; 11 | private readonly int _count; 12 | 13 | public abstract DataEntry Current { get; } 14 | 15 | object IEnumerator.Current { get { throw new NotImplementedException(); } } 16 | 17 | protected DataEntryEnumerator(int count) 18 | { 19 | _count = count; 20 | Reset(); 21 | } 22 | 23 | public void Dispose() 24 | { 25 | } 26 | 27 | public virtual bool MoveNext() 28 | { 29 | return ++index < _count; 30 | } 31 | 32 | public virtual void Reset() 33 | { 34 | index = -1; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /QuantBox/Data.Compression/DataSeriesEnumerator.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox.Data.Compression 4 | { 5 | internal class DataSeriesEnumerator : DataEntryEnumerator 6 | { 7 | private readonly DataSeries _series; 8 | private readonly int _index1; 9 | private readonly int _index2; 10 | 11 | private PriceSizeItem GetItem(Tick tick) 12 | { 13 | if (tick.TypeId == DataObjectType.Trade) { 14 | var trade = (Trade)tick; 15 | return new PriceSizeItem(tick.Price, tick.Size, (int)trade.GetOpenInterest(), trade.GetTurnover()); 16 | } 17 | else { 18 | return new PriceSizeItem(tick.Price, tick.Size); 19 | } 20 | } 21 | 22 | public DataSeriesEnumerator(DataSeries series, int index1, int index2) : base(index2 - index1 + 1) 23 | { 24 | _series = series; 25 | _index1 = index1; 26 | _index2 = index2; 27 | } 28 | 29 | public override bool MoveNext() 30 | { 31 | return ++index <= _index2; 32 | } 33 | 34 | public override void Reset() 35 | { 36 | index = _index1 - 1; 37 | } 38 | 39 | public override DataEntry Current 40 | { 41 | get { 42 | var tick = (Tick)_series[index]; 43 | var timeRanges = TimeRangeSelector.Get(tick.DateTime); 44 | if (tick.Size > 0 && timeRanges.InRange(tick.DateTime.TimeOfDay)) { 45 | return new DataEntry(tick.DateTime, timeRanges, new PriceSizeItem[] { GetItem(tick) }); 46 | } 47 | return null; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /QuantBox/Data.Compression/PriceSizeItem.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.Data.Compression 2 | { 3 | internal class PriceSizeItem 4 | { 5 | public double Price { get; private set; } 6 | 7 | public int Size { get; private set; } 8 | 9 | public int OpenInt { get; private set; } 10 | 11 | public double Amount { get; private set; } 12 | 13 | public PriceSizeItem(double price, int size, int openInt = 0, double amount = 0) 14 | { 15 | Price = price; 16 | Size = size; 17 | OpenInt = openInt; 18 | Amount = amount; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /QuantBox/Data.Compression/TickDataEnumerator.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox.Data.Compression 4 | { 5 | internal class TickDataEnumerator : DataEntryEnumerator 6 | { 7 | private readonly TickSeries _series; 8 | private readonly byte _type; 9 | 10 | private PriceSizeItem GetItem(Tick tick) 11 | { 12 | if (tick.TypeId == DataObjectType.Trade) { 13 | var trade = (Trade)tick; 14 | return new PriceSizeItem(tick.Price, tick.Size, (int)trade.GetOpenInterest(), trade.GetTurnover()); 15 | } 16 | else { 17 | return new PriceSizeItem(tick.Price, tick.Size); 18 | } 19 | } 20 | 21 | public override DataEntry Current 22 | { 23 | get { 24 | Tick tick = _series[index]; 25 | if (_type == tick.TypeId) { 26 | var range = TimeRangeSelector.Get(tick.DateTime); 27 | if (tick.Size > 0 && range.InRange(tick.DateTime.TimeOfDay)) { 28 | return new DataEntry(tick.DateTime, range, new PriceSizeItem[] { GetItem(tick) }); 29 | } 30 | } 31 | return null; 32 | } 33 | } 34 | 35 | public TickDataEnumerator(TickSeries series, byte type = DataObjectType.Trade) 36 | : base(series.Count) 37 | { 38 | _series = series; 39 | _type = type; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /QuantBox/DataEventMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using LiteDB; 4 | using SmartQuant; 5 | 6 | namespace QuantBox 7 | { 8 | public enum ObjectTableOwner 9 | { 10 | Order,Stop 11 | } 12 | 13 | public delegate void ObjectTableReader(ObjectTableOwner owner, ObjectTable table, BinaryReader writer); 14 | public delegate void ObjectTableWriter(ObjectTableOwner owner, ObjectTable table, BinaryWriter writer); 15 | 16 | internal class DataEventMapper : BsonMapper 17 | { 18 | public DataEventMapper(ObjectTableWriter fieldsWriter, ObjectTableReader fieldsReader) 19 | { 20 | ReportSerializer = new ExecutionReportSerializer(); 21 | CommandSerializer = new ExecutionCommandSerializer(fieldsWriter, fieldsReader); 22 | StopSerializer = new StopSerializer(fieldsWriter, fieldsReader); 23 | RegisterType(CommandSerializer.ToBson, CommandSerializer.ToCommand); 24 | RegisterType(ReportSerializer.ToBson, ReportSerializer.ToReport); 25 | RegisterType(StopSerializer.ToBson, StopSerializer.ToStop); 26 | RegisterType(PortfolioSerializer.ToBson, PortfolioSerializer.ToPortfolio); 27 | } 28 | 29 | public readonly StopSerializer StopSerializer; 30 | public readonly ExecutionReportSerializer ReportSerializer; 31 | public readonly ExecutionCommandSerializer CommandSerializer; 32 | } 33 | } -------------------------------------------------------------------------------- /QuantBox/DatabasePortfolioServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using LiteDB; 4 | using SmartQuant; 5 | 6 | namespace QuantBox 7 | { 8 | internal class DatabasePortfolioServer : PortfolioServer 9 | { 10 | private readonly LiteDatabase _database; 11 | private readonly ILiteCollection _portfolios; 12 | 13 | public DatabasePortfolioServer(Framework framework, LiteDatabase database) : base(framework) 14 | { 15 | _database = database; 16 | _portfolios = _database.GetCollection("portfolios"); 17 | } 18 | 19 | public override Portfolio Load(string name) 20 | { 21 | var map = _portfolios.FindAll().ToDictionary(n => n.Id); 22 | var items = map.Values.ToList(); 23 | items.Sort((x, y) => x.Id.CompareTo(y.Id)); 24 | Portfolio root = null; 25 | foreach (var item in items) { 26 | item.Init(framework); 27 | framework.PortfolioManager.Add(item); 28 | if (item.ParentId == -1) { 29 | root = item; 30 | } 31 | else { 32 | var parent = map[item.ParentId]; 33 | parent.Children.Add(item); 34 | item.Parent = parent; 35 | } 36 | } 37 | return root; 38 | } 39 | 40 | public override void Save(Portfolio portfolio) 41 | { 42 | _portfolios.Upsert(portfolio); 43 | foreach (var item in portfolio.Children) { 44 | Save(item); 45 | } 46 | } 47 | 48 | public override void Close() 49 | { 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /QuantBox/DataflowHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks.Dataflow; 3 | 4 | namespace QuantBox 5 | { 6 | internal static class DataflowHelper 7 | { 8 | public static readonly ExecutionDataflowBlockOptions SpscBlockOptions; 9 | 10 | static DataflowHelper() => 11 | SpscBlockOptions = new ExecutionDataflowBlockOptions { 12 | SingleProducerConstrained = true, 13 | CancellationToken = CancellationToken.None, 14 | MaxDegreeOfParallelism = 1 15 | }; 16 | } 17 | } -------------------------------------------------------------------------------- /QuantBox/Design/ApiSettingsConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | 6 | namespace QuantBox.Design 7 | { 8 | internal abstract class ApiSettingsConverter : ExpandableObjectConverter 9 | { 10 | protected abstract IDictionary PropertyMap { get; } 11 | 12 | public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) 13 | { 14 | var props = base.GetProperties(context, value, attributes); 15 | var list = new List(props.Count); 16 | var map = PropertyMap; 17 | if (map == null) { 18 | list.AddRange(props.Cast()); 19 | } 20 | else { 21 | foreach (PropertyDescriptor prop in props) { 22 | map.TryGetValue(prop.Name, out string displayName); 23 | if (string.IsNullOrEmpty(displayName)) { 24 | continue; 25 | } 26 | if (displayName != prop.DisplayName) { 27 | list.Add(new DisplayNamePropertyDescriptor(prop, displayName)); 28 | } 29 | else { 30 | list.Add(prop); 31 | } 32 | } 33 | } 34 | return new PropertyDescriptorCollection(list.ToArray(), true); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /QuantBox/Design/ApiTypeSelectorEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.ComponentModel.Design; 4 | using System.Windows.Forms; 5 | using QuantBox.XApi; 6 | 7 | namespace QuantBox.Design 8 | { 9 | internal class ApiTypeSelectorEditor : ObjectSelectorEditor 10 | { 11 | private Selector _selector; 12 | 13 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 14 | { 15 | base.EditValue(context, provider, value); 16 | _selector.BeforeSelect -= SelectBefore; 17 | var type = 0; 18 | foreach (SelectorNode node in _selector.Nodes) { 19 | if (node.Checked) { 20 | type |= (int)node.value; 21 | } 22 | } 23 | return (ApiType)type; 24 | } 25 | 26 | protected override void FillTreeWithData(Selector selector, ITypeDescriptorContext context, IServiceProvider provider) 27 | { 28 | if (context?.Instance != null) { 29 | _selector = selector; 30 | selector.CheckBoxes = true; 31 | selector.BeforeSelect += SelectBefore; 32 | selector.Clear(); 33 | var instance = context.Instance as ConnectionInfo; 34 | foreach (ApiType category in Enum.GetValues(typeof(ApiType))) { 35 | if (category != ApiType.None) { 36 | var node = selector.AddNode(category.ToString(), (int)category, null); 37 | if (instance != null) { 38 | node.Checked = (instance.Type & category) == category; 39 | } 40 | } 41 | } 42 | selector.SelectedNode = null; 43 | } 44 | else { 45 | base.FillTreeWithData(selector, context, provider); 46 | } 47 | } 48 | 49 | private static void SelectBefore(object sender, TreeViewCancelEventArgs e) 50 | { 51 | e.Cancel = true; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /QuantBox/Design/ComboBoxItemTypeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Globalization; 5 | 6 | namespace QuantBox.Design 7 | { 8 | internal abstract class ComboBoxItemTypeConverter : TypeConverter 9 | { 10 | protected readonly SortedDictionary Items = new SortedDictionary(); 11 | 12 | protected abstract void GetItems(ITypeDescriptorContext context); 13 | 14 | public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 15 | { 16 | return true; 17 | } 18 | 19 | public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 20 | { 21 | return true; 22 | } 23 | 24 | public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 25 | { 26 | GetItems(context); 27 | return new StandardValuesCollection(Items.Keys); 28 | } 29 | 30 | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) 31 | { 32 | return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); 33 | } 34 | 35 | public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) 36 | { 37 | return true; 38 | } 39 | 40 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object v) 41 | { 42 | if (v is string) { 43 | foreach (var pair in Items) { 44 | if (pair.Value.ToString() == v.ToString()) 45 | return pair.Key; 46 | } 47 | } 48 | return base.ConvertFrom(context, culture, v); 49 | } 50 | 51 | public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object v, Type destinationType) 52 | { 53 | GetItems(context); 54 | if (destinationType == typeof(string) && v is int) { 55 | foreach (var pair in Items) { 56 | if (pair.Key == (int)v) 57 | return pair.Value.ToString(); 58 | } 59 | return ""; 60 | } 61 | return base.ConvertTo(context, culture, v, destinationType); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /QuantBox/Design/DisplayNamePropertyDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace QuantBox.Design 5 | { 6 | internal class DisplayNamePropertyDescriptor : PropertyDescriptor 7 | { 8 | private readonly PropertyDescriptor _parent; 9 | 10 | public DisplayNamePropertyDescriptor(PropertyDescriptor parent, string displayName) 11 | : base(parent) 12 | { 13 | DisplayName = displayName; 14 | _parent = parent; 15 | } 16 | 17 | public override string DisplayName { get; } 18 | 19 | public override bool ShouldSerializeValue(object component) 20 | { 21 | return _parent.ShouldSerializeValue(component); 22 | } 23 | 24 | public override void SetValue(object component, object value) 25 | { 26 | _parent.SetValue(component, value); 27 | } 28 | public override object GetValue(object component) 29 | { 30 | return _parent.GetValue(component); 31 | } 32 | public override void ResetValue(object component) 33 | { 34 | _parent.ResetValue(component); 35 | } 36 | public override bool CanResetValue(object component) 37 | { 38 | return _parent.CanResetValue(component); 39 | } 40 | public override bool IsReadOnly => _parent.IsReadOnly; 41 | 42 | public override void AddValueChanged(object component, EventHandler handler) 43 | { 44 | _parent.AddValueChanged(component, handler); 45 | } 46 | public override void RemoveValueChanged(object component, EventHandler handler) 47 | { 48 | _parent.RemoveValueChanged(component, handler); 49 | } 50 | public override bool SupportsChangeEvents => _parent.SupportsChangeEvents; 51 | 52 | public override Type PropertyType => _parent.PropertyType; 53 | 54 | public override TypeConverter Converter => _parent.Converter; 55 | 56 | public override Type ComponentType => _parent.ComponentType; 57 | 58 | public override string Description => _parent.Description; 59 | 60 | public override PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter) 61 | { 62 | return _parent.GetChildProperties(instance, filter); 63 | } 64 | public override string Name => _parent.Name; 65 | } 66 | } -------------------------------------------------------------------------------- /QuantBox/Design/FolderNameEditor2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing.Design; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace QuantBox.Design 11 | { 12 | public class FolderNameEditor2 : UITypeEditor 13 | { 14 | public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 15 | { 16 | return UITypeEditorEditStyle.Modal; 17 | } 18 | 19 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 20 | { 21 | var browser = new FolderBrowser2(); 22 | if (value != null) { 23 | browser.DirectoryPath = $"{value}"; 24 | } 25 | 26 | if (browser.ShowDialog(null) == DialogResult.OK) 27 | return browser.DirectoryPath; 28 | 29 | return value; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /QuantBox/Design/InstrumentProviderConverter.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox.Design 4 | { 5 | internal class InstrumentProviderConverter : ProviderTypeConverter 6 | { 7 | protected override bool Filter(IProvider provider) 8 | { 9 | return provider is IInstrumentProvider; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /QuantBox/Design/RPropertyGrid.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Rajeev.Windows.Forms 2 | { 3 | partial class RPropertyGrid 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | components = new System.ComponentModel.Container(); 32 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 | } 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /QuantBox/Design/ServerInfoConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace QuantBox.Design 4 | { 5 | internal class ServerInfoConverter : ApiSettingsConverter 6 | { 7 | protected override IDictionary PropertyMap => Provider.GetServerPropertyMap(); 8 | internal static XProvider Provider; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /QuantBox/Design/ServerSelectorConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel; 3 | 4 | namespace QuantBox.Design 5 | { 6 | internal class ServerSelectorConverter : ComboBoxItemTypeConverter 7 | { 8 | protected override void GetItems(ITypeDescriptorContext context) 9 | { 10 | Items.Clear(); 11 | if (context?.Instance is ConnectionInfo) { 12 | for (var i = 0; i < Servers.Count; i++) { 13 | Items[i] = Servers[i]; 14 | } 15 | } 16 | } 17 | 18 | internal static IList Servers; 19 | } 20 | } -------------------------------------------------------------------------------- /QuantBox/Design/TimeSpanEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Drawing.Design; 4 | using System.Windows.Forms; 5 | using System.Windows.Forms.Design; 6 | 7 | namespace QuantBox.Design 8 | { 9 | internal class TimeSpanEditor : UITypeEditor 10 | { 11 | public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 12 | { 13 | return UITypeEditorEditStyle.DropDown; 14 | } 15 | 16 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 17 | { 18 | IWindowsFormsEditorService service = null; 19 | if (provider != null) 20 | service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); 21 | 22 | if (service != null) { 23 | var dtp = new DateTimePicker(); 24 | if (value != null) { 25 | dtp.Value = DateTime.Today.Add((TimeSpan)value); 26 | dtp.Format = DateTimePickerFormat.Time; 27 | dtp.ShowUpDown = true; 28 | service.DropDownControl(dtp); 29 | } 30 | value = dtp.Value.TimeOfDay; 31 | } 32 | return value; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /QuantBox/Design/UserInfoConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace QuantBox.Design 4 | { 5 | internal class UserInfoConverter : ApiSettingsConverter 6 | { 7 | protected override IDictionary PropertyMap => Provider.GetUserPropertyMap(); 8 | internal static XProvider Provider; 9 | } 10 | } -------------------------------------------------------------------------------- /QuantBox/Design/UserSelectorConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel; 3 | 4 | namespace QuantBox.Design 5 | { 6 | internal class UserSelectorConverter : ComboBoxItemTypeConverter 7 | { 8 | protected override void GetItems(ITypeDescriptorContext context) 9 | { 10 | Items.Clear(); 11 | if (context?.Instance is ConnectionInfo) { 12 | for (var i = 0; i < Users.Count; i++) { 13 | Items[i] = Users[i]; 14 | } 15 | } 16 | } 17 | 18 | internal static IList Users; 19 | } 20 | } -------------------------------------------------------------------------------- /QuantBox/Design/XApiSettingsTypeEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Drawing.Design; 4 | using System.Windows.Forms.Design; 5 | 6 | namespace QuantBox.Design 7 | { 8 | internal class XApiSettingsTypeEditor : UITypeEditor 9 | { 10 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 11 | { 12 | if (context?.Instance == null || provider == null) { 13 | return base.EditValue(context, provider, value); 14 | } 15 | if (provider.GetService(typeof(IWindowsFormsEditorService)) is IWindowsFormsEditorService service) { 16 | var instance = (XProvider)context.Instance; 17 | var dialog = new XApiSettingsDialog(instance); 18 | service.ShowDialog(dialog); 19 | } 20 | return value; 21 | } 22 | 23 | public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 24 | { 25 | if (context?.Instance != null) { 26 | return UITypeEditorEditStyle.Modal; 27 | } 28 | return base.GetEditStyle(context); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /QuantBox/EventPipe.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | public class EventPipe 6 | { 7 | private Framework _framework; 8 | 9 | private readonly LinkedList _queues = new LinkedList(); 10 | 11 | public EventPipe(Framework framework) 12 | { 13 | _framework = framework; 14 | } 15 | 16 | public int Count => _queues.Count; 17 | 18 | public void Add(IEventQueue queue) 19 | { 20 | _queues.Add(queue); 21 | } 22 | 23 | public void Remove(IEventQueue queue) 24 | { 25 | _queues.Remove(queue); 26 | } 27 | 28 | public bool IsEmpty() 29 | { 30 | if (_queues.Count != 0) { 31 | for (var node = _queues.First; node != null; node = node.Next) { 32 | if (!node.Data.IsEmpty()) { 33 | return false; 34 | } 35 | } 36 | } 37 | return true; 38 | } 39 | 40 | public Event Read() 41 | { 42 | if (_queues.Count != 0) { 43 | var next = _queues.First; 44 | LinkedListNode prev = null; 45 | while (next != null) { 46 | if (!next.Data.IsEmpty()) { 47 | var @event = next.Data.Read(); 48 | if (@event.TypeId == EventType.OnQueueClosed/*175*/) { 49 | if (prev == null) { 50 | _queues.First = next.Next; 51 | } 52 | else { 53 | prev.Next = next.Next; 54 | } 55 | _queues.Count--; 56 | } 57 | return @event; 58 | } 59 | prev = next; 60 | next = next.Next; 61 | } 62 | } 63 | return null; 64 | } 65 | 66 | public Event Dequeue() 67 | { 68 | return null; 69 | } 70 | 71 | public void Clear() 72 | { 73 | _queues.Clear(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /QuantBox/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json.Linq; 3 | 4 | namespace QuantBox 5 | { 6 | internal class Helper 7 | { 8 | public static DateTime CorrectionActionDay(DateTime local, DateTime exchange) 9 | { 10 | switch (exchange.Hour) { 11 | case 0: 12 | if (local.Hour == 23) { 13 | return local.Date.AddDays(1).Add(exchange.TimeOfDay); 14 | } 15 | break; 16 | case 23: 17 | if (local.Hour == 0) { 18 | return local.Date.AddDays(-1).Add(exchange.TimeOfDay); 19 | } 20 | break; 21 | } 22 | return local.Date.Add(exchange.TimeOfDay); 23 | } 24 | 25 | public static void LoadFromJson(object instance, Type type, JToken token) 26 | { 27 | var list = type.GetProperties(); 28 | foreach (var prop in list) { 29 | if (!prop.CanWrite) { 30 | continue; 31 | } 32 | var item = token[prop.Name]; 33 | if (item == null) { 34 | continue; 35 | } 36 | prop.SetValue(instance, item.ToObject(prop.PropertyType)); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /QuantBox/ICustomStatisticsType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | public interface ICustomStatisticsType 4 | { 5 | void SetStatisticsType(int type); 6 | } 7 | } -------------------------------------------------------------------------------- /QuantBox/IdGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Skyline; 8 | 9 | namespace QuantBox 10 | { 11 | public interface IIdGenerator 12 | { 13 | long Next(); 14 | } 15 | 16 | public class SyncTickIdGen : IIdGenerator 17 | { 18 | private const int Used = 1; 19 | private const int Unused = 0; 20 | 21 | private int _flag; 22 | private long _last; 23 | 24 | public SyncTickIdGen() 25 | { 26 | _last = DateTime.Now.Ticks; 27 | } 28 | public long Next() 29 | { 30 | while (Interlocked.CompareExchange(ref _flag, Used, Unused) != Used) { 31 | Thread.Sleep(0); 32 | } 33 | var ticks = DateTime.Now.Ticks; 34 | while (_last == ticks) { 35 | ticks = DateTime.Now.Ticks; 36 | } 37 | _last = ticks; 38 | Interlocked.Exchange(ref _flag, Unused); 39 | return ticks; 40 | } 41 | } 42 | 43 | public class TickIdGen : IIdGenerator 44 | { 45 | private long _last; 46 | 47 | public TickIdGen() 48 | { 49 | _last = DateTime.Now.Ticks; 50 | } 51 | public long Next() 52 | { 53 | var ticks = DateTime.Now.Ticks; 54 | while (_last == ticks) { 55 | ticks = DateTime.Now.Ticks; 56 | } 57 | _last = ticks; 58 | return ticks; 59 | } 60 | } 61 | 62 | public class IdGenerator : IIdGenerator 63 | { 64 | private long _value; 65 | 66 | public IdGenerator(int baseValue, int seriesValue) 67 | { 68 | _value = new MakeLong(baseValue, seriesValue).Value; 69 | } 70 | 71 | public long Next() => Interlocked.Increment(ref _value); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /QuantBox/IgnoreSerializerContractResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using Newtonsoft.Json; 5 | using Newtonsoft.Json.Serialization; 6 | 7 | namespace QuantBox 8 | { 9 | public class IgnoreSerializerContractResolver : DefaultContractResolver 10 | { 11 | private readonly Dictionary> _ignores; 12 | 13 | public IgnoreSerializerContractResolver() 14 | { 15 | _ignores = new Dictionary>(); 16 | } 17 | 18 | public void IgnoreProperty(Type type, params string[] jsonPropertyNames) 19 | { 20 | if (!_ignores.ContainsKey(type)) 21 | _ignores[type] = new HashSet(); 22 | 23 | foreach (var prop in jsonPropertyNames) 24 | _ignores[type].Add(prop); 25 | } 26 | 27 | protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) 28 | { 29 | var property = base.CreateProperty(member, memberSerialization); 30 | 31 | if (IsIgnored(property.DeclaringType, property.PropertyName)) 32 | property.ShouldSerialize = i => false; 33 | 34 | return property; 35 | } 36 | 37 | private bool IsIgnored(Type type, string jsonPropertyName) 38 | { 39 | if (!_ignores.ContainsKey(type)) 40 | return false; 41 | 42 | return _ignores[type].Contains(jsonPropertyName); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /QuantBox/MarketDataClient.cs: -------------------------------------------------------------------------------- 1 | using QuantBox.XApi; 2 | using SmartQuant; 3 | 4 | namespace QuantBox 5 | { 6 | internal class MarketDataClient : XApiClient 7 | { 8 | public MarketDataClient(XProvider provider, ConnectionInfo info) 9 | : base(provider, info) 10 | { 11 | } 12 | 13 | public void Subscribe(Instrument inst) 14 | { 15 | var altId = Provider.GetAltId(); 16 | api.Subscribe(inst.GetSymbol(altId), inst.GetExchange(altId), (XApi.InstrumentType)inst.Type); 17 | } 18 | 19 | public void Unsubscribe(Instrument inst) 20 | { 21 | var (symbol, exchange) = Provider.GetSymbolInfo(inst); 22 | api.Unsubscribe(symbol, exchange, (XApi.InstrumentType)inst.Type); 23 | } 24 | 25 | public static ApiType ApiType => ApiType.MarketData; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /QuantBox/NoTypeConverterJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Serialization; 4 | 5 | namespace QuantBox 6 | { 7 | /// 8 | /// 解决使用了 TypeConverter 以后类型无法用 Json.Net 进行系列化的问题 9 | /// 10 | /// 11 | internal class NoTypeConverterJsonConverter : JsonConverter 12 | { 13 | private static readonly IContractResolver Resolver = new NoTypeConverterContractResolver(); 14 | 15 | private class NoTypeConverterContractResolver : DefaultContractResolver 16 | { 17 | protected override JsonContract CreateContract(Type objectType) 18 | { 19 | if (typeof(T).IsAssignableFrom(objectType)) { 20 | var contract = CreateObjectContract(objectType); 21 | // Also null out the converter to prevent infinite recursion. 22 | contract.Converter = null; 23 | return contract; 24 | } 25 | return base.CreateContract(objectType); 26 | } 27 | } 28 | 29 | public override bool CanConvert(Type objectType) 30 | { 31 | return typeof(T).IsAssignableFrom(objectType); 32 | } 33 | 34 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 35 | { 36 | return JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = Resolver }).Deserialize(reader, objectType); 37 | } 38 | 39 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 40 | { 41 | JsonSerializer.CreateDefault(new JsonSerializerSettings { ContractResolver = Resolver }).Serialize(writer, value); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /QuantBox/OnAutoConnect.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class OnAutoConnect : Event 6 | { 7 | public override byte TypeId => XEventType.OnAutoReconnect; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /QuantBox/OnAutoDisconnect.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class OnAutoDisconnect : Event 6 | { 7 | public override byte TypeId => XEventType.OnAutoDisconnect; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /QuantBox/OnClientConnected.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class OnClientConnected : Event 6 | { 7 | public override byte TypeId => XEventType.OnClientConnected; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /QuantBox/OnClientDisconnected.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class OnClientDisconnected : Event 6 | { 7 | public override byte TypeId => XEventType.OnClientDisconnected; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /QuantBox/OptionChainData.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | public class OptionChainData : DataObject 6 | { 7 | public override byte TypeId => OptionChainDataType.OptionChainData; 8 | public readonly byte DataTypeId; 9 | 10 | public OptionChainData() 11 | { 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /QuantBox/OptionChainDataType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | public static class OptionChainDataType 4 | { 5 | public const byte OptionChainData = 255; 6 | public const byte OptionChain = 1; 7 | public const byte MarketData = 2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /QuantBox/OptionStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Text; 3 | using System.Threading.Tasks; 4 | using SmartQuant; 5 | 6 | namespace QuantBox 7 | { 8 | public class OptionStrategy : Strategy 9 | { 10 | public OptionStrategy(Framework framework, string name) 11 | : base(framework, name) 12 | { 13 | } 14 | 15 | protected sealed override void OnUserEvent(Event e) 16 | { 17 | if (e.TypeId == OptionChainDataType.OptionChainData) 18 | { 19 | 20 | } 21 | else 22 | { 23 | OnUserEvent2(e); 24 | } 25 | } 26 | 27 | protected virtual void OnUserEvent2(Event e) 28 | { 29 | 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /QuantBox/OrderAdjust.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox 4 | { 5 | [Flags] 6 | public enum OrderDeviationMode : byte 7 | { 8 | Disabled = 0, 9 | Time, 10 | Trade, 11 | QuoteAndTrade 12 | } 13 | 14 | public enum OrderDeviationMethod : byte 15 | { 16 | Cancel = 0, 17 | PriceAdjust 18 | } 19 | 20 | public enum OrderAdjustFailedMethod : byte 21 | { 22 | Cancel = 0, 23 | Keep 24 | } 25 | 26 | public enum OrderPriceAdjustMethod : byte 27 | { 28 | /// 29 | /// 默认设置 30 | /// 31 | Default = 0, 32 | /// 33 | /// 涨跌停价 34 | /// 35 | UpperLowerLimit, 36 | /// 37 | /// 对手价 38 | /// 39 | MatchPrice 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /QuantBox/OrderMap.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using SmartQuant; 5 | 6 | namespace QuantBox 7 | { 8 | internal class OrderMap : IEnumerable 9 | { 10 | private readonly Dictionary _working = new Dictionary(); 11 | private readonly Dictionary _noSent = new Dictionary(); 12 | 13 | public void AddNewOrder(string id, string orderId, Order order) 14 | { 15 | var record = new OrderRecord(order); 16 | _working.Add(id, record); 17 | if (string.IsNullOrEmpty(orderId)) { 18 | _noSent.Add(id, record); 19 | } 20 | } 21 | 22 | public void RemoveNoSent(string id) 23 | { 24 | _noSent.Remove(id); 25 | } 26 | 27 | public void RemoveDone(string id) 28 | { 29 | _working.Remove(id); 30 | } 31 | 32 | public bool OrderExist(string id) 33 | { 34 | return TryGetOrder(id, out _); 35 | } 36 | 37 | public bool TryGetOrder(string id, out OrderRecord record) 38 | { 39 | return _working.TryGetValue(id, out record); 40 | } 41 | 42 | public List GetNoSent() 43 | { 44 | return _noSent.Values.ToList(); 45 | } 46 | 47 | public IEnumerator GetEnumerator() 48 | { 49 | return _working.Values.GetEnumerator(); 50 | } 51 | 52 | IEnumerator IEnumerable.GetEnumerator() 53 | { 54 | return GetEnumerator(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /QuantBox/OrderOffsetFlag.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | public readonly struct OrderOffsetFlag 4 | { 5 | public readonly bool IsOpen; 6 | public readonly bool IsCloseToday; 7 | 8 | public OrderOffsetFlag(bool isOpen, bool isToday) 9 | { 10 | IsOpen = isOpen; 11 | IsCloseToday = isToday; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /QuantBox/OrderProxy/EmptyDataProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SmartQuant; 7 | 8 | namespace QuantBox.OrderProxy 9 | { 10 | internal class EmptyDataProvider : Provider, IDataProvider 11 | { 12 | public static readonly EmptyDataProvider Instance; 13 | static EmptyDataProvider() 14 | { 15 | Instance = new EmptyDataProvider(null); 16 | } 17 | public EmptyDataProvider(Framework framework) : base(framework) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /QuantBox/OrderProxy/OrderAgentInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using Newtonsoft.Json; 4 | using QuantBox.XApi; 5 | 6 | namespace QuantBox 7 | { 8 | public class OrderAgentInfo 9 | { 10 | private static string GetSettingsFile() 11 | { 12 | return QBHelper.GetConfigPath("orderagent"); 13 | } 14 | 15 | public OrderAgentInfo() 16 | { 17 | Market2Limit.PriceAdjustMethod = OrderPriceAdjustMethod.UpperLowerLimit; 18 | } 19 | 20 | /// 21 | /// 优先平金的交易所列表 22 | /// 23 | public readonly HashSet CloseTodayFirstExchanges = new HashSet { ExchangeNames.CFFEX }; 24 | 25 | /// 26 | /// 支持市价的交易所列表 27 | /// 28 | public readonly HashSet SupportMarketOrderExchanges = new HashSet { 29 | ExchangeNames.SSE, 30 | ExchangeNames.SZSE, 31 | ExchangeNames.DCE, 32 | ExchangeNames.CZCE 33 | }; 34 | 35 | /// 36 | /// 支持市价的交易所列表 37 | /// 38 | public readonly HashSet StrictCloseTodayExchanges = new HashSet { 39 | ExchangeNames.SHFE, 40 | ExchangeNames.INE 41 | }; 42 | 43 | /// 44 | /// 下反手单时,平仓单和开仓单同时发出还是先平后开顺序发出。 45 | /// 46 | public bool CloseFirstOnReversing = false; 47 | 48 | /// 49 | /// 市价转现价 50 | /// 51 | public DeviationInfo Market2Limit; 52 | 53 | public static OrderAgentInfo Load() 54 | { 55 | var settingsFile = GetSettingsFile(); 56 | if (File.Exists(settingsFile)) { 57 | return JsonConvert.DeserializeObject(QBHelper.ReadOnlyAllText(settingsFile)); 58 | } 59 | return new OrderAgentInfo(); 60 | } 61 | 62 | public void Save() 63 | { 64 | File.WriteAllText(GetSettingsFile(), JsonConvert.SerializeObject(this, Formatting.Indented)); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /QuantBox/OrderRecord.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class OrderRecord 6 | { 7 | public OrderRecord(Order order) 8 | { 9 | Order = order; 10 | LeavesQty = (int)order.Qty; 11 | CumQty = order.CumQty; 12 | AvgPx = order.AvgPx; 13 | } 14 | 15 | public readonly Order Order; 16 | 17 | public double LeavesQty; 18 | 19 | public bool Cancelling; 20 | 21 | public double CumQty { get; private set; } 22 | 23 | public double AvgPx { get; private set; } 24 | 25 | public void AddFill(double lastPx, double lastQty) 26 | { 27 | AvgPx = (AvgPx * CumQty + lastPx * lastQty) / (CumQty + lastQty); 28 | LeavesQty -= lastQty; 29 | CumQty += lastQty; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /QuantBox/PortfolioSerializer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using System.Runtime.Serialization; 4 | using LiteDB; 5 | using Skyline; 6 | using SmartQuant; 7 | 8 | namespace QuantBox 9 | { 10 | internal class PortfolioSerializer 11 | { 12 | private static readonly FastFieldInfo id; 13 | private static readonly FastFieldInfo isLoaded; 14 | private static readonly FastFieldInfo parentId; 15 | 16 | static PortfolioSerializer() 17 | { 18 | var fields = new Dictionary(); 19 | foreach (var field in typeof(Portfolio).GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { 20 | var attr = field.GetCustomAttribute(); 21 | if (attr != null) { 22 | fields[attr.Name] = field; 23 | } 24 | } 25 | id = new FastFieldInfo(fields["id"]); 26 | isLoaded = new FastFieldInfo(fields["isLoaded"]); 27 | parentId = new FastFieldInfo(fields["parentId"]); 28 | } 29 | 30 | public static BsonValue ToBson(Portfolio p) 31 | { 32 | var doc = new BsonDocument(); 33 | doc["_id"] = p.Id + 1; 34 | doc["name"] = p.Name; 35 | doc["description"] = p.Description; 36 | doc["parentId"] = p.ParentId; 37 | return doc; 38 | } 39 | 40 | public static Portfolio ToPortfolio(BsonValue value) 41 | { 42 | var doc = (BsonDocument)value; 43 | var p = new Portfolio(doc["name"].AsString); 44 | p.Description = doc["description"].AsString; 45 | id.Setter(p, doc["_id"].AsInt32 - 1); 46 | parentId.Setter(p, doc["parentId"].AsInt32); 47 | isLoaded.Setter(p, true); 48 | return p; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /QuantBox/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("QuantBox.OQ")] 8 | [assembly: AssemblyDescription("QuantBox's OpenQuant Extensions")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("QuantBox")] 11 | [assembly: AssemblyProduct("QuantBox.OQ")] 12 | [assembly: AssemblyCopyright("Copyright © QuantBox 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("5feb5600-7c98-4a76-a885-c21e6a99223e")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("2.0.0.1")] 35 | [assembly: AssemblyFileVersion("1.0.0.1871")] 36 | -------------------------------------------------------------------------------- /QuantBox/QBOptimizeBarFilter.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | internal class QBOptimizeBarFilter : EventFilter 6 | { 7 | private readonly long[] _barSizes; 8 | private readonly long _size; 9 | 10 | public QBOptimizeBarFilter(Framework framework) 11 | : base(framework) 12 | { 13 | _barSizes = DataManagerExtensions.globalOptimizeBarFilter; 14 | if (_barSizes != null && _barSizes.Length == 1) { 15 | _size = _barSizes[0]; 16 | } 17 | } 18 | 19 | public override Event Filter(Event e) 20 | { 21 | if (e.TypeId == DataObjectType.Bar) { 22 | var bar = (Bar)e; 23 | if (bar.Size == _size) { 24 | return e; 25 | } 26 | foreach (var item in _barSizes) { 27 | if (bar.Size == item) { 28 | return e; 29 | } 30 | } 31 | return null; 32 | } 33 | return e; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /QuantBox/StackTraceHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NLog; 3 | using System.Diagnostics; 4 | 5 | namespace QuantBox 6 | { 7 | public static class StackTraceHelper 8 | { 9 | public static void PrintStackTrace(Logger logger = null) 10 | { 11 | var st = new StackTrace(true); 12 | for (int i = 0; i < st.FrameCount; i++) { 13 | // Note that at this level, there are four 14 | // stack frames, one for each method invocation. 15 | var sf = st.GetFrame(i); 16 | var stackIndent = $"Method: {sf.GetMethod()} File: {sf.GetFileName()} Line Number: {sf.GetFileLineNumber()}"; 17 | if (logger != null) { 18 | logger.Debug(stackIndent); 19 | } 20 | else { 21 | Console.WriteLine(stackIndent); 22 | } 23 | } 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /QuantBox/StatisticsManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SmartQuant; 7 | 8 | namespace QuantBox 9 | { 10 | public static class StatisticsManagerExtensions 11 | { 12 | public static void Change(this StatisticsManager manager, int type, PortfolioStatisticsItem statisticsItem) 13 | { 14 | var i = (ICustomStatisticsType)statisticsItem; 15 | i.SetStatisticsType(type); 16 | manager.Add(statisticsItem); 17 | } 18 | 19 | public static void AddStatisticsItem(this StatisticsManager manager, PortfolioStatisticsItem statisticsItem) 20 | { 21 | var i = (ICustomStatisticsType)statisticsItem; 22 | if (i != null) { 23 | var max = 0; 24 | foreach (var item in manager.Statistics) { 25 | if (item.GetType() == statisticsItem.GetType()) { 26 | return; 27 | } 28 | max = Math.Max(max, item.Type); 29 | } 30 | i.SetStatisticsType(max + 1); 31 | } 32 | manager.Add(statisticsItem); 33 | } 34 | 35 | public static void RemoveStatisticsItem(this StatisticsManager manager, Type type) 36 | { 37 | var typeId = 0; 38 | foreach (var item in manager.Statistics) { 39 | if (item.GetType() == type) { 40 | typeId = item.Type; 41 | } 42 | } 43 | if (typeId > 0) { 44 | manager.Remove(typeId); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /QuantBox/StopExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using Skyline; 5 | using SmartQuant; 6 | 7 | namespace QuantBox 8 | { 9 | public static class StopExtensions 10 | { 11 | private static readonly FastFieldInfo QtyField; 12 | private static readonly FastFieldInfo StrategyField; 13 | private static readonly FastFieldInfo CreationTimeField; 14 | 15 | static StopExtensions() 16 | { 17 | var creationTimeField = typeof(Stop).GetField("creationTime", BindingFlags.Instance | BindingFlags.NonPublic); 18 | if (creationTimeField != null) { 19 | CreationTimeField = new FastFieldInfo(creationTimeField); 20 | } 21 | var strategyField = typeof(Stop).GetField("strategy", BindingFlags.Instance | BindingFlags.NonPublic); 22 | if (strategyField != null) { 23 | StrategyField = new FastFieldInfo(strategyField); 24 | } 25 | var qtyField = typeof(Stop).GetField("qty", BindingFlags.Instance | BindingFlags.NonPublic); 26 | if (qtyField != null) { 27 | QtyField = new FastFieldInfo(qtyField); 28 | } 29 | } 30 | 31 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 32 | public static void SetQty(this Stop s, double qty) 33 | { 34 | QtyField?.Setter(s, qty); 35 | } 36 | 37 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 38 | public static void SetStrategy(this Stop s, Strategy strategy) 39 | { 40 | StrategyField?.Setter(s, strategy); 41 | } 42 | 43 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 44 | public static void SetCreationTime(this Stop s, DateTime dateTime) 45 | { 46 | CreationTimeField?.Setter(s, dateTime); 47 | } 48 | 49 | internal static byte[] GetObjectId(this Stop s) 50 | { 51 | return (byte[])s.Fields[QuantBoxConst.StopIdOffset]; 52 | } 53 | 54 | internal static void SetObjectId(this Stop s, byte[] id) 55 | { 56 | s.Fields[QuantBoxConst.StopIdOffset] = id; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /QuantBox/StopStrategy.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace QuantBox 3 | { 4 | using SmartQuant; 5 | 6 | internal class StopStrategy : Strategy 7 | { 8 | public StopStrategy(Framework framework, Strategy strategy, string name) 9 | : base(framework, name) 10 | { 11 | RealStrategy = strategy; 12 | } 13 | 14 | public Strategy RealStrategy { get; } 15 | 16 | protected override void OnStopStatusChanged_(Stop stop) 17 | { 18 | stop.SetStrategy(RealStrategy); 19 | RealStrategy.CallStopStatusChanged(stop); 20 | StrategyServer.RemoveStop(stop); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /QuantBox/TickSizeSlippageProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using NLog; 4 | using SmartQuant; 5 | 6 | namespace QuantBox 7 | { 8 | public class TickSizeSlippageProvider : ISlippageProvider 9 | { 10 | public double Slippage { get; set; } 11 | 12 | public IdArray InstrumentSlippages { get; set; } = new IdArray(); 13 | 14 | public TickSizeSlippageProvider SetDefault(double slippage) 15 | { 16 | Slippage = slippage; 17 | return this; 18 | } 19 | 20 | public TickSizeSlippageProvider AddSlippage(Instrument instrument, double slippage) 21 | { 22 | InstrumentSlippages[instrument.Id] = Math.Max(slippage, 0); 23 | return this; 24 | } 25 | 26 | public TickSizeSlippageProvider DisableSlippage(Instrument instrument) 27 | { 28 | InstrumentSlippages[instrument.Id] = -1; 29 | return this; 30 | } 31 | 32 | public double GetPrice(ExecutionReport report) 33 | { 34 | var slippage = InstrumentSlippages[report.InstrumentId]; 35 | if (Math.Abs(slippage) < double.Epsilon) { 36 | slippage = Slippage; 37 | } 38 | else if (slippage < 0){ 39 | slippage = 0; 40 | } 41 | var offset = slippage * report.Instrument.TickSize; 42 | double price = report.LastPx; 43 | switch (report.Side) { 44 | case OrderSide.Buy: 45 | price += offset; 46 | break; 47 | case OrderSide.Sell: 48 | price -= offset; 49 | break; 50 | } 51 | return price; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /QuantBox/TimeRange.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox 4 | { 5 | public class TimeRange 6 | { 7 | public TimeSpan Begin { get; set; } 8 | public TimeSpan End { get; set; } 9 | public bool IsOpen { get; set; } 10 | public bool IsClose { get; set; } 11 | public bool IsNight { get; set; } 12 | 13 | public TimeRange(TimeSpan begin, TimeSpan end, bool open = false, bool close = false, bool night = false) 14 | { 15 | Begin = begin; 16 | End = end; 17 | IsOpen = open; 18 | IsClose = close; 19 | IsNight = night; 20 | } 21 | 22 | public TimeRange() 23 | { 24 | } 25 | 26 | public TimeRange Clone() 27 | { 28 | return (TimeRange)MemberwiseClone(); 29 | } 30 | 31 | public override string ToString() 32 | { 33 | return $"Start={Begin};End={End}"; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /QuantBox/TimeSeriesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using Skyline; 5 | using SmartQuant; 6 | 7 | namespace QuantBox 8 | { 9 | public static class TimeSeriesExtensions 10 | { 11 | public static void Save(this TimeSeries s, string filename) 12 | { 13 | using (var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write)) { 14 | Save(s, fs); 15 | } 16 | } 17 | 18 | public static void Save(this TimeSeries s, Stream stream) 19 | { 20 | using (var writer = new BinaryWriter(stream)) { 21 | for (var i = 0; i < s.Count; i++) { 22 | var item = s.GetItem(i); 23 | writer.Write(item.DateTime.Ticks); 24 | writer.Write(item.Value); 25 | } 26 | } 27 | } 28 | 29 | public static void Load(this TimeSeries s, string filename) 30 | { 31 | using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { 32 | Load(s, fs); 33 | } 34 | } 35 | 36 | public static void Load(this TimeSeries s, Stream stream) 37 | { 38 | using (var reader = new BinaryReader(stream)) { 39 | while (reader.PeekChar() != -1) { 40 | s.Add(new DateTime(reader.ReadInt64()), reader.ReadDouble()); 41 | } 42 | } 43 | } 44 | 45 | } 46 | } -------------------------------------------------------------------------------- /QuantBox/TraderClient.cs: -------------------------------------------------------------------------------- 1 | using QuantBox.XApi; 2 | using SmartQuant; 3 | 4 | namespace QuantBox 5 | { 6 | public class TraderClient : XApiClient 7 | { 8 | public static ApiType ApiType => ApiType.Trade; 9 | 10 | public TraderClient(XProvider provider, ConnectionInfo info, IXSpi spi = null) 11 | : base(provider, info, spi) 12 | { 13 | } 14 | 15 | public string CancelOrder(string orderId) 16 | { 17 | return api.CancelOrder(orderId); 18 | } 19 | 20 | public string SendOrder(OrderField order) 21 | { 22 | return api.SendOrder(order); 23 | } 24 | 25 | public void QueryAccount() 26 | { 27 | if (Connected) { 28 | api.Query(QueryType.ReqQryTradingAccount, null); 29 | } 30 | } 31 | 32 | public void QueryPositions() 33 | { 34 | if (Connected) { 35 | api.Query(QueryType.ReqQryInvestorPosition, null); 36 | } 37 | } 38 | 39 | public void QueryOrders() 40 | { 41 | if (Connected) { 42 | api.Query(QueryType.ReqQryOrder, null); 43 | } 44 | } 45 | 46 | public void QueryTrades() 47 | { 48 | if (Connected) { 49 | api.Query(QueryType.ReqQryTrade, null); 50 | } 51 | } 52 | 53 | public void QueryQuote(Instrument inst) 54 | { 55 | if (Connected) { 56 | var (symbol, exchange) = Provider.GetSymbolInfo(inst); 57 | api.Query(QueryType.ReqQryQuote, new ReqQueryField { 58 | ExchangeID = exchange, 59 | InstrumentID = symbol, 60 | Symbol = symbol 61 | }); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /QuantBox/TradesCost.cs: -------------------------------------------------------------------------------- 1 | using SmartQuant; 2 | 3 | namespace QuantBox 4 | { 5 | public class TradesCost : PortfolioStatisticsItem, ICustomStatisticsType 6 | { 7 | public static int TypeId; 8 | 9 | protected override void OnRoundTrip(TradeInfo trade) 10 | { 11 | var cost = trade.EntryCost + trade.ExitCost; 12 | if (trade.IsLong) { 13 | longValue += cost; 14 | longValues.Add(Clock.DateTime, longValue); 15 | } 16 | else { 17 | shortValue += cost; 18 | shortValues.Add(Clock.DateTime, shortValue); 19 | } 20 | totalValue += cost; 21 | totalValues.Add(Clock.DateTime, totalValue); 22 | Emit(); 23 | } 24 | 25 | public override string Category 26 | { 27 | get 28 | { 29 | return "Trades"; 30 | } 31 | } 32 | 33 | public override string Name 34 | { 35 | get 36 | { 37 | return "Trades Cost"; 38 | } 39 | } 40 | 41 | public override int Type 42 | { 43 | get 44 | { 45 | return TypeId; 46 | } 47 | } 48 | 49 | public void SetStatisticsType(int type) 50 | { 51 | TypeId = type; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /QuantBox/TradingTimeRangeSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Skyline; 5 | using SmartQuant; 6 | 7 | namespace QuantBox 8 | { 9 | public class TimeRangeSelector 10 | { 11 | private readonly IList _list; 12 | private TradingTimeRange _last; 13 | 14 | public TimeRangeSelector(Instrument inst) 15 | { 16 | _list = TradingCalendar.Instance.GetTimeRanges(inst); 17 | } 18 | 19 | public TradingTimeRange Get(DateTime dateTime) 20 | { 21 | _last = TradingCalendar.Instance.GetTimeRange(_list, _last, dateTime); 22 | return _last; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /QuantBox/UserInfo.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Runtime.Serialization; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Linq; 5 | #if NETFRAMEWORK 6 | using QuantBox.Design; 7 | #endif 8 | using QuantBox.XApi; 9 | 10 | namespace QuantBox 11 | { 12 | [DefaultProperty("Label")] 13 | #if NETFRAMEWORK 14 | [TypeConverter(typeof(UserInfoConverter))] 15 | #endif 16 | [JsonConverter(typeof(NoTypeConverterJsonConverter))] 17 | [DataContract] 18 | public class UserInfo 19 | { 20 | [Category("标签")] 21 | [DataMember] 22 | public string Label { get; set; } 23 | [Category("账号")] 24 | [DataMember] 25 | public string UserId { get; set; } 26 | [Category("账号")] 27 | [DataMember] 28 | public string Password { get; set; } 29 | [Category("账号")] 30 | [DataMember] 31 | public string AccountId { get; set; } 32 | [Category("账号")] 33 | [DataMember] 34 | public string CombinationId { get; set; } 35 | [Category("账号")] 36 | [DataMember] 37 | public string AssetId { get; set; } 38 | 39 | public UserInfoField Get() 40 | { 41 | var field = new UserInfoField { 42 | UserID = UserId, 43 | Password = Password 44 | }; 45 | return field; 46 | } 47 | 48 | public override string ToString() 49 | { 50 | return string.IsNullOrEmpty(Label) ? "空用户" : Label; 51 | } 52 | 53 | public UserInfo Clone() 54 | { 55 | return (UserInfo)MemberwiseClone(); 56 | } 57 | 58 | public static UserInfo Load(JToken token) 59 | { 60 | var user = new UserInfo(); 61 | QBHelper.LoadFromJson(user, typeof(UserInfo), token); 62 | return user; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /QuantBox/XApiEventType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | internal static class XApiEventType 4 | { 5 | public const byte OnFrontConnected = 250; 6 | public const byte OnFrontDisconnected = 251; 7 | } 8 | } -------------------------------------------------------------------------------- /QuantBox/XEventType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | internal static class XEventType 4 | { 5 | public const byte OnClientConnected = 250; 6 | public const byte OnClientDisconnected = 251; 7 | public const byte OnAutoReconnect = 252; 8 | public const byte OnAutoDisconnect = 253; 9 | } 10 | } -------------------------------------------------------------------------------- /QuantBox/XProviderEventType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox 2 | { 3 | public enum XProviderEventType : byte 4 | { 5 | AutoDisconnect, 6 | TraderCreated, 7 | ConnectDone, 8 | DisconnectDone, 9 | MarketBeforeTrading = 48, 10 | MarketNoTrading = 49, 11 | MarketContinuous = 50, 12 | MarketAuctionOrdering = 51, 13 | MarketAuctionBalance = 52, 14 | MarketAuctionMatch = 53, 15 | MarketClosed = 54 16 | } 17 | } -------------------------------------------------------------------------------- /QuantBox/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /QuantBox/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /SfitCtpseQuote/CtpQuote.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace QuantBox.XApi 5 | { 6 | public class CtpQuote : IXApi 7 | { 8 | private CtpMdClient _client; 9 | 10 | public void RegisterSpi(IXSpi spi) 11 | { 12 | if (_client != null) { 13 | return; 14 | } 15 | _client = new CtpMdClient(spi); 16 | } 17 | 18 | public void Release() 19 | { 20 | Disconnect(); 21 | _client = null; 22 | } 23 | 24 | public void Connect(ServerInfoField server, UserInfoField user) 25 | { 26 | _client?.Init(server, user); 27 | } 28 | 29 | public void Disconnect() 30 | { 31 | _client?.Release(); 32 | } 33 | 34 | public void Query(QueryType type, ReqQueryField query) 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | 39 | public void Subscribe(string instrument, string exchange, InstrumentType type) 40 | { 41 | _client?.Subscribe(instrument); 42 | } 43 | 44 | public void Unsubscribe(string instrument, string exchange, InstrumentType type) 45 | { 46 | _client?.Unsubscribe(instrument); 47 | } 48 | 49 | public string SendOrder(params OrderField[] orders) 50 | { 51 | throw new NotImplementedException(); 52 | } 53 | 54 | public string CancelOrder(params string[] list) 55 | { 56 | throw new NotImplementedException(); 57 | } 58 | 59 | public string ApiVersion => XApiHelper.GetVersionString(typeof(CtpQuote)); 60 | public ApiType ApiTypes => ApiType.MarketData; 61 | #if CTP || CTPSE 62 | public string ApiName => "CTP"; 63 | #elif CTPMINI 64 | public string ApiName => "CTPMINI"; 65 | #else 66 | public string ApiName => "Rohon"; 67 | #endif 68 | public bool Connected => _client?.Connected ?? false; 69 | public ServerInfoField Server => _client?.Server; 70 | public UserInfoField User => _client?.User; 71 | public RspUserLoginField UserLogin => _client?.UserLogin; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /SfitCtpseQuote/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("SfitCtpse.Quote")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("quantbox")] 11 | [assembly: AssemblyProduct("SfitCtpse.Quote")] 12 | [assembly: AssemblyCopyright("Copyright © quantbox 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("31e28ffd-7eb6-4c51-906f-f819afd38ffe")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /SfitCtpseQuote/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SfitCtpseQuote/sfit_ctpse_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseQuote/sfit_ctpse_x64.dll -------------------------------------------------------------------------------- /SfitCtpseQuote/thostmduserapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseQuote/thostmduserapi_se.dll -------------------------------------------------------------------------------- /SfitCtpseQuote/thosttraderapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseQuote/thosttraderapi_se.dll -------------------------------------------------------------------------------- /SfitCtpseTrader/OrderMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace QuantBox.XApi 5 | { 6 | internal class OrderMap 7 | { 8 | private readonly Dictionary _orders = new Dictionary(); 9 | private readonly Dictionary _ordersBySysId = new Dictionary(); 10 | private readonly Dictionary _orderRefMap = new Dictionary(); 11 | 12 | public void AddOrder(OrderField order) 13 | { 14 | _orders[order.ID] = order; 15 | _orderRefMap[order.LocalID] = order.ID; 16 | } 17 | 18 | public bool TryGetById(string id, out OrderField order) 19 | { 20 | return _orders.TryGetValue(id, out order); 21 | } 22 | 23 | public bool TryGetByOrderRef(string orderRef, out OrderField order) 24 | { 25 | order = null; 26 | return _orderRefMap.TryGetValue(orderRef, out var id) && TryGetById(id, out order); 27 | } 28 | 29 | public bool TryGetBySysId(string orderSysId, out OrderField order) 30 | { 31 | return _ordersBySysId.TryGetValue(orderSysId, out order); 32 | } 33 | 34 | public void SetMap(OrderField order) 35 | { 36 | _ordersBySysId[order.OrderID] = order; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /SfitCtpseTrader/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("SfitCtpse.Trader")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("qauntbox")] 11 | [assembly: AssemblyProduct("SfitCtpse.Trader")] 12 | [assembly: AssemblyCopyright("Copyright © qauntbox 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("d9e7f267-6b17-4ef4-8180-3d1a20712a53")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /SfitCtpseTrader/StatusPublisher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks.Dataflow; 3 | 4 | namespace QuantBox.XApi 5 | { 6 | internal class StatusPublisher 7 | { 8 | private readonly IXSpi _spi; 9 | private readonly ActionBlock<(ConnectionStatus, RspUserLoginField)> _statusAction; 10 | 11 | private void StatusAction((ConnectionStatus status, RspUserLoginField login) data) 12 | { 13 | _spi.ProcessConnectionStatus(data.status, data.login); 14 | } 15 | 16 | public StatusPublisher(IXSpi spi) 17 | { 18 | _spi = spi; 19 | _statusAction = new ActionBlock<(ConnectionStatus, RspUserLoginField)>(StatusAction, DataflowHelper.SpscBlockOptions); 20 | } 21 | 22 | public void Post(ConnectionStatus status, RspUserLoginField field = null) 23 | { 24 | _statusAction.Post((status, field)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /SfitCtpseTrader/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SfitCtpseTrader/sfit_ctpse_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseTrader/sfit_ctpse_x64.dll -------------------------------------------------------------------------------- /SfitCtpseTrader/thostmduserapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseTrader/thostmduserapi_se.dll -------------------------------------------------------------------------------- /SfitCtpseTrader/thosttraderapi_se.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/SfitCtpseTrader/thosttraderapi_se.dll -------------------------------------------------------------------------------- /TALib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TaLib4OpenQuant")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("quantbox.cn")] 12 | [assembly: AssemblyProduct("TaLib4OpenQuant")] 13 | [assembly: AssemblyCopyright("quantbox.cn")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9cc9819d-bf7b-4730-bdeb-61037b521926")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.1")] 37 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Acos.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Acos(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Acos(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Acos(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Acos((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int AcosLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Add.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Add(int startIdx, int endIdx, double[] inReal0, double[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal0 == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (inReal1 == null) { 18 | return RetCode.BadParam; 19 | } 20 | if (outReal == null) { 21 | return RetCode.BadParam; 22 | } 23 | int i = startIdx; 24 | int outIdx = 0; 25 | while (i <= endIdx) { 26 | outReal[outIdx] = inReal0[i] + inReal1[i]; 27 | i++; 28 | outIdx++; 29 | } 30 | outNBElement = outIdx; 31 | outBegIdx = startIdx; 32 | return RetCode.Success; 33 | } 34 | public static RetCode Add(int startIdx, int endIdx, float[] inReal0, float[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 35 | { 36 | if (startIdx < 0) { 37 | return RetCode.OutOfRangeStartIndex; 38 | } 39 | if ((endIdx < 0) || (endIdx < startIdx)) { 40 | return RetCode.OutOfRangeEndIndex; 41 | } 42 | if (inReal0 == null) { 43 | return RetCode.BadParam; 44 | } 45 | if (inReal1 == null) { 46 | return RetCode.BadParam; 47 | } 48 | if (outReal == null) { 49 | return RetCode.BadParam; 50 | } 51 | int i = startIdx; 52 | int outIdx = 0; 53 | while (i <= endIdx) { 54 | outReal[outIdx] = inReal0[i] + inReal1[i]; 55 | i++; 56 | outIdx++; 57 | } 58 | outNBElement = outIdx; 59 | outBegIdx = startIdx; 60 | return RetCode.Success; 61 | } 62 | public static int AddLookback() 63 | { 64 | return 0; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Asin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Asin(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Asin(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Asin(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Asin((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int AsinLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Atan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Atan(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Atan(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Atan(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Atan((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int AtanLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_AvgPrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode AvgPrice(int startIdx, int endIdx, double[] inOpen, double[] inHigh, double[] inLow, double[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (((inOpen == null) || (inHigh == null)) || ((inLow == null) || (inClose == null))) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int outIdx = 0; 21 | for (int i = startIdx; i <= endIdx; i++) { 22 | outReal[outIdx] = (((inHigh[i] + inLow[i]) + inClose[i]) + inOpen[i]) / 4.0; 23 | outIdx++; 24 | } 25 | outNBElement = outIdx; 26 | outBegIdx = startIdx; 27 | return RetCode.Success; 28 | } 29 | public static RetCode AvgPrice(int startIdx, int endIdx, float[] inOpen, float[] inHigh, float[] inLow, float[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 30 | { 31 | if (startIdx < 0) { 32 | return RetCode.OutOfRangeStartIndex; 33 | } 34 | if ((endIdx < 0) || (endIdx < startIdx)) { 35 | return RetCode.OutOfRangeEndIndex; 36 | } 37 | if (((inOpen == null) || (inHigh == null)) || ((inLow == null) || (inClose == null))) { 38 | return RetCode.BadParam; 39 | } 40 | if (outReal == null) { 41 | return RetCode.BadParam; 42 | } 43 | int outIdx = 0; 44 | for (int i = startIdx; i <= endIdx; i++) { 45 | outReal[outIdx] = (((inHigh[i] + inLow[i]) + inClose[i]) + inOpen[i]) / 4.0; 46 | outIdx++; 47 | } 48 | outNBElement = outIdx; 49 | outBegIdx = startIdx; 50 | return RetCode.Success; 51 | } 52 | public static int AvgPriceLookback() 53 | { 54 | return 0; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Ceil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Ceil(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Ceiling(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Ceil(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Ceiling((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int CeilLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Cos.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Cos(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Cos(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Cos(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Cos((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int CosLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Cosh.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Cosh(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Cosh(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Cosh(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Cosh((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int CoshLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Div.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Div(int startIdx, int endIdx, double[] inReal0, double[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal0 == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (inReal1 == null) { 18 | return RetCode.BadParam; 19 | } 20 | if (outReal == null) { 21 | return RetCode.BadParam; 22 | } 23 | int i = startIdx; 24 | int outIdx = 0; 25 | while (i <= endIdx) { 26 | outReal[outIdx] = inReal0[i] / inReal1[i]; 27 | i++; 28 | outIdx++; 29 | } 30 | outNBElement = outIdx; 31 | outBegIdx = startIdx; 32 | return RetCode.Success; 33 | } 34 | public static RetCode Div(int startIdx, int endIdx, float[] inReal0, float[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 35 | { 36 | if (startIdx < 0) { 37 | return RetCode.OutOfRangeStartIndex; 38 | } 39 | if ((endIdx < 0) || (endIdx < startIdx)) { 40 | return RetCode.OutOfRangeEndIndex; 41 | } 42 | if (inReal0 == null) { 43 | return RetCode.BadParam; 44 | } 45 | if (inReal1 == null) { 46 | return RetCode.BadParam; 47 | } 48 | if (outReal == null) { 49 | return RetCode.BadParam; 50 | } 51 | int i = startIdx; 52 | int outIdx = 0; 53 | while (i <= endIdx) { 54 | outReal[outIdx] = ((double)inReal0[i]) / ((double)inReal1[i]); 55 | i++; 56 | outIdx++; 57 | } 58 | outNBElement = outIdx; 59 | outBegIdx = startIdx; 60 | return RetCode.Success; 61 | } 62 | public static int DivLookback() 63 | { 64 | return 0; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Exp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Exp(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Exp(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Exp(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Exp((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int ExpLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Floor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Floor(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Floor(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Floor(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Floor((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int FloorLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Ln.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Ln(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Log(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Ln(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Log((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int LnLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Log10.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Log10(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Log10(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Log10(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Log10((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int Log10Lookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_MedPrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode MedPrice(int startIdx, int endIdx, double[] inHigh, double[] inLow, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if ((inHigh == null) || (inLow == null)) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int outIdx = 0; 21 | for (int i = startIdx; i <= endIdx; i++) { 22 | outReal[outIdx] = (inHigh[i] + inLow[i]) / 2.0; 23 | outIdx++; 24 | } 25 | outNBElement = outIdx; 26 | outBegIdx = startIdx; 27 | return RetCode.Success; 28 | } 29 | public static RetCode MedPrice(int startIdx, int endIdx, float[] inHigh, float[] inLow, ref int outBegIdx, ref int outNBElement, double[] outReal) 30 | { 31 | if (startIdx < 0) { 32 | return RetCode.OutOfRangeStartIndex; 33 | } 34 | if ((endIdx < 0) || (endIdx < startIdx)) { 35 | return RetCode.OutOfRangeEndIndex; 36 | } 37 | if ((inHigh == null) || (inLow == null)) { 38 | return RetCode.BadParam; 39 | } 40 | if (outReal == null) { 41 | return RetCode.BadParam; 42 | } 43 | int outIdx = 0; 44 | for (int i = startIdx; i <= endIdx; i++) { 45 | outReal[outIdx] = (inHigh[i] + inLow[i]) / 2.0; 46 | outIdx++; 47 | } 48 | outNBElement = outIdx; 49 | outBegIdx = startIdx; 50 | return RetCode.Success; 51 | } 52 | public static int MedPriceLookback() 53 | { 54 | return 0; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Mult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Mult(int startIdx, int endIdx, double[] inReal0, double[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal0 == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (inReal1 == null) { 18 | return RetCode.BadParam; 19 | } 20 | if (outReal == null) { 21 | return RetCode.BadParam; 22 | } 23 | int i = startIdx; 24 | int outIdx = 0; 25 | while (i <= endIdx) { 26 | outReal[outIdx] = inReal0[i] * inReal1[i]; 27 | i++; 28 | outIdx++; 29 | } 30 | outNBElement = outIdx; 31 | outBegIdx = startIdx; 32 | return RetCode.Success; 33 | } 34 | public static RetCode Mult(int startIdx, int endIdx, float[] inReal0, float[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 35 | { 36 | if (startIdx < 0) { 37 | return RetCode.OutOfRangeStartIndex; 38 | } 39 | if ((endIdx < 0) || (endIdx < startIdx)) { 40 | return RetCode.OutOfRangeEndIndex; 41 | } 42 | if (inReal0 == null) { 43 | return RetCode.BadParam; 44 | } 45 | if (inReal1 == null) { 46 | return RetCode.BadParam; 47 | } 48 | if (outReal == null) { 49 | return RetCode.BadParam; 50 | } 51 | int i = startIdx; 52 | int outIdx = 0; 53 | while (i <= endIdx) { 54 | outReal[outIdx] = inReal0[i] * inReal1[i]; 55 | i++; 56 | outIdx++; 57 | } 58 | outNBElement = outIdx; 59 | outBegIdx = startIdx; 60 | return RetCode.Success; 61 | } 62 | public static int MultLookback() 63 | { 64 | return 0; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Sin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Sin(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Sin(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Sin(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Sin((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int SinLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Sinh.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Sinh(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Sinh(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Sinh(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Sinh((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int SinhLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Sma.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Sma(int startIdx, int endIdx, double[] inReal, int optInTimePeriod, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (optInTimePeriod == -2147483648) { 18 | optInTimePeriod = 30; 19 | } 20 | else if ((optInTimePeriod < 2) || (optInTimePeriod > 0x186a0)) { 21 | return RetCode.BadParam; 22 | } 23 | if (outReal == null) { 24 | return RetCode.BadParam; 25 | } 26 | return TA_INT_SMA(startIdx, endIdx, inReal, optInTimePeriod, ref outBegIdx, ref outNBElement, outReal); 27 | } 28 | public static RetCode Sma(int startIdx, int endIdx, float[] inReal, int optInTimePeriod, ref int outBegIdx, ref int outNBElement, double[] outReal) 29 | { 30 | if (startIdx < 0) { 31 | return RetCode.OutOfRangeStartIndex; 32 | } 33 | if ((endIdx < 0) || (endIdx < startIdx)) { 34 | return RetCode.OutOfRangeEndIndex; 35 | } 36 | if (inReal == null) { 37 | return RetCode.BadParam; 38 | } 39 | if (optInTimePeriod == -2147483648) { 40 | optInTimePeriod = 30; 41 | } 42 | else if ((optInTimePeriod < 2) || (optInTimePeriod > 0x186a0)) { 43 | return RetCode.BadParam; 44 | } 45 | if (outReal == null) { 46 | return RetCode.BadParam; 47 | } 48 | return TA_INT_SMA(startIdx, endIdx, inReal, optInTimePeriod, ref outBegIdx, ref outNBElement, outReal); 49 | } 50 | public static int SmaLookback(int optInTimePeriod) 51 | { 52 | if (optInTimePeriod == -2147483648) { 53 | optInTimePeriod = 30; 54 | } 55 | else if ((optInTimePeriod < 2) || (optInTimePeriod > 0x186a0)) { 56 | return -1; 57 | } 58 | return (optInTimePeriod - 1); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Sqrt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Sqrt(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Sqrt(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Sqrt(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Sqrt((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int SqrtLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Sub.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Sub(int startIdx, int endIdx, double[] inReal0, double[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal0 == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (inReal1 == null) { 18 | return RetCode.BadParam; 19 | } 20 | if (outReal == null) { 21 | return RetCode.BadParam; 22 | } 23 | int i = startIdx; 24 | int outIdx = 0; 25 | while (i <= endIdx) { 26 | outReal[outIdx] = inReal0[i] - inReal1[i]; 27 | i++; 28 | outIdx++; 29 | } 30 | outNBElement = outIdx; 31 | outBegIdx = startIdx; 32 | return RetCode.Success; 33 | } 34 | public static RetCode Sub(int startIdx, int endIdx, float[] inReal0, float[] inReal1, ref int outBegIdx, ref int outNBElement, double[] outReal) 35 | { 36 | if (startIdx < 0) { 37 | return RetCode.OutOfRangeStartIndex; 38 | } 39 | if ((endIdx < 0) || (endIdx < startIdx)) { 40 | return RetCode.OutOfRangeEndIndex; 41 | } 42 | if (inReal0 == null) { 43 | return RetCode.BadParam; 44 | } 45 | if (inReal1 == null) { 46 | return RetCode.BadParam; 47 | } 48 | if (outReal == null) { 49 | return RetCode.BadParam; 50 | } 51 | int i = startIdx; 52 | int outIdx = 0; 53 | while (i <= endIdx) { 54 | outReal[outIdx] = inReal0[i] - inReal1[i]; 55 | i++; 56 | outIdx++; 57 | } 58 | outNBElement = outIdx; 59 | outBegIdx = startIdx; 60 | return RetCode.Success; 61 | } 62 | public static int SubLookback() 63 | { 64 | return 0; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Tan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Tan(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Tan(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Tan(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Tan((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int TanLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_Tanh.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode Tanh(int startIdx, int endIdx, double[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (inReal == null) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int i = startIdx; 21 | int outIdx = 0; 22 | while (i <= endIdx) { 23 | outReal[outIdx] = Math.Tanh(inReal[i]); 24 | i++; 25 | outIdx++; 26 | } 27 | outNBElement = outIdx; 28 | outBegIdx = startIdx; 29 | return RetCode.Success; 30 | } 31 | public static RetCode Tanh(int startIdx, int endIdx, float[] inReal, ref int outBegIdx, ref int outNBElement, double[] outReal) 32 | { 33 | if (startIdx < 0) { 34 | return RetCode.OutOfRangeStartIndex; 35 | } 36 | if ((endIdx < 0) || (endIdx < startIdx)) { 37 | return RetCode.OutOfRangeEndIndex; 38 | } 39 | if (inReal == null) { 40 | return RetCode.BadParam; 41 | } 42 | if (outReal == null) { 43 | return RetCode.BadParam; 44 | } 45 | int i = startIdx; 46 | int outIdx = 0; 47 | while (i <= endIdx) { 48 | outReal[outIdx] = Math.Tanh((double)inReal[i]); 49 | i++; 50 | outIdx++; 51 | } 52 | outNBElement = outIdx; 53 | outBegIdx = startIdx; 54 | return RetCode.Success; 55 | } 56 | public static int TanhLookback() 57 | { 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_TypPrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode TypPrice(int startIdx, int endIdx, double[] inHigh, double[] inLow, double[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (((inHigh == null) || (inLow == null)) || (inClose == null)) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int outIdx = 0; 21 | for (int i = startIdx; i <= endIdx; i++) { 22 | outReal[outIdx] = ((inHigh[i] + inLow[i]) + inClose[i]) / 3.0; 23 | outIdx++; 24 | } 25 | outNBElement = outIdx; 26 | outBegIdx = startIdx; 27 | return RetCode.Success; 28 | } 29 | public static RetCode TypPrice(int startIdx, int endIdx, float[] inHigh, float[] inLow, float[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 30 | { 31 | if (startIdx < 0) { 32 | return RetCode.OutOfRangeStartIndex; 33 | } 34 | if ((endIdx < 0) || (endIdx < startIdx)) { 35 | return RetCode.OutOfRangeEndIndex; 36 | } 37 | if (((inHigh == null) || (inLow == null)) || (inClose == null)) { 38 | return RetCode.BadParam; 39 | } 40 | if (outReal == null) { 41 | return RetCode.BadParam; 42 | } 43 | int outIdx = 0; 44 | for (int i = startIdx; i <= endIdx; i++) { 45 | outReal[outIdx] = ((inHigh[i] + inLow[i]) + inClose[i]) / 3.0; 46 | outIdx++; 47 | } 48 | outNBElement = outIdx; 49 | outBegIdx = startIdx; 50 | return RetCode.Success; 51 | } 52 | public static int TypPriceLookback() 53 | { 54 | return 0; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TALib/TAFunc/TA_WclPrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace TaLib 3 | { 4 | public partial class Core 5 | { 6 | public static RetCode WclPrice(int startIdx, int endIdx, double[] inHigh, double[] inLow, double[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 7 | { 8 | if (startIdx < 0) { 9 | return RetCode.OutOfRangeStartIndex; 10 | } 11 | if ((endIdx < 0) || (endIdx < startIdx)) { 12 | return RetCode.OutOfRangeEndIndex; 13 | } 14 | if (((inHigh == null) || (inLow == null)) || (inClose == null)) { 15 | return RetCode.BadParam; 16 | } 17 | if (outReal == null) { 18 | return RetCode.BadParam; 19 | } 20 | int outIdx = 0; 21 | for (int i = startIdx; i <= endIdx; i++) { 22 | outReal[outIdx] = ((inHigh[i] + inLow[i]) + (inClose[i] * 2.0)) / 4.0; 23 | outIdx++; 24 | } 25 | outNBElement = outIdx; 26 | outBegIdx = startIdx; 27 | return RetCode.Success; 28 | } 29 | public static RetCode WclPrice(int startIdx, int endIdx, float[] inHigh, float[] inLow, float[] inClose, ref int outBegIdx, ref int outNBElement, double[] outReal) 30 | { 31 | if (startIdx < 0) { 32 | return RetCode.OutOfRangeStartIndex; 33 | } 34 | if ((endIdx < 0) || (endIdx < startIdx)) { 35 | return RetCode.OutOfRangeEndIndex; 36 | } 37 | if (((inHigh == null) || (inLow == null)) || (inClose == null)) { 38 | return RetCode.BadParam; 39 | } 40 | if (outReal == null) { 41 | return RetCode.BadParam; 42 | } 43 | int outIdx = 0; 44 | for (int i = startIdx; i <= endIdx; i++) { 45 | outReal[outIdx] = ((inHigh[i] + inLow[i]) + (inClose[i] * 2.0)) / 4.0; 46 | outIdx++; 47 | } 48 | outNBElement = outIdx; 49 | outBegIdx = startIdx; 50 | return RetCode.Success; 51 | } 52 | public static int WclPriceLookback() 53 | { 54 | return 0; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /TALib/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SmartQuant; 7 | 8 | namespace TaLib 9 | { 10 | public partial class Core 11 | { 12 | private static void SeriesCopy(SmartQuant.ISeries source, long sourceIndex, Array destinationArray, long destinationIndex, long length) 13 | { 14 | for (var i = 0; i < length; i++) { 15 | destinationArray.SetValue(source[i + (int)sourceIndex], i + destinationIndex); 16 | } 17 | } 18 | } 19 | 20 | public abstract class TaIndicator : SmartQuant.Indicator 21 | { 22 | protected static readonly double[] InOpen = { 0 }; 23 | protected static readonly double[] InClose = { 0 }; 24 | protected static readonly double[] InHigh = { 0 }; 25 | protected static readonly double[] InLow = { 0 }; 26 | protected static readonly double[] InVolume = { 0 }; 27 | 28 | protected TaIndicator(ISeries input) : base(input) 29 | { 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /XApiSharp/AccountField.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/XApiSharp/AccountField.cs -------------------------------------------------------------------------------- /XApiSharp/ApiType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [Flags] 6 | public enum ApiType : byte 7 | { 8 | None = 0, 9 | Trade = 1, 10 | MarketData = 2, 11 | Level2 = 4, 12 | QuoteRequest = 8, 13 | HistoricalData = 16, 14 | Instrument = 32, 15 | Query = 64, 16 | }; 17 | } -------------------------------------------------------------------------------- /XApiSharp/AssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Security; 8 | 9 | namespace QuantBox.XApi 10 | { 11 | public static class AssemblyResolver 12 | { 13 | private static readonly ConcurrentDictionary ScanPaths = new ConcurrentDictionary(); 14 | private static string[] _paths = new string[0]; 15 | 16 | private static void AddPathStringToEnvironment(string path) 17 | { 18 | try { 19 | var environmentVariable = Environment.GetEnvironmentVariable("PATH"); 20 | if (environmentVariable != null && !environmentVariable.Contains(path)) { 21 | Environment.SetEnvironmentVariable("PATH", path + ";" + environmentVariable); 22 | Trace.WriteLine($"{path} added to Path."); 23 | } 24 | } 25 | catch (SecurityException) { 26 | Trace.WriteLine("Changing PATH not allowed"); 27 | } 28 | } 29 | 30 | static AssemblyResolver() 31 | { 32 | AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve; 33 | } 34 | 35 | public static void AddPath(string path) 36 | { 37 | if (ScanPaths.TryAdd(path, 1)) { 38 | AddPathStringToEnvironment(path); 39 | _paths = ScanPaths.Keys.ToArray(); 40 | } 41 | } 42 | 43 | private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args) 44 | { 45 | var assemblyName = new AssemblyName(args.Name); 46 | foreach (var path in _paths) { 47 | var file = Path.Combine(path, assemblyName.Name + ".dll"); 48 | if (File.Exists(file)) 49 | return Assembly.LoadFile(file); 50 | } 51 | return null; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /XApiSharp/BarDataField.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace QuantBox.XApi 6 | { 7 | public class BarDataField 8 | { 9 | public DateTime CloseDateTime; 10 | public DateTime OpenDateTime; 11 | public double Low; 12 | public double High; 13 | public double Open; 14 | public double Close; 15 | public int Volume; 16 | public double Turnover; 17 | public int OpenInterest; 18 | public string Symbol; 19 | public long BarSize; 20 | public double Settle; 21 | public double PreSettle; 22 | public double PreClose; 23 | 24 | public BarDataField() 25 | { 26 | } 27 | 28 | public BarDataField( 29 | DateTime openDateTime, DateTime closeDateTime, string symbol, long barSize, 30 | double open, double close, double high, double low, 31 | double turnover, int openInterest) 32 | { 33 | OpenDateTime = openDateTime; 34 | CloseDateTime = closeDateTime; 35 | Symbol = symbol; 36 | BarSize = barSize; 37 | Open = open; 38 | Close = close; 39 | High = high; 40 | Low = low; 41 | OpenInterest = openInterest; 42 | Turnover = turnover; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return $"{OpenDateTime:dd_HH:mm}-{CloseDateTime:dd_HH:mm},{Open},{Close},{High},{Low}"; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /XApiSharp/BarType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum BarType : byte 4 | { 5 | Time = 1, 6 | Tick, 7 | Volume, 8 | Range, 9 | Session, 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /XApiSharp/BusinessType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum BusinessType : byte 4 | { 5 | Undefined, 6 | Future, 7 | Stock, 8 | Option, 9 | }; 10 | } -------------------------------------------------------------------------------- /XApiSharp/ConnectionStatus.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | public enum ConnectionStatus : byte 6 | { 7 | /// 8 | /// 未初始化 9 | /// 10 | [Description("未初始化")] 11 | Uninitialized = 0, 12 | /// 13 | /// 已经初始化 14 | /// 15 | [Description("已经初始化")] 16 | Initialized, 17 | /// 18 | /// 连接已经断开 19 | /// 20 | [Description("连接已经断开")] 21 | Disconnected, 22 | /// 23 | /// 连接中... 24 | /// 25 | [Description("连接中...")] 26 | Connecting, 27 | /// 28 | /// 连接成功 29 | /// 30 | [Description("连接成功")] 31 | Connected, 32 | /// 33 | /// 授权中... 34 | /// 35 | [Description("授权中...")] 36 | Authorizing, 37 | /// 38 | /// 授权成功 39 | /// 40 | [Description("授权成功")] 41 | Authorized, 42 | /// 43 | /// 登录中... 44 | /// 45 | [Description("登录中...")] 46 | Logining, 47 | /// 48 | /// 登录成功 49 | /// 50 | [Description("登录成功")] 51 | Logined, 52 | /// 53 | /// 确认中... 54 | /// 55 | [Description("确认中...")] 56 | Confirming, 57 | /// 58 | /// 已经确认 59 | /// 60 | [Description("已经确认")] 61 | Confirmed, 62 | /// 63 | /// 操作中... 64 | /// 65 | [Description("操作中...")] 66 | Doing, 67 | /// 68 | /// 完成 69 | /// 70 | [Description("完成")] 71 | Done, 72 | /// 73 | /// 关闭中... 74 | /// 75 | [Description("关闭中...")] 76 | Releasing 77 | } 78 | } -------------------------------------------------------------------------------- /XApiSharp/DataObjetType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum DataObjetType : byte 4 | { 5 | DataObject, 6 | Tick, 7 | Bid, 8 | Ask, 9 | Trade, 10 | Quote, 11 | Bar, 12 | Level2, 13 | Level2Snapshot, 14 | Level2Update, 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /XApiSharp/DepthField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public struct DepthField 7 | { 8 | public double Price; 9 | public int Size; 10 | public int Count; 11 | } 12 | } -------------------------------------------------------------------------------- /XApiSharp/DepthLevelType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum DepthLevelType : byte 4 | { 5 | L0, 6 | L1, 7 | L3, 8 | L5, 9 | L10, 10 | Full, 11 | }; 12 | } -------------------------------------------------------------------------------- /XApiSharp/EnterReasonType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum EnterReasonType 4 | { 5 | Automatic, 6 | Manual, 7 | Fuse 8 | } 9 | } -------------------------------------------------------------------------------- /XApiSharp/ErrorField.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public class ErrorField 4 | { 5 | /// 6 | /// 错误代码 7 | /// 8 | public readonly int XErrorId; 9 | /// 10 | /// 错误代码 11 | /// 12 | public readonly int RawErrorId; 13 | /// 14 | /// 错误信息 15 | /// 16 | public readonly string Text; 17 | /// 18 | /// 信息来源 19 | /// 20 | public readonly string Source; 21 | 22 | public ErrorField(int errorId, int rawErrorId, string text, string source) 23 | { 24 | XErrorId = errorId; 25 | RawErrorId = rawErrorId; 26 | Text = text; 27 | Source = source; 28 | } 29 | 30 | internal ErrorField(InternalErrorField field) 31 | { 32 | XErrorId = field.XErrorID; 33 | RawErrorId = field.RawErrorID; 34 | Text = field.Text(); 35 | Source = field.Source; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /XApiSharp/ExchangeType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public static class ExchangeNames 4 | { 5 | /// 上期所 6 | public const string SHFE = "SHFE"; 7 | /// 郑商所 8 | public const string CZCE = "CZCE"; 9 | /// 中金所 10 | public const string CFFEX = "CFFEX"; 11 | /// 郑商所 12 | public const string DCE = "DCE"; 13 | /// 能源中心 14 | public const string INE = "INE"; 15 | /// 上交所 16 | public const string SSE = "SSE"; 17 | /// 深交所 18 | public const string SZSE = "SZSE"; 19 | /// 上海黄金交易所 20 | public const string SGE = "SGE"; 21 | /// 全国中小企业股份转让系统(三板) 22 | public const string NEEQ = "NEEQ"; 23 | /// 港交所 24 | public const string HKEx = "HKEx"; 25 | } 26 | 27 | public enum ExchangeType : byte 28 | { 29 | /// 未定义 30 | Undefined, 31 | /// 上期所 32 | SHFE, 33 | /// 大商所 34 | DCE, 35 | /// 郑商所 36 | CZCE, 37 | /// 中金所 38 | CFFEX, 39 | /// 能源中心 40 | INE, 41 | /// 上交所 42 | SSE, 43 | /// 深交所 44 | SZSE, 45 | /// 上海黄金交易所 46 | SGE, 47 | /// 全国中小企业股份转让系统,三板 48 | NEEQ, 49 | /// 港交所 50 | HKEx, 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /XApiSharp/ExecType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum ExecType : byte 4 | { 5 | New, 6 | Stopped, 7 | Rejected, 8 | Expired, 9 | Trade, 10 | PendingCancel, 11 | Cancelled, 12 | CancelReject, 13 | PendingReplace, 14 | Replace, 15 | ReplaceReject, 16 | TradeCorrect, 17 | TradeCancel, 18 | OrderStatus, 19 | PendingNew, 20 | ClearingHold, 21 | }; 22 | } -------------------------------------------------------------------------------- /XApiSharp/HedgeFlagType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum HedgeFlagType : byte 4 | { 5 | /// 6 | /// 投机 7 | /// 8 | Speculation, 9 | /// 10 | /// 套利 11 | /// 12 | Arbitrage, 13 | /// 14 | /// 套保 15 | /// 16 | Hedge, 17 | Covered, 18 | MarketMaker, 19 | Undefined 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /XApiSharp/IXApi.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public interface IXApi 4 | { 5 | void RegisterSpi(IXSpi spi); 6 | void Release(); 7 | void Connect(ServerInfoField server, UserInfoField user); 8 | void Disconnect(); 9 | void Query(QueryType type, ReqQueryField query); 10 | bool Connected { get; } 11 | void Subscribe(string instrument, string exchange, InstrumentType type); 12 | void Unsubscribe(string instrument, string exchange, InstrumentType type); 13 | string SendOrder(params OrderField[] orders); 14 | string CancelOrder(params string[] list); 15 | string ApiVersion { get; } 16 | ApiType ApiTypes { get; } 17 | string ApiName { get; } 18 | ServerInfoField Server { get; } 19 | UserInfoField User { get; } 20 | RspUserLoginField UserLogin { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /XApiSharp/IXSpi.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public interface IXSpi 4 | { 5 | void ProcessConnectionStatus(ConnectionStatus status, RspUserLoginField login); 6 | void ProcessError(ErrorField error); 7 | void ProcessQryInstrument(InstrumentField inst, bool last); 8 | void ProcessQryPosition(PositionField position, bool last); 9 | void ProcessQryInvestor(InvestorField investor, bool last); 10 | void ProcessQryAccount(AccountField account, bool last); 11 | void ProcessQrySettlementInfo(SettlementInfoField info, bool last); 12 | void ProcessQryOrder(OrderField order, bool last); 13 | void ProcessQryTrade(TradeField trade, bool last); 14 | void ProcessDepthMarketData(DepthMarketDataField data); 15 | void ProcessRtnOrder(OrderField order); 16 | void ProcessRtnTrade(TradeField trade); 17 | void ProcessRtnInstrumentStatus(InstrumentStatusField status); 18 | void ProcessLog(LogField log); 19 | } 20 | } -------------------------------------------------------------------------------- /XApiSharp/IdCardType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum IdCardType : byte 4 | { 5 | EID, ///组织机构代码 6 | IDCard, ///中国公民身份证 7 | Passport, ///护照 8 | LicenseNo, ///营业执照号 9 | TaxNo, ///税务登记号/当地纳税ID 10 | DrivingLicense, ///驾照 11 | SocialID, ///当地社保ID 12 | LocalID, ///当地身份证 13 | OtherCard, ///其他证件 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /XApiSharp/InstLifePhaseType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum InstLifePhaseType : byte 4 | { 5 | ///未上市 6 | NotStart, 7 | ///上市 8 | Started, 9 | ///停牌 10 | Pause, 11 | ///到期 12 | Expired, 13 | ///发行,参考于XSpeed 14 | Issue, 15 | ///首日上市,参考于XSpeed 16 | FirstList, 17 | ///退市,参考于XSpeed 18 | UnList, 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /XApiSharp/InstrumentField.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/XApiSharp/InstrumentField.cs -------------------------------------------------------------------------------- /XApiSharp/InstrumentStatusField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | public class InstrumentStatusField 6 | { 7 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 8 | public string InstrumentID; 9 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 10 | public string ExchangeID; 11 | public int EnterTime; 12 | public EnterReasonType EnterReason; 13 | public InstrumentStatusType Status; 14 | } 15 | } -------------------------------------------------------------------------------- /XApiSharp/InstrumentStatusType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum InstrumentStatusType : byte 4 | { 5 | BeforeTrading, 6 | NoTrading, 7 | Continous, 8 | AuctionOrdering, 9 | AuctionBalance, 10 | AuctionMatch, 11 | Closed 12 | } 13 | } -------------------------------------------------------------------------------- /XApiSharp/InstrumentType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum InstrumentType : byte 4 | { 5 | Stock, 6 | Future, 7 | Option, 8 | FutureOption, 9 | Bond, 10 | FX, 11 | Index, 12 | ETF, 13 | MultiLeg, 14 | Synthetic, 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /XApiSharp/InternalDepthMarketDataField.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/XApiSharp/InternalDepthMarketDataField.cs -------------------------------------------------------------------------------- /XApiSharp/InternalErrorField.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/XApiSharp/InternalErrorField.cs -------------------------------------------------------------------------------- /XApiSharp/InternalLogField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | internal class InternalLogField 7 | { 8 | /// 9 | /// 日志级别 10 | /// 11 | public LogLevel Level; 12 | /// 13 | /// 错误信息 14 | /// 15 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] 16 | public byte[] Message; 17 | } 18 | } -------------------------------------------------------------------------------- /XApiSharp/InternalRspUserLoginField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | internal class InternalRspUserLoginField 7 | { 8 | /// 9 | /// 交易日 10 | /// 11 | public int TradingDay; 12 | /// 13 | /// 时间 14 | /// 15 | public int LoginTime; 16 | /// 17 | /// 18 | /// 19 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 20 | public string SessionID; 21 | 22 | /// 23 | /// 24 | /// 25 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 26 | public string UserID; 27 | /// 28 | /// 29 | /// 30 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 31 | public string AccountID; 32 | /// 33 | /// 投资者名称 34 | /// 35 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 81)] 36 | public byte[] InvestorName; 37 | 38 | /// 39 | /// 错误代码 40 | /// 41 | public int XErrorID; 42 | /// 43 | /// 错误信息 44 | /// 45 | public int RawErrorID; 46 | /// 47 | /// 错误信息 48 | /// 49 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] 50 | public byte[] Text; 51 | } 52 | } -------------------------------------------------------------------------------- /XApiSharp/InternalSettlementInfoField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | internal class InternalSettlementInfoField 7 | { 8 | public int Size; 9 | /// 10 | /// 交易日 11 | /// 12 | public int TradingDay; 13 | } 14 | } -------------------------------------------------------------------------------- /XApiSharp/InvestorField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class InvestorField 7 | { 8 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 9 | public string InvestorID; 10 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] 11 | public string BrokerID; 12 | public IdCardType IdentifiedCardType; 13 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 51)] 14 | public string IdentifiedCardNo; 15 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 81)] 16 | public byte[] InvestorName; 17 | } 18 | } -------------------------------------------------------------------------------- /XApiSharp/LogField.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public class LogField 4 | { 5 | public LogLevel Level { get; private set; } 6 | public string Message { get; private set; } 7 | 8 | internal LogField(InternalLogField field) 9 | { 10 | Level = field.Level; 11 | Message = field.Text(); 12 | } 13 | 14 | public LogField(LogLevel level, string message) 15 | { 16 | Level = level; 17 | Message = message; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /XApiSharp/LogLevel.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum LogLevel : byte 4 | { 5 | Trace, 6 | Debug, 7 | Info, 8 | Warn, 9 | Error, 10 | Fatal, 11 | }; 12 | } -------------------------------------------------------------------------------- /XApiSharp/ManagedApiLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | 5 | namespace QuantBox.XApi 6 | { 7 | internal class ManagedApiLoader : IDisposable 8 | { 9 | private readonly string _file; 10 | 11 | private ManagedApiLoader(string file) 12 | { 13 | AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; 14 | _file = file; 15 | } 16 | 17 | private Assembly Load() 18 | { 19 | var asm = File.Exists(_file) ? Assembly.LoadFile(_file) : null; 20 | if (asm != null) { 21 | foreach (var type in asm.ExportedTypes) { 22 | if (type.Name == "impossible is") { 23 | break; 24 | } 25 | } 26 | } 27 | return asm; 28 | } 29 | 30 | private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 31 | { 32 | var assemblyName = new AssemblyName(args.Name); 33 | var path = Path.Combine(Path.GetDirectoryName(_file), assemblyName.Name + ".dll"); 34 | return File.Exists(path) ? Assembly.LoadFile(path) : null; 35 | } 36 | 37 | public void Dispose() 38 | { 39 | AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; 40 | } 41 | 42 | public static Assembly LoadFile(string file) 43 | { 44 | using (var loader = new ManagedApiLoader(file)) { 45 | return loader.Load(); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /XApiSharp/ManagedManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | 5 | namespace QuantBox.XApi 6 | { 7 | internal static class ManagedManager 8 | { 9 | private static readonly Dictionary Loaded = new Dictionary(); 10 | private static readonly object Locker = new object(); 11 | 12 | private static Assembly GetAssembly(string path) 13 | { 14 | foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { 15 | try { 16 | if (asm.Location == path) { 17 | return asm; 18 | } 19 | } 20 | catch (Exception) { 21 | // ignored 22 | } 23 | } 24 | return ManagedApiLoader.LoadFile(path); 25 | } 26 | 27 | private static Type GetApiType(string path) 28 | { 29 | Loaded.TryGetValue(path, out var exist); 30 | if (exist == null) { 31 | var asm = GetAssembly(path); 32 | foreach (var type in asm.ExportedTypes) { 33 | if (typeof(IXApi).IsAssignableFrom(type)) { 34 | Loaded.Add(path, type); 35 | exist = type; 36 | break; 37 | } 38 | } 39 | } 40 | return exist; 41 | } 42 | 43 | public static object GetInstance(string path) 44 | { 45 | lock (Locker) { 46 | var type = GetApiType(path); 47 | if (type == null) { 48 | throw new InvalidOperationException("XApi type not found."); 49 | } 50 | return Activator.CreateInstance(type); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /XApiSharp/Native/ResponseData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox.XApi.Native 4 | { 5 | internal struct ResponseData 6 | { 7 | public readonly byte RspType; 8 | public readonly IntPtr Api1; 9 | public readonly IntPtr Api2; 10 | public readonly double Double1; 11 | public readonly double Double2; 12 | public readonly IntPtr Ptr1; 13 | public readonly int Size1; 14 | public readonly IntPtr Ptr2; 15 | public readonly int Size2; 16 | public readonly IntPtr Ptr3; 17 | public readonly int Size3; 18 | 19 | public ResponseData(byte type, IntPtr api1, IntPtr api2, double double1, double double2, IntPtr ptr1, 20 | int size1, IntPtr ptr2, int size2, IntPtr ptr3, int size3) 21 | { 22 | RspType = type; 23 | Api1 = api1; 24 | Api2 = api2; 25 | Double1 = double1; 26 | Double2 = double2; 27 | Ptr1 = ptr1; 28 | Size1 = size1; 29 | Ptr2 = ptr2; 30 | Size2 = size2; 31 | Ptr3 = ptr3; 32 | Size3 = size3; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /XApiSharp/Native/SubscribedList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace QuantBox.XApi.Native 6 | { 7 | internal class SubscribedList : IEnumerable> 8 | { 9 | private readonly Dictionary> _list = new Dictionary>(); 10 | 11 | public void Subscribe(string instrument, string exchange) 12 | { 13 | _list.TryGetValue(exchange, out HashSet insts); 14 | if (insts == null) { 15 | insts = new HashSet(); 16 | _list.Add(exchange, insts); 17 | } 18 | if (!insts.Contains(instrument)) { 19 | insts.Add(instrument); 20 | } 21 | } 22 | 23 | public void Unsubscribe(string instrument, string exchange) 24 | { 25 | _list.TryGetValue(exchange, out HashSet insts); 26 | if (insts == null) { 27 | return; 28 | } 29 | if (insts.Contains(instrument)) { 30 | insts.Remove(instrument); 31 | } 32 | } 33 | 34 | public IEnumerator> GetEnumerator() 35 | { 36 | foreach (var item in _list) { 37 | foreach (var inst in item.Value) { 38 | yield return Tuple.Create(inst, item.Key); 39 | } 40 | } 41 | } 42 | 43 | IEnumerator IEnumerable.GetEnumerator() 44 | { 45 | return GetEnumerator(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /XApiSharp/Native/UnixInvoke.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace QuantBox.XApi.Native 5 | { 6 | internal class UnixInvoke : XApiInvoke 7 | { 8 | [DllImport("libdl.so")] 9 | private static extern IntPtr dlopen(string path, int mode); 10 | [DllImport("libdl.so")] 11 | private static extern IntPtr dlsym(IntPtr handle, string symbol); 12 | [DllImport("libdl.so")] 13 | private static extern IntPtr dlerror(); 14 | [DllImport("libdl.so")] 15 | private static extern int dlclose(IntPtr handle); 16 | 17 | public UnixInvoke(string path) 18 | { 19 | DllLib = dlopen(path, 1); 20 | if (DllLib == IntPtr.Zero) { 21 | var errptr = dlerror(); 22 | var error = Marshal.PtrToStringAnsi(errptr); 23 | throw new Exception(error); 24 | } 25 | } 26 | 27 | public override XRequest GetXRequest() 28 | { 29 | if (DllLib == IntPtr.Zero) 30 | return null; 31 | 32 | var api = dlsym(DllLib, XRequestFunction); 33 | return (XRequest)Marshal.GetDelegateForFunctionPointer(api, typeof(XRequest)); 34 | } 35 | 36 | public override void Dispose() 37 | { 38 | if (DllLib != IntPtr.Zero) 39 | dlclose(DllLib); 40 | DllLib = IntPtr.Zero; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /XApiSharp/Native/UnmanagedOrders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace QuantBox.XApi.Native 6 | { 7 | internal struct UnmanagedOrders : IDisposable 8 | { 9 | private static readonly int OrderFieldSize = Marshal.SizeOf(typeof(OrderField)); 10 | private static readonly int OrderIdTypeSize = Marshal.SizeOf(typeof(OrderIdType)); 11 | 12 | public UnmanagedOrders(IReadOnlyList orders) 13 | { 14 | OrderPtr = Marshal.AllocHGlobal(OrderFieldSize * orders.Count); 15 | InOrderIdPtr = IntPtr.Zero; 16 | OutOrderIdPtr = Marshal.AllocHGlobal(OrderIdTypeSize * orders.Count); 17 | //将结构体写成内存块 18 | for (var i = 0; i < orders.Count; ++i) { 19 | Marshal.StructureToPtr(orders[i], new IntPtr(OrderPtr.ToInt64() + i * OrderFieldSize), false); 20 | } 21 | } 22 | 23 | public UnmanagedOrders(IReadOnlyList list) 24 | { 25 | OrderPtr = IntPtr.Zero; 26 | InOrderIdPtr = Marshal.AllocHGlobal(OrderIdTypeSize * list.Count); 27 | OutOrderIdPtr = Marshal.AllocHGlobal(OrderIdTypeSize * list.Count); 28 | // 将结构体写成内存块 29 | for (var i = 0; i < list.Count; ++i) { 30 | var id = new OrderIdType() { 31 | ID = list[i] 32 | }; 33 | Marshal.StructureToPtr(id, new IntPtr(InOrderIdPtr.ToInt64() + i * OrderIdTypeSize), false); 34 | } 35 | } 36 | 37 | public IntPtr OrderPtr; 38 | public IntPtr InOrderIdPtr; 39 | public IntPtr OutOrderIdPtr; 40 | 41 | public void Dispose() 42 | { 43 | if (OrderPtr != IntPtr.Zero) { 44 | Marshal.FreeHGlobal(OrderPtr); 45 | OrderPtr = IntPtr.Zero; 46 | } 47 | if (InOrderIdPtr != IntPtr.Zero) { 48 | Marshal.FreeHGlobal(InOrderIdPtr); 49 | InOrderIdPtr = IntPtr.Zero; 50 | } 51 | if (OutOrderIdPtr != IntPtr.Zero) { 52 | Marshal.FreeHGlobal(OutOrderIdPtr); 53 | OutOrderIdPtr = IntPtr.Zero; 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /XApiSharp/Native/UnmanagedPtr.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace QuantBox.XApi.Native 5 | { 6 | internal struct UnmanagedPtr : IDisposable 7 | { 8 | public UnmanagedPtr(T obj) 9 | { 10 | Ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T))); 11 | Marshal.StructureToPtr(obj, Ptr, false); 12 | } 13 | 14 | public UnmanagedPtr(string s) 15 | { 16 | Ptr = Marshal.StringToHGlobalAnsi(s); 17 | } 18 | 19 | public static implicit operator IntPtr(UnmanagedPtr data) 20 | { 21 | return data.Ptr; 22 | } 23 | 24 | public void Dispose() 25 | { 26 | if (Ptr != IntPtr.Zero) 27 | { 28 | Marshal.FreeHGlobal(Ptr); 29 | Ptr = IntPtr.Zero; 30 | } 31 | } 32 | 33 | public IntPtr Ptr { get; private set; } 34 | } 35 | } -------------------------------------------------------------------------------- /XApiSharp/Native/XApiInvoke.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox.XApi.Native 4 | { 5 | internal abstract class XApiInvoke : IDisposable 6 | { 7 | public delegate IntPtr XRequest(byte type, IntPtr pApi1, IntPtr pApi2, double double1, double double2, IntPtr ptr1, int size1, IntPtr ptr2, int size2, IntPtr ptr3, int size3); 8 | 9 | protected const string XRequestFunction = "XRequest"; 10 | 11 | protected IntPtr DllLib = IntPtr.Zero; 12 | 13 | public abstract XRequest GetXRequest(); 14 | 15 | public virtual void Dispose() 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /XApiSharp/Native/XApiInvokeProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace QuantBox.XApi.Native 4 | { 5 | internal class XApiInvokeProxy : IDisposable 6 | { 7 | private readonly XApiInvoke _invoke; 8 | private readonly XApiInvoke.XRequest _request; 9 | 10 | public XApiInvokeProxy(string path) 11 | { 12 | if (Environment.OSVersion.Platform == PlatformID.Unix) { 13 | _invoke = new UnixInvoke(path); 14 | } 15 | else { 16 | _invoke = new WindowsInvoke(path); 17 | } 18 | if (_invoke != null) { 19 | _request = _invoke.GetXRequest(); 20 | } 21 | } 22 | 23 | ~XApiInvokeProxy() 24 | { 25 | Dispose(); 26 | } 27 | 28 | public void Dispose() 29 | { 30 | _invoke?.Dispose(); 31 | } 32 | 33 | public IntPtr XRequest(QueryType type, IntPtr api, IntPtr ptr1, int size1) 34 | { 35 | return _request((byte)type, api, IntPtr.Zero, 0, 0, ptr1, size1, IntPtr.Zero, 0, IntPtr.Zero, 0); 36 | } 37 | 38 | public IntPtr XRequest(RequestType type, IntPtr api, IntPtr ptr1, IntPtr ptr2) 39 | { 40 | return _request((byte)type, api, IntPtr.Zero, 0, 0, ptr1, 0, ptr2, 0, IntPtr.Zero, 0); 41 | } 42 | 43 | public IntPtr XRequest(RequestType type, IntPtr api1, IntPtr api2, double double1, double double2, 44 | IntPtr ptr1, int size1, IntPtr ptr2, int size2, IntPtr ptr3, int size3) 45 | { 46 | return _request((byte)type, api1, api2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3); 47 | } 48 | 49 | public IntPtr XRequest(RequestType type) 50 | { 51 | return XRequest(type, IntPtr.Zero); 52 | } 53 | 54 | public IntPtr XRequest(RequestType type, IntPtr api) 55 | { 56 | return XRequest(type, api, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /XApiSharp/OpenCloseType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum OpenCloseType : byte 4 | { 5 | Undefined, 6 | Open, 7 | Close, 8 | CloseToday, 9 | LockToday 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /XApiSharp/OrderField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class OrderField 7 | { 8 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] 9 | public byte[] InstrumentName; 10 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 11 | public string Symbol; 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 13 | public string InstrumentID; 14 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)] 15 | public string ExchangeID; 16 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 17 | public string ClientID; 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 19 | public string AccountID; 20 | 21 | public OrderSide Side; 22 | public double Qty; 23 | public double Price; 24 | public OpenCloseType OpenClose; 25 | public HedgeFlagType HedgeFlag; 26 | public int Date; 27 | public int Time; 28 | 29 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 30 | public string ID; 31 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 32 | public string OrderID; 33 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 34 | public string LocalID; 35 | 36 | public OrderType Type; 37 | public double StopPx; 38 | public TimeInForce TimeInForce; 39 | 40 | public OrderStatus Status; 41 | public ExecType ExecType; 42 | public double LeavesQty; 43 | public double CumQty; 44 | public double AvgPx; 45 | 46 | public int XErrorID; 47 | public int RawErrorID; 48 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] 49 | public byte[] Text; 50 | 51 | public int ReserveInt32; 52 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 53 | public string ReserveChar64; 54 | 55 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 56 | public string PortfolioID1; 57 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 58 | public string PortfolioID2; 59 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 60 | public string PortfolioID3; 61 | 62 | public BusinessType Business; 63 | 64 | public OrderField Clone() 65 | { 66 | return (OrderField)MemberwiseClone(); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /XApiSharp/OrderIDType.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | internal class OrderIdType 7 | { 8 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 9 | public string ID; 10 | } 11 | } -------------------------------------------------------------------------------- /XApiSharp/OrderSide.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum OrderSide : byte 4 | { 5 | Buy, 6 | Sell, 7 | /// 8 | /// LOF申购 9 | /// 10 | LOFCreation, 11 | /// 12 | /// LOF赎回 13 | /// 14 | LOFRedemption, 15 | ///ETF申购 16 | ETFCreation, 17 | /// 18 | /// ETF赎回 19 | /// 20 | ETFRedemption, 21 | /// 22 | /// 合并 23 | /// 24 | Merge, 25 | /// 26 | /// 拆分 27 | /// 28 | Split, 29 | /// 30 | /// 可转债转股,参考于https://en.wikipedia.org/wiki/Convertible_bond 31 | /// 32 | CBConvert, 33 | CBRedemption, 34 | Undefined, 35 | }; 36 | } -------------------------------------------------------------------------------- /XApiSharp/OrderStatus.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum OrderStatus : byte 4 | { 5 | NotSent, 6 | PendingNew, 7 | New, 8 | Rejected, 9 | PartiallyFilled, 10 | Filled, 11 | PendingCancel, 12 | Cancelled, 13 | Expired, 14 | PendingReplace, 15 | Replaced, 16 | }; 17 | } -------------------------------------------------------------------------------- /XApiSharp/OrderType.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [ComVisible(false)] 6 | public enum OrderType : byte 7 | { 8 | Market, 9 | Stop, 10 | Limit, 11 | StopLimit, 12 | MarketOnClose, 13 | Pegged, 14 | TrailingStop, 15 | TrailingStopLimit, 16 | }; 17 | } -------------------------------------------------------------------------------- /XApiSharp/PositionField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class PositionField 7 | { 8 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] 9 | public byte[] InstrumentName; 10 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 11 | public string Symbol; 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 13 | public string InstrumentID; 14 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)] 15 | public string ExchangeID; 16 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 17 | public string ClientID; 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 19 | public string AccountID; 20 | 21 | public PositionSide Side; 22 | public HedgeFlagType HedgeFlag; 23 | public int Date; 24 | public double PositionCost; 25 | public double OpenCost; 26 | public double Position; 27 | public double TodayPosition; 28 | public double HistoryPosition; 29 | public double HistoryFrozen; 30 | 31 | ///今日买卖持仓 32 | public double TodayBSPosition; 33 | ///今日买卖持仓冻结 34 | public double TodayBSFrozen; 35 | ///今日申赎持仓 36 | public double TodayPRPosition; 37 | ///今日申赎持仓冻结 38 | public double TodayPRFrozen; 39 | 40 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 41 | public string ID; 42 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 43 | public string PortfolioID1; 44 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 45 | public string PortfolioID2; 46 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 47 | public string PortfolioID3; 48 | 49 | public BusinessType Business; 50 | } 51 | } -------------------------------------------------------------------------------- /XApiSharp/PositionSide.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum PositionSide : byte 4 | { 5 | Long, 6 | Short, 7 | }; 8 | } -------------------------------------------------------------------------------- /XApiSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的一般信息由以下 5 | // 控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("XApiSharp")] 8 | [assembly: AssemblyDescription("XAPI 接口的 CSharp 封装")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("QuantBox")] 11 | [assembly: AssemblyProduct("XApiSharp")] 12 | [assembly: AssemblyCopyright("Copyright © qunatbox 2017")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 会使此程序集中的类型 17 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 18 | //请将此类型的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("ba6da3bd-c80f-49f5-953f-34e12967d166")] 23 | 24 | // 程序集的版本信息由下列四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 32 | //通过使用 "*",如下所示: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.1623")] 36 | -------------------------------------------------------------------------------- /XApiSharp/PutCall.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum PutCall : byte 4 | { 5 | Put, 6 | Call, 7 | }; 8 | } -------------------------------------------------------------------------------- /XApiSharp/QueryType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum QueryType : byte 4 | { 5 | ReqQryInstrument = 32, 6 | ReqQryTradingAccount, 7 | ReqQryInvestorPosition, 8 | 9 | ReqQryOrder, 10 | ReqQryTrade, 11 | ReqQryQuote, 12 | 13 | ReqQryInstrumentCommissionRate, 14 | ReqQryInstrumentMarginRate, 15 | ReqQrySettlementInfo, 16 | ReqQryInvestor, 17 | 18 | ReqQryHistoricalTicks, 19 | ReqQryHistoricalBars, 20 | 21 | ReqError, 22 | } 23 | } -------------------------------------------------------------------------------- /XApiSharp/ReqQueryField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class ReqQueryField 7 | { 8 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] 9 | public byte[] InstrumentName; 10 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 11 | public string Symbol; 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 13 | public string InstrumentID; 14 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)] 15 | public string ExchangeID; 16 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 17 | public string ClientID; 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 19 | public string AccountID; 20 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)] 21 | public string CurrencyID; 22 | 23 | public int DateStart; 24 | public int DateEnd; 25 | public int TimeStart; 26 | public int TimeEnd; 27 | 28 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 29 | public string Char64ID; 30 | public int Int32ID; 31 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 32 | public string Char64PositionIndex; 33 | public int Int32PositionIndex; 34 | 35 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 36 | public string PortfolioID1; 37 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 38 | public string PortfolioID2; 39 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 40 | public string PortfolioID3; 41 | 42 | public BusinessType Business; 43 | } 44 | } -------------------------------------------------------------------------------- /XApiSharp/RequestType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | internal enum RequestType : byte 4 | { 5 | GetApiTypes = 0, 6 | GetApiVersion, 7 | GetApiName, 8 | 9 | Create, // 创建 10 | Release, // 销毁 11 | Register, // 注册回调 12 | Config, // 配置参数 13 | 14 | Connect, // 开始/连接 15 | Disconnect, // 停止/断开 16 | 17 | Clear, // 清理 18 | Process, // 处理 19 | 20 | Subscribe, // 订阅 21 | Unsubscribe, // 取消订阅 22 | 23 | SubscribeQuote, // 订阅应价 24 | UnsubscribeQuote, // 取消应价 25 | 26 | ReqOrderInsert, 27 | ReqQuoteInsert, 28 | ReqOrderAction, 29 | ReqQuoteAction, 30 | } 31 | } -------------------------------------------------------------------------------- /XApiSharp/ResponseType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | internal enum ResponseType : byte 4 | { 5 | OnConnectionStatus = 64, 6 | OnRtnError, 7 | OnLog, 8 | 9 | OnRtnDepthMarketData, 10 | OnRspQryInstrument, 11 | OnRspQryTradingAccount, 12 | OnRspQryInvestorPosition, 13 | OnRspQrySettlementInfo, 14 | 15 | OnRspQryOrder, 16 | OnRspQryTrade, 17 | OnRspQryQuote, 18 | 19 | OnRtnOrder, 20 | OnRtnTrade, 21 | OnRtnQuote, 22 | 23 | OnRtnQuoteRequest, 24 | 25 | OnRspQryHistoricalTicks, 26 | OnRspQryHistoricalBars, 27 | OnRspQryInvestor, 28 | 29 | OnFilterSubscribe, 30 | } 31 | } -------------------------------------------------------------------------------- /XApiSharp/ResumeType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum ResumeType : byte 4 | { 5 | Restart, 6 | Resume, 7 | Quick, 8 | Undefined, 9 | }; 10 | } -------------------------------------------------------------------------------- /XApiSharp/RspUserLoginField.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public class RspUserLoginField 4 | { 5 | /// 6 | /// 交易日 7 | /// 8 | public int TradingDay; 9 | /// 10 | /// 登陆时间 11 | /// 12 | public int LoginTime; 13 | /// 14 | /// 15 | /// 16 | public string SessionID; 17 | /// 18 | /// 19 | /// 20 | public string UserID; 21 | /// 22 | /// 23 | /// 24 | public string AccountID; 25 | /// 26 | /// 投资者名称 27 | /// 28 | public string InvestorName; 29 | /// 30 | /// 错误代码 31 | /// 32 | public int XErrorID; 33 | /// 34 | /// 错误信息 35 | /// 36 | public int RawErrorID; 37 | /// 38 | /// 错误信息 39 | /// 40 | public string Text; 41 | 42 | public RspUserLoginField() 43 | { 44 | } 45 | 46 | internal RspUserLoginField(InternalRspUserLoginField field) 47 | { 48 | TradingDay = field.TradingDay; 49 | LoginTime = field.LoginTime; 50 | SessionID = field.SessionID; 51 | UserID = field.UserID; 52 | AccountID = field.AccountID; 53 | InvestorName = field.Name(); 54 | XErrorID = field.XErrorID; 55 | RawErrorID = field.RawErrorID; 56 | Text = field.Text(); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /XApiSharp/ServerInfoField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | /// 6 | /// 服务器信息 7 | /// 8 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 9 | public class ServerInfoField 10 | { 11 | /// 12 | /// 订阅主题 13 | /// 14 | [MarshalAs(UnmanagedType.U1)] 15 | public bool IsUsingUdp; 16 | /// 17 | /// 订阅主题 18 | /// 19 | [MarshalAs(UnmanagedType.U1)] 20 | public bool IsMulticast; 21 | /// 22 | /// 订阅主题 23 | /// 24 | public int TopicId; 25 | /// 26 | /// 端口号 27 | /// 28 | public int Port; 29 | /// 30 | /// 流恢复 31 | /// 32 | public ResumeType MarketDataTopicResumeType; 33 | public ResumeType PrivateTopicResumeType; 34 | public ResumeType PublicTopicResumeType; 35 | public ResumeType UserTopicResumeType; 36 | /// 37 | /// 经纪公司代码 38 | /// 39 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] 40 | public string BrokerID; 41 | /// 42 | /// 用户端产品信息 43 | /// 44 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] 45 | public string UserProductInfo; 46 | /// 47 | /// 认证码 48 | /// 49 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)] 50 | public string AuthCode; 51 | /// 52 | /// 地址 53 | /// 54 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 512)] 55 | public string Address; 56 | /// 57 | /// 配置文件路径 58 | /// 59 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] 60 | public string ConfigPath; 61 | /// 62 | /// 扩展信息 63 | /// 64 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] 65 | public string ExtInfoChar128; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /XApiSharp/SettlementInfoField.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/XApiSharp/SettlementInfoField.cs -------------------------------------------------------------------------------- /XApiSharp/TimeInForce.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | public enum TimeInForce : byte 4 | { 5 | ATC, 6 | Day, 7 | GTC, 8 | IOC, 9 | OPG, 10 | OC, 11 | FOK, 12 | GTX, 13 | GTD, 14 | GFS, 15 | AUC, 16 | }; 17 | } -------------------------------------------------------------------------------- /XApiSharp/TradeField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class TradeField 7 | { 8 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] 9 | public byte[] InstrumentName; 10 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 11 | public string Symbol; 12 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 31)] 13 | public string InstrumentID; 14 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)] 15 | public string ExchangeID; 16 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 17 | public string ClientID; 18 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 19 | public string AccountID; 20 | 21 | public OrderSide Side; 22 | public double Qty; 23 | public double Price; 24 | public OpenCloseType OpenClose; 25 | public HedgeFlagType HedgeFlag; 26 | public int Date; 27 | public int Time; 28 | 29 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 30 | public string ID; 31 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 32 | public string TradeID; 33 | 34 | public double Commission; 35 | 36 | public int ReserveInt32; 37 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 38 | public string ReserveChar64; 39 | 40 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 41 | public string PortfolioID1; 42 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 43 | public string PortfolioID2; 44 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 45 | public string PortfolioID3; 46 | 47 | public BusinessType Business; 48 | } 49 | } -------------------------------------------------------------------------------- /XApiSharp/TradingPhaseType.cs: -------------------------------------------------------------------------------- 1 | namespace QuantBox.XApi 2 | { 3 | ///交易阶段类型 4 | public enum TradingPhaseType : byte 5 | { 6 | /// 7 | /// 开盘前 8 | /// 9 | BeforeTrading, 10 | /// 11 | /// 非交易 12 | /// 13 | NoTrading, 14 | /// 15 | /// 连续交易 16 | /// 17 | Continuous, 18 | /// 19 | /// 集合竞价报单 20 | /// 21 | AuctionOrdering, 22 | /// 23 | /// 集合竞价价格平衡 24 | /// 25 | AuctionBalance, 26 | /// 27 | /// 集合竞价撮合 28 | /// 29 | AuctionMatch, 30 | /// 31 | /// 收盘 32 | /// 33 | Closed, 34 | /// 35 | /// 停牌时段,参考于LTS 36 | /// 37 | Suspension, 38 | /// 39 | /// 熔断时段,参考于LTS 40 | /// 41 | Fuse, 42 | /// 43 | /// 存量数据,TFData 44 | /// 45 | Repository 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /XApiSharp/UserInfoField.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace QuantBox.XApi 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 6 | public class UserInfoField 7 | { 8 | /// 9 | /// 用户代码 10 | /// 11 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] 12 | public string UserID; 13 | /// 14 | /// 密码 15 | /// 16 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 41)] 17 | public string Password; 18 | /// 19 | /// 扩展信息,通达信中用来做通讯密码 20 | /// 21 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] 22 | public string ExtInfoChar64; 23 | /// 24 | /// 扩展信息 25 | /// 26 | public int ExtInfoInt32; 27 | } 28 | } -------------------------------------------------------------------------------- /libs/CSharpHdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/libs/CSharpHdf.dll -------------------------------------------------------------------------------- /libs/Skyline.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantBox/QuantBoxXProvider/9dbf6adf72e72e4b29579e0e4ac04faa17e4f93f/libs/Skyline.Core.dll --------------------------------------------------------------------------------