├── .gitee └── ISSUE_TEMPLATE │ ├── bug.yml │ ├── config.yml │ ├── enhance.yml │ └── feature.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── env.ps1 ├── env.sh ├── lombok.config ├── northstar-api ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── org │ │ │ └── dromara │ │ │ │ └── northstar │ │ │ │ ├── ai │ │ │ │ ├── SampleData.java │ │ │ │ └── SamplingAware.java │ │ │ │ ├── common │ │ │ │ ├── BarDataAware.java │ │ │ │ ├── ContractBindedAware.java │ │ │ │ ├── GatewaySettings.java │ │ │ │ ├── IDataSource.java │ │ │ │ ├── IGatewayService.java │ │ │ │ ├── IHolidayManager.java │ │ │ │ ├── IModuleService.java │ │ │ │ ├── MessageSenderSettings.java │ │ │ │ ├── ObjectManager.java │ │ │ │ ├── SettingOptionsProvider.java │ │ │ │ ├── Subscribable.java │ │ │ │ ├── TickDataAware.java │ │ │ │ ├── Timed.java │ │ │ │ ├── TransactionAware.java │ │ │ │ ├── constant │ │ │ │ │ ├── ChannelType.java │ │ │ │ │ ├── ClosingPolicy.java │ │ │ │ │ ├── ConnectionState.java │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── DateTimeConstant.java │ │ │ │ │ ├── FieldType.java │ │ │ │ │ ├── GatewayUsage.java │ │ │ │ │ ├── GlobalSpringContext.java │ │ │ │ │ ├── ModuleState.java │ │ │ │ │ ├── ModuleType.java │ │ │ │ │ ├── ModuleUsage.java │ │ │ │ │ ├── Platform.java │ │ │ │ │ ├── PlaybackPrecision.java │ │ │ │ │ ├── PlaybackSpeed.java │ │ │ │ │ ├── ReturnCode.java │ │ │ │ │ ├── SignalOperation.java │ │ │ │ │ └── TickType.java │ │ │ │ ├── event │ │ │ │ │ ├── AbstractEventHandler.java │ │ │ │ │ ├── FastEventEngine.java │ │ │ │ │ ├── GenericEventHandler.java │ │ │ │ │ ├── NorthstarEvent.java │ │ │ │ │ └── NorthstarEventType.java │ │ │ │ ├── exception │ │ │ │ │ ├── AuthenticationException.java │ │ │ │ │ ├── InsufficientException.java │ │ │ │ │ ├── NoSuchElementException.java │ │ │ │ │ ├── TradeException.java │ │ │ │ │ └── ValueMismatchException.java │ │ │ │ ├── model │ │ │ │ │ ├── AccountRuntimeDescription.java │ │ │ │ │ ├── ComponentAndParamsPair.java │ │ │ │ │ ├── ComponentField.java │ │ │ │ │ ├── ComponentMetaInfo.java │ │ │ │ │ ├── ContractSimpleInfo.java │ │ │ │ │ ├── DynamicParams.java │ │ │ │ │ ├── GatewayDescription.java │ │ │ │ │ ├── GatewayTypeDescription.java │ │ │ │ │ ├── Identifier.java │ │ │ │ │ ├── ListValue.java │ │ │ │ │ ├── LogDescription.java │ │ │ │ │ ├── MailConfigDescription.java │ │ │ │ │ ├── MockTradeDescription.java │ │ │ │ │ ├── ModuleAccountDescription.java │ │ │ │ │ ├── ModuleAccountRuntimeDescription.java │ │ │ │ │ ├── ModuleDealRecord.java │ │ │ │ │ ├── ModuleDescription.java │ │ │ │ │ ├── ModulePositionDescription.java │ │ │ │ │ ├── ModuleRuntimeDescription.java │ │ │ │ │ ├── NsUser.java │ │ │ │ │ ├── NumberValue.java │ │ │ │ │ ├── OptionItem.java │ │ │ │ │ ├── OrderRecall.java │ │ │ │ │ ├── OrderRequest.java │ │ │ │ │ ├── PlaybackRuntimeDescription.java │ │ │ │ │ ├── ResultBean.java │ │ │ │ │ ├── ResultSet.java │ │ │ │ │ ├── Setting.java │ │ │ │ │ ├── SimAccountDescription.java │ │ │ │ │ ├── StringValue.java │ │ │ │ │ ├── TimeSeriesValue.java │ │ │ │ │ ├── Tuple.java │ │ │ │ │ ├── Value.java │ │ │ │ │ └── core │ │ │ │ │ │ ├── Account.java │ │ │ │ │ │ ├── Bar.java │ │ │ │ │ │ ├── Contract.java │ │ │ │ │ │ ├── ContractDefinition.java │ │ │ │ │ │ ├── Notice.java │ │ │ │ │ │ ├── Order.java │ │ │ │ │ │ ├── Position.java │ │ │ │ │ │ ├── SubmitOrderReq.java │ │ │ │ │ │ ├── Tick.java │ │ │ │ │ │ ├── TimeSlot.java │ │ │ │ │ │ ├── Trade.java │ │ │ │ │ │ └── TradeTimeDefinition.java │ │ │ │ └── utils │ │ │ │ │ ├── CommonUtils.java │ │ │ │ │ ├── DateTimeUtils.java │ │ │ │ │ ├── FieldUtils.java │ │ │ │ │ ├── LocalEnvUtils.java │ │ │ │ │ ├── MarketDataUtils.java │ │ │ │ │ ├── MessagePrinter.java │ │ │ │ │ ├── OrderUtils.java │ │ │ │ │ ├── TradeHelper.java │ │ │ │ │ └── TradeTimeUtil.java │ │ │ │ ├── data │ │ │ │ ├── IGatewayRepository.java │ │ │ │ ├── IMarketDataRepository.java │ │ │ │ ├── IMessageSenderRepository.java │ │ │ │ ├── IModuleRepository.java │ │ │ │ ├── IPlaybackRuntimeRepository.java │ │ │ │ └── ISimAccountRepository.java │ │ │ │ ├── gateway │ │ │ │ ├── Gateway.java │ │ │ │ ├── GatewayFactory.java │ │ │ │ ├── GatewayMetaProvider.java │ │ │ │ ├── IContract.java │ │ │ │ ├── IContractManager.java │ │ │ │ ├── IMarketCenter.java │ │ │ │ ├── Instrument.java │ │ │ │ ├── MarketGateway.java │ │ │ │ ├── TradeGateway.java │ │ │ │ ├── contract │ │ │ │ │ ├── GatewayContract.java │ │ │ │ │ ├── IndexContract.java │ │ │ │ │ ├── OptionChainContract.java │ │ │ │ │ └── PrimaryContract.java │ │ │ │ ├── mktdata │ │ │ │ │ ├── DataSourceDataLoader.java │ │ │ │ │ ├── EmptyDataSource.java │ │ │ │ │ ├── IndexTicker.java │ │ │ │ │ ├── MarketCenter.java │ │ │ │ │ ├── MinuteBarGenerator.java │ │ │ │ │ ├── NorthstarDataSource.java │ │ │ │ │ └── QuantitDataServiceManager.java │ │ │ │ └── utils │ │ │ │ │ └── DataLoadUtil.java │ │ │ │ ├── indicator │ │ │ │ ├── AbstractIndicator.java │ │ │ │ ├── Indicator.java │ │ │ │ ├── constant │ │ │ │ │ ├── PeriodUnit.java │ │ │ │ │ └── ValueType.java │ │ │ │ ├── helper │ │ │ │ │ ├── DiffIndicator.java │ │ │ │ │ ├── HHVIndicator.java │ │ │ │ │ ├── LLVIndicator.java │ │ │ │ │ ├── NormalizeIndicator.java │ │ │ │ │ ├── SimpleValueIndicator.java │ │ │ │ │ ├── StandardDeviationIndicator.java │ │ │ │ │ ├── SumIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── model │ │ │ │ │ ├── Configuration.java │ │ │ │ │ ├── Num.java │ │ │ │ │ └── RingArray.java │ │ │ │ ├── momentum │ │ │ │ │ ├── KDIndicator.java │ │ │ │ │ ├── RSIIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── trend │ │ │ │ │ ├── EMAIndicator.java │ │ │ │ │ ├── MACDIndicator.java │ │ │ │ │ ├── MAIndicator.java │ │ │ │ │ ├── PBXIndicator.java │ │ │ │ │ ├── PuBuIndicator.java │ │ │ │ │ ├── SMAIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── volatility │ │ │ │ │ ├── BOLLIndicator.java │ │ │ │ │ ├── TrueRangeIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── volume │ │ │ │ │ ├── ExpandedVolumeThresholdIndicator.java │ │ │ │ │ ├── IntraDaySettlePriceIndicator.java │ │ │ │ │ ├── VWAPIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ └── wave │ │ │ │ │ ├── MABasedWaveIndicator.java │ │ │ │ │ └── package-info.java │ │ │ │ └── strategy │ │ │ │ ├── AbstractStrategy.java │ │ │ │ ├── ContextAware.java │ │ │ │ ├── DynamicParamsAware.java │ │ │ │ ├── IAccount.java │ │ │ │ ├── IDisposablePriceListener.java │ │ │ │ ├── IEmbededRule.java │ │ │ │ ├── IMessageSender.java │ │ │ │ ├── IModule.java │ │ │ │ ├── IModuleAccount.java │ │ │ │ ├── IModuleContext.java │ │ │ │ ├── IModuleStrategyContext.java │ │ │ │ ├── MergedBarListener.java │ │ │ │ ├── OrderRequestFilter.java │ │ │ │ ├── StrategicComponent.java │ │ │ │ ├── TradeStrategy.java │ │ │ │ ├── constant │ │ │ │ ├── DisposablePriceListenerType.java │ │ │ │ └── PriceType.java │ │ │ │ ├── model │ │ │ │ └── TradeIntent.java │ │ │ │ └── tester │ │ │ │ ├── AbstractTester.java │ │ │ │ ├── ModuleTesterContext.java │ │ │ │ └── ModuleTesterRunner.java │ │ └── xyz │ │ │ └── redtorch │ │ │ └── pb │ │ │ ├── CoreEnum.java │ │ │ └── CoreField.java │ └── resources │ │ └── proto │ │ └── xyz │ │ └── redtorch │ │ └── pb │ │ ├── core_enum.proto │ │ └── core_field.proto │ └── test │ └── java │ └── org │ └── dromara │ └── northstar │ ├── common │ ├── constant │ │ ├── ChannelTypeTest.java │ │ ├── ClosingPolicyTest.java │ │ └── ModuleStateTest.java │ ├── model │ │ └── core │ │ │ ├── AccountTest.java │ │ │ ├── BarTest.java │ │ │ ├── ContractTest.java │ │ │ ├── NoticeTest.java │ │ │ ├── OrderTest.java │ │ │ ├── PositionTest.java │ │ │ ├── SubmitOrderReqTest.java │ │ │ ├── TickTest.java │ │ │ ├── TradeTest.java │ │ │ └── TradeTimeDefinitionTest.java │ └── utils │ │ ├── CommonUtilsTest.java │ │ ├── ContractSymbolPatternTest.java │ │ ├── DateTimeUtilsTest.java │ │ ├── FieldUtilsTest.java │ │ ├── LocalEnvUtilsTest.java │ │ ├── MarketDataUtilsTest.java │ │ ├── OrderUtilsTest.java │ │ ├── TradeHelperTest.java │ │ └── TradeTimeUtilTest.java │ ├── gateway │ ├── GatewayMetaProviderTest.java │ └── mktdata │ │ ├── DataSourceDataLoaderTest.java │ │ ├── EmptyDataSourceTest.java │ │ ├── IndexTickerTest.java │ │ ├── MarketCenterTest.java │ │ ├── MinuteBarGeneratorTest.java │ │ ├── NorthstarDataSourceTest.java │ │ └── QuantitDataServiceManagerTest.java │ ├── indicator │ ├── AbstractIndicatorTest.java │ ├── helper │ │ └── SimpleValueIndicatorTest.java │ ├── model │ │ ├── ConfigurationTest.java │ │ └── RingArrayTest.java │ ├── trend │ │ └── MAIndicatorTest.java │ ├── volume │ │ └── VWAPIndicatorTest.java │ └── wave │ │ └── MABasedWaveIndicatorTest.java │ └── strategy │ └── model │ └── TradeIntentTest.java ├── northstar-external-archetype ├── pom.xml └── src │ └── main │ └── resources │ ├── META-INF │ └── maven │ │ └── archetype-metadata.xml │ └── archetype-resources │ ├── pom.xml │ └── src │ └── main │ └── java │ ├── ExternalConfig.java │ ├── gateway │ └── package-info.java │ ├── indicator │ └── package-info.java │ └── strategy │ └── ExternalSampleStrategy.java ├── northstar-gateway-playback ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── dromara │ │ └── northstar │ │ └── gateway │ │ └── playback │ │ ├── IPlaybackContext.java │ │ ├── PlaybackConfig.java │ │ ├── PlaybackContext.java │ │ ├── PlaybackContract.java │ │ ├── PlaybackContractDefProvider.java │ │ ├── PlaybackDataLoader.java │ │ ├── PlaybackGatewayAdapter.java │ │ ├── PlaybackGatewayFactory.java │ │ ├── PlaybackGatewaySettings.java │ │ ├── PlaybackLoader.java │ │ ├── model │ │ └── DataFrame.java │ │ └── ticker │ │ ├── RandomWalkTickSimulation.java │ │ ├── SimpleCloseSimulation.java │ │ ├── SimplePriceSimulation.java │ │ ├── TickEntry.java │ │ └── TickSimulationAlgorithm.java │ └── test │ └── java │ └── org │ └── dromara │ └── northstar │ └── gateway │ └── playback │ ├── PlaybackContractDefProviderTest.java │ ├── PlaybackDataLoaderTest.java │ ├── model │ └── DataFrameTest.java │ └── ticker │ └── RandomWalkTickSimulationTest.java ├── northstar-gateway-sim ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── dromara │ │ └── northstar │ │ └── gateway │ │ └── sim │ │ ├── SimConfig.java │ │ ├── SimContractDefProvider.java │ │ ├── SimLoader.java │ │ ├── market │ │ ├── SimMarketGatewayLocal.java │ │ └── SimTickGenerator.java │ │ └── trade │ │ ├── Deal.java │ │ ├── OrderReqManager.java │ │ ├── OrderRequest.java │ │ ├── PositionManager.java │ │ ├── SimContract.java │ │ ├── SimContractGenerator.java │ │ ├── SimGatewayAccount.java │ │ ├── SimGatewayFactory.java │ │ ├── SimTradeGateway.java │ │ ├── SimTradeGatewayLocal.java │ │ ├── TradePosition.java │ │ └── Transaction.java │ └── test │ └── java │ └── org │ └── dromara │ └── northstar │ └── gateway │ └── sim │ └── trade │ ├── DealTest.java │ ├── OrderReqManagerTest.java │ ├── OrderRequestTest.java │ ├── PositionManagerTest.java │ ├── SimContractGeneratorTest.java │ ├── SimGatewayAccountTest.java │ ├── SimGatewayFactoryTest.java │ ├── SimTradeGatewayLocalTest.java │ └── TradePositionTest.java ├── northstar-intelligence ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── dromara │ │ └── northstar │ │ └── ai │ │ ├── AbstractModelBasedStrategy.java │ │ ├── infer │ │ └── PretrainedModel.java │ │ └── sampling │ │ └── SampleDataWriter.java │ └── test │ └── java │ └── org │ └── dromara │ └── northstar │ └── ai │ ├── infer │ └── PretrainedModelTest.java │ └── sampling │ └── SampleDataWriterTest.java ├── northstar-main ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── dromara │ │ │ └── northstar │ │ │ ├── NorthstarApplication.java │ │ │ ├── YamlAndPropertySourceFactory.java │ │ │ ├── account │ │ │ ├── AccountManager.java │ │ │ ├── GatewayManager.java │ │ │ └── TradeAccount.java │ │ │ ├── config │ │ │ ├── AppConfig.java │ │ │ ├── CacheConfig.java │ │ │ ├── EngineConfig.java │ │ │ ├── GatewayConfig.java │ │ │ ├── InternalEventHandlerConfig.java │ │ │ ├── RepositoryConfig.java │ │ │ ├── ServiceConfig.java │ │ │ ├── SocketIOServerConfig.java │ │ │ └── UserInfo.java │ │ │ ├── data │ │ │ └── jdbc │ │ │ │ ├── GatewayDescriptionRepository.java │ │ │ │ ├── GatewayRepoAdapter.java │ │ │ │ ├── MarketDataRepoAdapter.java │ │ │ │ ├── MarketDataRepository.java │ │ │ │ ├── MessageSenderSettingsRepoAdapter.java │ │ │ │ ├── MessageSenderSettingsRepository.java │ │ │ │ ├── ModuleDealRecordRepository.java │ │ │ │ ├── ModuleDescriptionRepository.java │ │ │ │ ├── ModuleRepoAdapter.java │ │ │ │ ├── ModuleRuntimeDescriptionRepository.java │ │ │ │ ├── NotificationEventRepository.java │ │ │ │ ├── PlaybackRuntimeRepoAdapter.java │ │ │ │ ├── PlaybackRuntimeRepository.java │ │ │ │ ├── SimAccountRepoAdapter.java │ │ │ │ ├── SimAccountRepository.java │ │ │ │ └── entity │ │ │ │ ├── BarDO.java │ │ │ │ ├── GatewayDescriptionDO.java │ │ │ │ ├── MessageSenderSettingsDO.java │ │ │ │ ├── ModuleDealRecordDO.java │ │ │ │ ├── ModuleDescriptionDO.java │ │ │ │ ├── ModuleRuntimeDescriptionDO.java │ │ │ │ ├── PlaybackRuntimeDescriptionDO.java │ │ │ │ ├── SimAccountDescriptionDO.java │ │ │ │ └── SubscriptionEventsDO.java │ │ │ ├── event │ │ │ ├── AccountHandler.java │ │ │ ├── BroadcastHandler.java │ │ │ ├── ConnectionHandler.java │ │ │ ├── DisruptorFastEventEngine.java │ │ │ ├── EventNotificationHandler.java │ │ │ ├── IllegalOrderHandler.java │ │ │ ├── InternalDispatcher.java │ │ │ ├── MarketDataHandler.java │ │ │ ├── ModuleHandler.java │ │ │ └── SimMarketHandler.java │ │ │ ├── indicator │ │ │ ├── IndicatorValueUpdateHelper.java │ │ │ └── InstantBarGenerator.java │ │ │ ├── module │ │ │ ├── ArbitrageModuleContext.java │ │ │ ├── DefaultOrderFilter.java │ │ │ ├── DisposablePriceListener.java │ │ │ ├── ModuleAccount.java │ │ │ ├── ModuleContext.java │ │ │ ├── ModuleManager.java │ │ │ ├── ModulePosition.java │ │ │ ├── ModuleStateMachine.java │ │ │ ├── PlaybackModuleContext.java │ │ │ └── TradeModule.java │ │ │ ├── support │ │ │ ├── ServiceLoader.java │ │ │ ├── job │ │ │ │ ├── AppScheduleTask.java │ │ │ │ └── ModuleCheckingTask.java │ │ │ ├── log │ │ │ │ └── ModuleLoggerFactory.java │ │ │ └── utils │ │ │ │ ├── BarCacheKeyGenerator.java │ │ │ │ ├── CodecUtils.java │ │ │ │ ├── ExceptionLogChecker.java │ │ │ │ ├── NamingValidator.java │ │ │ │ ├── PositionChecker.java │ │ │ │ ├── ProtoBeanUtils.java │ │ │ │ ├── SpringContextUtil.java │ │ │ │ └── bar │ │ │ │ ├── BarMerger.java │ │ │ │ ├── BarMergerRegistry.java │ │ │ │ └── DailyBarMerger.java │ │ │ └── web │ │ │ ├── PostLoadAware.java │ │ │ ├── interceptor │ │ │ └── AuthorizationInterceptor.java │ │ │ ├── restful │ │ │ ├── AlertingController.java │ │ │ ├── AuthenticationController.java │ │ │ ├── ContractController.java │ │ │ ├── GatewayDataController.java │ │ │ ├── GatewayManagementController.java │ │ │ ├── LogController.java │ │ │ ├── ModuleController.java │ │ │ ├── TradeOperationController.java │ │ │ ├── VersionController.java │ │ │ └── common │ │ │ │ └── CommonControllerAdvice.java │ │ │ └── service │ │ │ ├── AccountService.java │ │ │ ├── GatewayService.java │ │ │ ├── LogService.java │ │ │ └── ModuleService.java │ └── resources │ │ ├── .gitignore │ │ ├── application.yml │ │ ├── banner.txt │ │ ├── ehcache.xml │ │ ├── keystore │ │ └── northstarKeyStore.p12 │ │ └── logback-spring.xml │ └── test │ └── java │ ├── common │ └── TestGatewayFactory.java │ └── org │ └── dromara │ └── northstar │ ├── ArbitrageModuleTest.java │ ├── CtaModuleTest.java │ ├── PlaybackModuleTest.java │ ├── account │ ├── AccountManagerTest.java │ ├── GatewayManagerTest.java │ └── TradeAccountTest.java │ ├── data │ └── jdbc │ │ ├── GatewayRepoAdapterTest.java │ │ ├── MarketDataRepoAdapterTest.java │ │ ├── MarketDataRepositoryTest.java │ │ ├── MessageSenderSettingsRepoAdapterTest.java │ │ ├── ModuleRepoAdapterTest.java │ │ ├── PlaybackRuntimeRepoAdapterTest.java │ │ └── SimAccountRepoAdapterTest.java │ ├── indicator │ └── RingArrayTest.java │ ├── module │ ├── DisposablePriceListenerTest.java │ ├── ModuleAccountTest.java │ ├── ModuleManagerTest.java │ ├── ModulePositionTest.java │ ├── ModuleStateMachineTest.java │ └── TradeModuleTest.java │ ├── support │ ├── log │ │ └── ModuleLoggerFactoryTest.java │ └── utils │ │ ├── ExceptionLogCheckerTest.java │ │ ├── NamingValidatorTest.java │ │ ├── PositionCheckerTest.java │ │ └── bar │ │ ├── BarMergerRegistryTest.java │ │ ├── BarMergerTest.java │ │ └── DailyBarMergerTest.java │ ├── utils │ └── CodecUtilsTest.java │ └── web │ └── restful │ ├── ContractControllerTest.java │ ├── GatewayDataControllerTest.java │ ├── GatewayManagementTest.java │ └── ModuleControllerTest.java ├── northstar-monitor ├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── .prettierrc.js ├── LICENSE ├── README.md ├── babel.config.js ├── deploy.sh ├── e2e │ ├── cypress.json │ ├── cypress │ │ ├── fixtures │ │ │ └── example.json │ │ ├── integration │ │ │ └── 0-northstar-e2e │ │ │ │ ├── GatewayMgmt.cy.js │ │ │ │ ├── LogView.cy.js │ │ │ │ ├── LoginView.cy.js │ │ │ │ ├── ModuleMgmt.cy.js │ │ │ │ └── TradeView.cy.js │ │ ├── plugins │ │ │ └── index.js │ │ └── support │ │ │ ├── commands.js │ │ │ ├── component-index.html │ │ │ ├── component.js │ │ │ ├── e2e.js │ │ │ └── index.js │ ├── package-lock.json │ └── package.json ├── electron-egg │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── README.zh-CN.md │ ├── appveyor.yml │ ├── build │ │ ├── extraResources │ │ │ └── placeholder.txt │ │ └── icons │ │ │ ├── 256x256.png │ │ │ ├── 32x32.png │ │ │ ├── 512x512.png │ │ │ ├── 64x64.png │ │ │ └── icon.ico │ ├── electron │ │ ├── addon │ │ │ ├── autoUpdater │ │ │ │ └── index.js │ │ │ ├── awaken │ │ │ │ └── index.js │ │ │ ├── chromeExtension │ │ │ │ └── index.js │ │ │ ├── example │ │ │ │ └── index.js │ │ │ ├── javaServer │ │ │ │ ├── index.js │ │ │ │ ├── ps.js │ │ │ │ └── server.js │ │ │ ├── security │ │ │ │ └── index.js │ │ │ └── tray │ │ │ │ └── index.js │ │ ├── config │ │ │ ├── config.default.js │ │ │ ├── config.local.js │ │ │ ├── config.prod.js │ │ │ ├── encrypt.js │ │ │ └── nodemon.json │ │ ├── controller │ │ │ └── example.js │ │ ├── preload │ │ │ ├── bridge.js │ │ │ └── index.js │ │ └── service │ │ │ ├── example.js │ │ │ └── storage.js │ ├── main.js │ ├── package.json │ ├── public │ │ ├── html │ │ │ ├── loading.html │ │ │ └── view_example.html │ │ ├── images │ │ │ ├── loding.gif │ │ │ ├── logo-32.png │ │ │ ├── logo.png │ │ │ └── tray_logo.png │ │ └── ssl │ │ │ ├── localhost+1.key │ │ │ └── localhost+1.pem │ └── update.md ├── jsconfig.json ├── package-lock.json ├── package.json ├── pom.xml ├── public │ ├── index.html │ ├── logo │ │ ├── logo.png │ │ └── logo.svg │ ├── ns.ico │ └── static │ │ ├── axios@0.21.1.js │ │ ├── element-ui@2.15.8.js │ │ ├── index.css │ │ ├── theme │ │ ├── fonts │ │ │ ├── element-icons.ttf │ │ │ └── element-icons.woff │ │ └── index.css │ │ └── vue@2.6.12.js ├── shutdown.sh ├── src │ ├── App.vue │ ├── api │ │ ├── alertingApi.js │ │ ├── baseRequest.js │ │ ├── contractApi.js │ │ ├── gatewayDataApi.js │ │ ├── gatewayMgmtApi.js │ │ ├── logApi.js │ │ ├── loginApi.js │ │ ├── moduleApi.js │ │ └── tradeOprApi.js │ ├── assets │ │ ├── logo.png │ │ ├── style │ │ │ ├── config.json │ │ │ └── index.css │ │ ├── wx.jpg │ │ └── 知识星球.jpg │ ├── components │ │ ├── AccountDetail.vue │ │ ├── GatewayForm.vue │ │ ├── GatewaySettingsForm.vue │ │ ├── MarketData.vue │ │ ├── MessageConfigForm.vue │ │ ├── ModuleForm.vue │ │ ├── ModulePerformance.vue │ │ ├── ModulePerformancePopup.vue │ │ ├── ModulePositionForm.vue │ │ ├── ModuleRuntime.vue │ │ ├── PlaybackForm.vue │ │ ├── PriceBoard.vue │ │ ├── SidePanel.vue │ │ ├── SimBalanceMgmt.vue │ │ ├── SocketConnection.vue │ │ └── TradeButton.vue │ ├── filter │ │ └── number-filter.js │ ├── lib │ │ ├── indicator │ │ │ ├── open-interest.js │ │ │ ├── simple-value.js │ │ │ └── volume-pure.js │ │ └── xyz │ │ │ └── redtorch │ │ │ └── pb │ │ │ ├── core_enum_pb.js │ │ │ └── core_field_pb.js │ ├── main.js │ ├── router │ │ └── index.js │ ├── store │ │ ├── index.js │ │ └── modules │ │ │ ├── accountModule.js │ │ │ ├── contractModule.js │ │ │ ├── marketCurrentDataModule.js │ │ │ └── moduleInfoModule.js │ ├── utils.js │ ├── utils │ │ ├── file-utils.js │ │ ├── kline-utils.js │ │ └── media-utils.js │ └── views │ │ ├── GatewayMgmt.vue │ │ ├── LogTailingView.vue │ │ ├── LoginView.vue │ │ ├── ModuleMgmt.vue │ │ ├── NotImplemented.vue │ │ ├── TradeView.vue │ │ └── WorkspaceView.vue ├── startup.sh └── vue.config.js ├── northstar-strategy-example ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── dromara │ └── northstar │ └── strategy │ └── example │ ├── BeginnerExampleStrategy.java │ ├── DualAccountExampleStrategy.java │ ├── IndicatorDemoStrategy.java │ ├── IndicatorExampleStrategy.java │ ├── LongPeriodExampleStrategy.java │ ├── MultiPeriodExampleStrategy.java │ ├── OrderingTestStrategy.java │ └── SimpleSpreadStrategy.java ├── pom.xml ├── settings.xml ├── startup.sh └── update-protobuf-obj.ps1 /.gitee/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug 反馈 2 | description: 当你在代码中发现了一个 Bug,导致应用崩溃或抛出异常,或者有一个组件存在问题,或者某些地方看起来不对劲。 3 | title: "[Bug]: " 4 | labels: ["bug"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | 感谢对项目的支持与关注。在提出问题之前,请确保你已查看相关开发或使用文档: 10 | - https://www.quantit.tech 11 | - type: checkboxes 12 | attributes: 13 | label: 这个问题是否已经存在? 14 | options: 15 | - label: 我已经搜索过现有的问题 (https://gitee.com/dromara/northstar/issues) 16 | required: true 17 | - type: textarea 18 | attributes: 19 | label: 如何复现 20 | description: 请详细告诉我们如何复现你遇到的问题,如涉及代码,可提供一个最小代码示例,并使用反引号```附上它 21 | placeholder: | 22 | 1. ... 23 | 2. ... 24 | 3. ... 25 | validations: 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: 预期结果 30 | description: 请告诉我们你预期会发生什么。 31 | validations: 32 | required: true 33 | - type: textarea 34 | attributes: 35 | label: 实际结果 36 | description: 请告诉我们实际发生了什么。 37 | validations: 38 | required: true 39 | - type: textarea 40 | attributes: 41 | label: 截图或视频 42 | description: 如果可以的话,上传任何关于 bug 的截图。 43 | value: | 44 | [在这里上传图片] 45 | - type: input 46 | id: prevalence 47 | attributes: 48 | label: 问题版本号 49 | description: 你当前正在使用我们软件的哪个版本/分支? 50 | placeholder: v6.0.0 51 | validations: 52 | required: true -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Gitee 帮助中心 4 | url: https://help.gitee.com/ 5 | about: 提供 Git 使用指南、教程、Gitee.com 平台基本功能使用、介绍和常见问题解答 -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/enhance.yml: -------------------------------------------------------------------------------- 1 | name: 优化 2 | title: "[优化]: " 3 | labels: ["enhancement"] 4 | body: 5 | - type: textarea 6 | attributes: 7 | label: 现存问题 8 | description: 请详细说明问题,并附上必要的截图说明 9 | placeholder: | 10 | 1. ... 11 | 2. ... 12 | 3. ... 13 | validations: 14 | required: true 15 | - type: textarea 16 | attributes: 17 | label: 优化方案 18 | description: 请说明优化方案。 19 | validations: 20 | required: true 21 | - type: textarea 22 | attributes: 23 | label: 优化效果验证 24 | description: 请告诉附上优化前后的效果对比。 25 | validations: 26 | required: true 27 | - type: input 28 | id: prevalence 29 | attributes: 30 | label: 问题版本号 31 | description: 你当前正在使用我们软件的哪个版本/分支? 32 | placeholder: v6.0.0 33 | validations: 34 | required: true -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: 功能建议 2 | description: 对本项目提出一个功能建议 3 | title: "[功能建议]: " 4 | labels: ["enhancement"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | 感谢提出功能建议,我们将仔细考虑! 10 | - type: textarea 11 | id: related-problem 12 | attributes: 13 | label: 你的功能建议是否和某个问题相关? 14 | description: 清晰并简洁地描述问题是什么,例如,当我...时,我总是感到困扰。 15 | validations: 16 | required: false 17 | - type: textarea 18 | id: desired-solution 19 | attributes: 20 | label: 你希望看到什么解决方案? 21 | description: 清晰并简洁地描述你希望发生的事情。 22 | validations: 23 | required: true 24 | - type: textarea 25 | id: alternatives 26 | attributes: 27 | label: 你考虑过哪些替代方案? 28 | description: 清晰并简洁地描述你考虑过的任何替代解决方案或功能。 29 | validations: 30 | required: false 31 | - type: textarea 32 | id: additional-context 33 | attributes: 34 | label: 你有其他上下文或截图吗? 35 | description: 在此处添加有关功能请求的任何其他上下文或截图。 36 | validations: 37 | required: false 38 | - type: checkboxes 39 | attributes: 40 | label: 意向参与贡献 41 | options: 42 | - label: 我有意向参与具体功能的开发实现并将代码贡献回到上游社区 43 | required: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | deploy/ 4 | logs/ 5 | **/.mvn/** 6 | !**/src/main/** 7 | !**/src/test/** 8 | release.properties 9 | *.releaseBackup 10 | **/*.releaseBackup 11 | *.versionsBackup 12 | **/*.versionsBackup 13 | .lh 14 | 15 | ### STS ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### IntelliJ IDEA ### 25 | .idea 26 | *.iws 27 | *.iml 28 | *.ipr 29 | 30 | ### NetBeans ### 31 | /nbproject/private/ 32 | /nbbuild/ 33 | /dist/ 34 | /nbdist/ 35 | /.nb-gradle/ 36 | build/ 37 | 38 | ### VS Code ### 39 | .vscode/ 40 | /pom.xml.versionsBackup 41 | /northstar-dist/ 42 | /.metadata/ 43 | 44 | **/__pycache__/ 45 | northstar-rl/python-app/models 46 | .flattened-pom.xml 47 | /data/ 48 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 使用官方CentOS 8基础映像 2 | FROM openjdk:21 3 | 4 | # 创建工作目录 5 | RUN mkdir -p /northstar-dist 6 | WORKDIR /northstar-dist 7 | 8 | # 复制当前目录下的所有*.jar文件到工作目录 9 | COPY ./*.jar ./ 10 | COPY ./*.json ./ 11 | 12 | ENV NS_USER=admin 13 | ENV NS_PWD=123456 14 | ENV TZ=Asia/Shanghai 15 | 16 | # 添加启动脚本 17 | RUN echo 'java -Denv=prod -Dloader.path=/northstar-dist -jar /northstar-dist/northstar-*.jar' > /northstar-dist/entrypoint.sh 18 | 19 | EXPOSE 443 20 | EXPOSE 51688 21 | 22 | # 运行启动脚本 23 | CMD ["bash","/northstar-dist/entrypoint.sh"] -------------------------------------------------------------------------------- /env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "准备环境依赖..." 6 | yum install git wget -y 7 | 8 | mkdir -p ~/northstar-env ~/northstar-dist 9 | 10 | # 检查JDK环境 11 | if [[ $(which java >/dev/null && echo $?) != 0 ]]; 12 | then 13 | echo "安装JDK21" 14 | cd ~/northstar-env && wget --no-check-certificate https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz 15 | tar -xvf jdk-21_linux-x64_bin.tar.gz 16 | rm -f jdk-21_linux-x64_bin.tar.gz 17 | ln -sf ~/northstar-env/$(find jdk* -maxdepth 0 -type d)/bin/* /usr/local/bin/ 18 | else 19 | echo "JDK21已安装" 20 | java -version 21 | fi 22 | 23 | echo "环境安装完成" -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.addLombokGeneratedAnnotation=true -------------------------------------------------------------------------------- /northstar-api/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | log/ 4 | test-output/** 5 | !.mvn/wrapper/maven-wrapper.jar 6 | !**/src/main/** 7 | !**/src/test/** 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | /test-output/ 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/ai/SamplingAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.ai; 2 | 3 | public interface SamplingAware { 4 | 5 | /** 6 | * 采样 7 | * @return 8 | */ 9 | SampleData sample(); 10 | 11 | /** 12 | * 是否处于采样阶段 13 | * @return 14 | */ 15 | boolean isSampling(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/BarDataAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.core.Bar; 4 | 5 | /** 6 | * BAR行情组件 7 | * @author KevinHuangwl 8 | * 9 | */ 10 | public interface BarDataAware { 11 | 12 | 13 | void onBar(Bar bar); 14 | } 15 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/ContractBindedAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.core.Contract; 4 | 5 | public interface ContractBindedAware { 6 | 7 | String bindedContractSymbol(); 8 | 9 | void setBindedContract(Contract contract); 10 | } 11 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/GatewaySettings.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | /** 4 | * 网关配置信息标记 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public interface GatewaySettings { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/IGatewayService.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.GatewayDescription; 4 | 5 | public interface IGatewayService { 6 | 7 | /** 8 | * 创建网关 9 | * @return 10 | * @throws Exception 11 | */ 12 | boolean createGateway(GatewayDescription gatewayDescription); 13 | 14 | /** 15 | * 更新网关 16 | * @return 17 | * @throws Exception 18 | */ 19 | boolean updateGateway(GatewayDescription gatewayDescription); 20 | 21 | /** 22 | * 移除网关 23 | * @return 24 | */ 25 | boolean deleteGateway(String gatewayId); 26 | 27 | /** 28 | * 连接网关 29 | * @return 30 | */ 31 | boolean connect(String gatewayId); 32 | 33 | /** 34 | * 断开网关 35 | * @return 36 | */ 37 | boolean disconnect(String gatewayId); 38 | 39 | /** 40 | * 模拟出入金 41 | * @param money 42 | * @return 43 | */ 44 | boolean simMoneyIO(String gatewayId, int money); 45 | 46 | /** 47 | * 复位重置回放网关 48 | * @param gatewayId 49 | * @return 50 | * @throws Exception 51 | */ 52 | boolean resetPlayback(String gatewayId); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/IHolidayManager.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.dromara.northstar.common.constant.ChannelType; 6 | 7 | public interface IHolidayManager { 8 | 9 | ChannelType channelType(); 10 | 11 | boolean isHoliday(LocalDateTime dateTime); 12 | } 13 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/IModuleService.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.ModuleDescription; 4 | 5 | public interface IModuleService { 6 | 7 | /** 8 | * 增加模组 9 | * @param md 10 | * @return 11 | * @throws Exception 12 | */ 13 | ModuleDescription createModule(ModuleDescription md) throws Exception; 14 | 15 | /** 16 | * 修改模组 17 | * @param md 18 | * @return 19 | * @throws Exception 20 | */ 21 | ModuleDescription modifyModule(ModuleDescription md, boolean reset) throws Exception; 22 | 23 | /** 24 | * 删除模组 25 | * @param name 26 | * @return 27 | */ 28 | boolean removeModule(String name); 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/MessageSenderSettings.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | /** 4 | * 消息发送器配置标记 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public interface MessageSenderSettings { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/ObjectManager.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.model.Identifier; 6 | 7 | public interface ObjectManager { 8 | 9 | void add(T t); 10 | 11 | void remove(Identifier id); 12 | 13 | T get(Identifier id); 14 | 15 | boolean contains(Identifier id); 16 | 17 | List findAll(); 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/SettingOptionsProvider.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.model.OptionItem; 6 | 7 | public interface SettingOptionsProvider { 8 | 9 | /** 10 | * 提供选项列表值 11 | * @return 12 | */ 13 | List optionVals(); 14 | } 15 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/Subscribable.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | /** 4 | * 可订阅接口 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public interface Subscribable { 9 | 10 | /** 11 | * 订阅 12 | * @return 13 | */ 14 | boolean subscribe(); 15 | 16 | /** 17 | * 取消订阅 18 | * @return 19 | */ 20 | boolean unsubscribe(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/TickDataAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.core.Tick; 4 | 5 | /** 6 | * TICK行情组件 7 | * @author KevinHuangwl 8 | * 9 | */ 10 | public interface TickDataAware { 11 | 12 | 13 | void onTick(Tick tick); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/Timed.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | public interface Timed { 4 | 5 | long getTimestamp(); 6 | } 7 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/TransactionAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common; 2 | 3 | import org.dromara.northstar.common.model.core.Order; 4 | import org.dromara.northstar.common.model.core.Trade; 5 | 6 | public interface TransactionAware { 7 | 8 | /** 9 | * 响应订单事件 10 | * @param order 11 | */ 12 | void onOrder(Order order); 13 | 14 | /** 15 | * 响应成交事件 16 | * @param trade 17 | */ 18 | void onTrade(Trade trade); 19 | } 20 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/ConnectionState.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum ConnectionState { 4 | 5 | CONNECTING, 6 | CONNECTED, 7 | DISCONNECTING, 8 | DISCONNECTED; 9 | } 10 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public interface Constants { 4 | 5 | Double ZERO_D = 0D; 6 | 7 | Integer ZERO = 0; 8 | 9 | String INDEX_SUFFIX = "0000"; 10 | 11 | String PRIMARY_SUFFIX = "9999"; 12 | 13 | String MOCK_ORDER_ID = "MockOrderId"; 14 | 15 | String OPTION_CHAIN_PREFIX = "OCC#"; // 期权链前缀 16 | 17 | String KEY_USER = "USER"; 18 | 19 | String APP_NAME ="NS:"; 20 | 21 | // 监控台默认登录信息 22 | String DEFAULT_USERID = "admin"; 23 | String DEFAULT_PASSWORD = "123456"; 24 | 25 | // 环境变量名 26 | String NS_DS_SECRET = "NS_DS_SECRET"; 27 | String NS_USER = "NS_USER"; 28 | String NS_PWD = "NS_PWD"; 29 | 30 | // 资金占用比例估算系数 31 | double ESTIMATED_FROZEN_FACTOR = 1.5; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/FieldType.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum FieldType { 4 | 5 | TEXT, 6 | 7 | PASSWORD, 8 | 9 | NUMBER, 10 | 11 | DATE, 12 | 13 | SELECT, 14 | 15 | MULTI_SELECT; 16 | } 17 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/GatewayUsage.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum GatewayUsage { 4 | MARKET_DATA, TRADE; 5 | } 6 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/GlobalSpringContext.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | import java.util.concurrent.atomic.AtomicReference; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | 7 | public class GlobalSpringContext { 8 | 9 | public static final AtomicReference INSTANCE = new AtomicReference<>(); 10 | } 11 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/ModuleState.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | /** 4 | * 策略模组状态 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public enum ModuleState { 9 | 10 | /** 11 | * 空仓 12 | */ 13 | EMPTY, 14 | /** 15 | * 持多仓 16 | */ 17 | HOLDING_LONG, 18 | /** 19 | * 持空仓 20 | */ 21 | HOLDING_SHORT, 22 | /** 23 | * 持仓对冲锁仓(合约相同,持仓数量相等,方向相反) 24 | */ 25 | EMPTY_HEDGE, 26 | /** 27 | * 套利持仓(合约不同,持仓数量相等,方向相反) 28 | */ 29 | HOLDING_HEDGE, 30 | /** 31 | * 下单中 32 | */ 33 | PLACING_ORDER, 34 | /** 35 | * 等待订单反馈 36 | */ 37 | PENDING_ORDER, 38 | /** 39 | * 撤单 40 | */ 41 | RETRIEVING_FOR_CANCEL; 42 | 43 | 44 | public boolean isHolding() { 45 | return this == HOLDING_LONG || this == HOLDING_SHORT || this == HOLDING_HEDGE; 46 | } 47 | 48 | public boolean isWaiting() { 49 | return this == PENDING_ORDER || this == RETRIEVING_FOR_CANCEL; 50 | } 51 | 52 | public boolean isOrdering() { 53 | return this == PLACING_ORDER || isWaiting(); 54 | } 55 | 56 | public boolean isEmpty() { 57 | return this == EMPTY || this == EMPTY_HEDGE; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/ModuleType.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum ModuleType { 4 | /** 5 | * 投机 6 | */ 7 | SPECULATION("投机"), 8 | /** 9 | * 套利类 10 | */ 11 | ARBITRAGE("套利"); 12 | 13 | 14 | private String name; 15 | private ModuleType(String name) { 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return name; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/ModuleUsage.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum ModuleUsage { 4 | /** 5 | * 回测 6 | */ 7 | PLAYBACK, 8 | /** 9 | * 模拟盘 10 | */ 11 | UAT, 12 | /** 13 | * 实盘 14 | */ 15 | PROD; 16 | } 17 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/Platform.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum Platform { 4 | 5 | WINDOWS, 6 | 7 | LINUX, 8 | 9 | MAC_OS, 10 | 11 | UNKNOWN; 12 | 13 | public static Platform current() { 14 | String sysName = System.getProperties().getProperty("os.name").toUpperCase(); 15 | if(sysName.contains("WINDOWS")) { 16 | return WINDOWS; 17 | } 18 | if(sysName.contains("LINUX")) { 19 | return LINUX; 20 | } 21 | if(sysName.contains("MAC")) { 22 | return MAC_OS; 23 | } 24 | return UNKNOWN; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/PlaybackPrecision.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | /** 4 | * 回放精度 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public enum PlaybackPrecision { 9 | /** 10 | * 每分钟1TICK 11 | */ 12 | LITE, 13 | /** 14 | * 每分钟4TICK 15 | */ 16 | LOW, 17 | /** 18 | * 每分钟30TICK 19 | */ 20 | MEDIUM, 21 | /** 22 | * 每分钟120TICK 23 | */ 24 | HIGH; 25 | } 26 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/PlaybackSpeed.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | /** 4 | * 回放速度 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public enum PlaybackSpeed { 9 | /** 10 | * 正常速度 11 | */ 12 | NORMAL, 13 | /** 14 | * 快速 15 | */ 16 | SPRINT, 17 | /** 18 | * 极速 19 | */ 20 | RUSH; 21 | } 22 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/ReturnCode.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | /** 4 | * RESTful接口返回码 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public interface ReturnCode { 9 | 10 | /** 11 | * 成功 12 | */ 13 | int SUCCESS = 200; 14 | /** 15 | * 未知异常 16 | */ 17 | int ERROR = 500; 18 | /** 19 | * 认证异常 20 | */ 21 | int AUTH_ERR = 555; 22 | /** 23 | * 交易异常 24 | */ 25 | int TRADE_EXCEPTION = 540; 26 | /** 27 | * 数量不足异常 28 | */ 29 | int INSUFFICIENT_EXCEPTION = 541; 30 | /** 31 | * 元素不存在异常 32 | */ 33 | int NO_SUCH_ELEMENT_EXCEPTION = 542; 34 | /** 35 | * 数量不匹配异常 36 | */ 37 | int VALUE_MISMATCH_EXCEPTION = 543; 38 | } 39 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/constant/TickType.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.constant; 2 | 3 | public enum TickType { 4 | /** 5 | * 回测行情 6 | */ 7 | PLAYBACK_TICK, 8 | /** 9 | * 非交易时间的信息行情 10 | */ 11 | INFO_TICK, 12 | /** 13 | * 实时行情 14 | */ 15 | MARKET_TICK; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/event/AbstractEventHandler.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.event; 2 | 3 | public abstract class AbstractEventHandler implements GenericEventHandler{ 4 | 5 | 6 | @Override 7 | public void onEvent(NorthstarEvent e) { 8 | if(canHandle(e.getEvent())) { 9 | doHandle(e); 10 | } 11 | } 12 | 13 | protected abstract void doHandle(NorthstarEvent e); 14 | } 15 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/event/FastEventEngine.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.event; 2 | 3 | import com.lmax.disruptor.EventFactory; 4 | import com.lmax.disruptor.EventHandler; 5 | 6 | /** 7 | * 事件引擎 8 | * 负责第三方网关的事件 9 | */ 10 | public interface FastEventEngine { 11 | 12 | void addHandler(NorthstarEventDispatcher handler); 13 | 14 | void removeHandler(NorthstarEventDispatcher handler); 15 | 16 | void emitEvent(NorthstarEventType event, Object obj); 17 | 18 | public static interface NorthstarEventDispatcher extends EventHandler{ 19 | } 20 | 21 | public static class NorthstarEventFactory implements EventFactory { 22 | 23 | @Override 24 | public NorthstarEvent newInstance() { 25 | return new NorthstarEvent(null, null); 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/event/GenericEventHandler.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.event; 2 | 3 | public interface GenericEventHandler { 4 | 5 | void onEvent(NorthstarEvent e); 6 | 7 | boolean canHandle(NorthstarEventType eventType); 8 | } 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/event/NorthstarEvent.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.event; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @AllArgsConstructor 7 | @Data 8 | public class NorthstarEvent { 9 | 10 | private NorthstarEventType event; 11 | private Object data; 12 | } 13 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/event/NorthstarEventType.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.event; 2 | 3 | /** 4 | * 系统事件列表 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public enum NorthstarEventType { 9 | /** 10 | * 行情TICK事件 11 | */ 12 | TICK, 13 | /** 14 | * K线BAR事件 15 | */ 16 | BAR, 17 | /** 18 | * 账户回报事件 19 | */ 20 | ACCOUNT, 21 | /** 22 | * 持仓回报事件 23 | */ 24 | POSITION, 25 | /** 26 | * 成交回报事件 27 | */ 28 | TRADE, 29 | /** 30 | * 委托回报事件 31 | */ 32 | ORDER, 33 | /** 34 | * 消息事件 35 | */ 36 | NOTICE, 37 | /** 38 | * 合约事件 39 | */ 40 | CONTRACT, 41 | /** 42 | * 出入金事件 43 | */ 44 | BALANCE, 45 | /** 46 | * 登录中 47 | */ 48 | LOGGING_IN, 49 | /** 50 | * 登录成功 51 | */ 52 | LOGGED_IN, 53 | /** 54 | * 登出中 55 | */ 56 | LOGGING_OUT, 57 | /** 58 | * 登出成功 59 | */ 60 | LOGGED_OUT, 61 | /** 62 | * 网关就绪 63 | */ 64 | GATEWAY_READY, 65 | 66 | } 67 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/exception/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.exception; 2 | 3 | /** 4 | * 认证异常 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public class AuthenticationException extends RuntimeException { 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = -3503902860043562239L; 14 | 15 | private static final String MSG = "认证异常:"; 16 | 17 | public AuthenticationException(String message) { 18 | super(MSG + message); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/exception/InsufficientException.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.exception; 2 | 3 | /** 4 | * 数量不足异常 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public class InsufficientException extends TradeException{ 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 7387299700651706659L; 14 | 15 | public InsufficientException() { 16 | super(); 17 | } 18 | 19 | public InsufficientException(String message, Throwable cause, boolean enableSuppression, 20 | boolean writableStackTrace) { 21 | super(message, cause, enableSuppression, writableStackTrace); 22 | } 23 | 24 | public InsufficientException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public InsufficientException(String message) { 29 | super(message); 30 | } 31 | 32 | public InsufficientException(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/exception/NoSuchElementException.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.exception; 2 | 3 | /** 4 | * 找不到相应元素异常 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public class NoSuchElementException extends RuntimeException{ 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = -6631205607185324276L; 14 | 15 | public NoSuchElementException() { 16 | super(); 17 | } 18 | 19 | public NoSuchElementException(String message, Throwable cause, boolean enableSuppression, 20 | boolean writableStackTrace) { 21 | super(message, cause, enableSuppression, writableStackTrace); 22 | } 23 | 24 | public NoSuchElementException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public NoSuchElementException(String message) { 29 | super(message); 30 | } 31 | 32 | public NoSuchElementException(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/exception/TradeException.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.exception; 2 | 3 | /** 4 | * 交易异常 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public class TradeException extends RuntimeException{ 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 3362623046560159440L; 14 | 15 | public TradeException() { 16 | super(); 17 | } 18 | 19 | public TradeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 20 | super(message, cause, enableSuppression, writableStackTrace); 21 | } 22 | 23 | public TradeException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public TradeException(String message) { 28 | super(message); 29 | } 30 | 31 | public TradeException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/exception/ValueMismatchException.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.exception; 2 | 3 | /** 4 | * 数量不匹配异常 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public class ValueMismatchException extends TradeException{ 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = -6704498774997165335L; 14 | 15 | public ValueMismatchException() { 16 | super(); 17 | } 18 | 19 | public ValueMismatchException(String message, Throwable cause, boolean enableSuppression, 20 | boolean writableStackTrace) { 21 | super(message, cause, enableSuppression, writableStackTrace); 22 | } 23 | 24 | public ValueMismatchException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public ValueMismatchException(String message) { 29 | super(message); 30 | } 31 | 32 | public ValueMismatchException(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/AccountRuntimeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class AccountRuntimeDescription { 13 | 14 | /** 15 | * 账户名称 16 | */ 17 | private String name; 18 | /** 19 | * 账户余额 20 | */ 21 | private double balance; 22 | /** 23 | * 账户可用资金 24 | */ 25 | private double availableAmount; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ComponentAndParamsPair.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Data 14 | public class ComponentAndParamsPair { 15 | 16 | private ComponentMetaInfo componentMeta; 17 | private List initParams; 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ComponentField.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import org.dromara.northstar.common.constant.FieldType; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @Data 12 | public class ComponentField { 13 | 14 | private String label; 15 | 16 | private String name; 17 | 18 | private int order; 19 | 20 | private FieldType type; 21 | 22 | private Object value; 23 | 24 | private String unit; 25 | 26 | private String[] options; 27 | 28 | private String[] optionsVal; 29 | 30 | private String placeholder; 31 | 32 | private boolean required; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ComponentMetaInfo.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @AllArgsConstructor 8 | @NoArgsConstructor 9 | @Data 10 | public class ComponentMetaInfo { 11 | 12 | private String name; 13 | 14 | private String className; 15 | } 16 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ContractSimpleInfo.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.Objects; 4 | 5 | import org.dromara.northstar.common.constant.ChannelType; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Builder; 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @Getter 14 | @Setter 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | public class ContractSimpleInfo { 19 | 20 | /** 21 | * 合约名 22 | */ 23 | private String name; 24 | /** 25 | * 合约代码 26 | */ 27 | private String unifiedSymbol; 28 | /** 29 | * 渠道类型 30 | */ 31 | private ChannelType channelType; 32 | /** 33 | * 合约ID 34 | */ 35 | private String value; 36 | /** 37 | * 合约价格精度 38 | */ 39 | private int precision; 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) 44 | return true; 45 | if (obj == null) 46 | return false; 47 | if (getClass() != obj.getClass()) 48 | return false; 49 | ContractSimpleInfo other = (ContractSimpleInfo) obj; 50 | return Objects.equals(value, other.value); 51 | } 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash(value); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/GatewayDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | import org.dromara.northstar.common.constant.ChannelType; 7 | import org.dromara.northstar.common.constant.ConnectionState; 8 | import org.dromara.northstar.common.constant.GatewayUsage; 9 | 10 | import lombok.AllArgsConstructor; 11 | import lombok.Builder; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | /** 16 | * 网关连接信息 17 | * @author KevinHuangwl 18 | * 19 | */ 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | @Builder(toBuilder = true) 23 | @Data 24 | public class GatewayDescription { 25 | 26 | private String gatewayId; 27 | 28 | private String description; 29 | 30 | private ChannelType channelType; 31 | 32 | private GatewayUsage gatewayUsage; 33 | 34 | private boolean autoConnect; 35 | 36 | private Object settings; 37 | 38 | @Builder.Default 39 | private List subscribedContracts = Collections.emptyList(); 40 | 41 | private String bindedMktGatewayId; 42 | 43 | @Builder.Default 44 | private ConnectionState connectionState = ConnectionState.DISCONNECTED; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/GatewayTypeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import org.dromara.northstar.common.constant.ChannelType; 4 | import org.dromara.northstar.common.constant.GatewayUsage; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Builder 14 | @Data 15 | public class GatewayTypeDescription { 16 | 17 | private ChannelType type; 18 | 19 | public String getName() { 20 | return type.name(); 21 | } 22 | 23 | public GatewayUsage[] getUsage() { 24 | return type.usage(); 25 | } 26 | 27 | public boolean isAdminOnly() { 28 | return type.adminOnly(); 29 | } 30 | 31 | public boolean isAllowDuplication() { 32 | return type.allowDuplication(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/Identifier.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | public record Identifier(String value) { 6 | 7 | private static ConcurrentHashMap cache = new ConcurrentHashMap<>(); 8 | 9 | public static Identifier of(String value) { 10 | cache.computeIfAbsent(value, Identifier::new); 11 | return cache.get(value); 12 | } 13 | 14 | public static void resetCache() { 15 | cache.clear(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ListValue.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @Data 11 | @Builder 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class ListValue implements Value{ 15 | 16 | private String name; 17 | 18 | private List value; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/LogDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Builder 13 | @Data 14 | public class LogDescription { 15 | 16 | private long startPosition; 17 | 18 | private long endPosition; 19 | 20 | private List linesOfLog; 21 | } 22 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/MailConfigDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | import org.dromara.northstar.common.event.NorthstarEventType; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Builder; 10 | import lombok.Builder.Default; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | /** 15 | * EMAIL配置信息 16 | * @author KevinHuangwl 17 | * 18 | */ 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Builder 22 | @Data 23 | public class MailConfigDescription { 24 | /** 25 | * 禁用邮件通知 26 | */ 27 | @Default 28 | private boolean disabled = true; 29 | /** 30 | * SMTP服务器地址 31 | */ 32 | private String emailSMTPHost; 33 | /** 34 | * 邮箱名 35 | */ 36 | private String emailUsername; 37 | /** 38 | * 邮箱授权码 39 | */ 40 | private String emailPassword; 41 | /** 42 | * 订阅人邮箱列表 43 | */ 44 | @Default 45 | private List subscriberList = Collections.emptyList(); 46 | /** 47 | * 订阅事件列表 48 | */ 49 | @Default 50 | private List interestTopicList = Collections.emptyList(); 51 | } 52 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/MockTradeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import xyz.redtorch.pb.CoreEnum.DirectionEnum; 8 | import xyz.redtorch.pb.CoreEnum.OffsetFlagEnum; 9 | 10 | /** 11 | * 手工模拟成交 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | @Builder 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Data 19 | public class MockTradeDescription { 20 | 21 | private String contractId; 22 | 23 | private String gatewayId; 24 | 25 | private double price; 26 | 27 | private int volume; 28 | 29 | private DirectionEnum direction; 30 | 31 | private OffsetFlagEnum offsetFlag; 32 | 33 | private String tradeDate; 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ModuleAccountDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | * 模组账户配置信息 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class ModuleAccountDescription { 20 | 21 | /** 22 | * 账户网关ID 23 | */ 24 | private String accountGatewayId; 25 | /** 26 | * 账户关联合约名称 27 | */ 28 | private List bindedContracts; 29 | } 30 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ModuleAccountRuntimeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 模组账户信息 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | @Data 14 | @Builder 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class ModuleAccountRuntimeDescription { 18 | 19 | /** 20 | * 初始余额 21 | */ 22 | private double initBalance; 23 | /** 24 | * 累计平仓盈亏 25 | */ 26 | private double accCloseProfit; 27 | /** 28 | * 累计开平仓手数(开平仓一手算1) 29 | */ 30 | private int accDealVolume; 31 | /** 32 | * 累计手续费 33 | */ 34 | private double accCommission; 35 | /** 36 | * 模组持仓描述 37 | */ 38 | @Builder.Default 39 | private ModulePositionDescription positionDescription = new ModulePositionDescription(); 40 | /** 41 | * 最大盈利 42 | */ 43 | private double maxProfit; 44 | /** 45 | * 最大回撤 46 | */ 47 | private double maxDrawback; 48 | /** 49 | * 最大回撤比 50 | */ 51 | private double maxDrawbackPercentage; 52 | /** 53 | * 平均盈亏 54 | */ 55 | private double avgEarning; 56 | /** 57 | * 年化收益率 58 | */ 59 | private double annualizedRateOfReturn; 60 | /** 61 | * 可用余额 62 | */ 63 | private double availableAmount; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ModuleDealRecord.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 交易开平仓记录 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Data 17 | public class ModuleDealRecord { 18 | /** 19 | * 模组名称 20 | */ 21 | private String moduleName; 22 | /** 23 | * 模组账户 24 | */ 25 | private String moduleAccountId; 26 | /** 27 | * 合约中文名称 28 | */ 29 | private String contractName; 30 | /** 31 | * 平仓盈亏 32 | */ 33 | private double dealProfit; 34 | /** 35 | * 开仓成交 36 | */ 37 | private byte[] openTrade; 38 | /** 39 | * 平仓成交 40 | */ 41 | private byte[] closeTrade; 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ModulePositionDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | /** 12 | * 模组持仓信息 13 | * @author KevinHuangwl 14 | * 15 | */ 16 | @Data 17 | @Builder 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | public class ModulePositionDescription { 21 | 22 | /** 23 | * 逻辑持仓 24 | */ 25 | @Builder.Default 26 | private List logicalPositions = Collections.emptyList(); 27 | 28 | /** 29 | * 未平仓成交(以TradeField的字节数组表示一个未平仓成交) 30 | * 也可以理解为物理持仓 31 | */ 32 | @Builder.Default 33 | private List nonclosedTrades = Collections.emptyList(); 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ModuleRuntimeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.dromara.northstar.common.constant.ModuleState; 7 | 8 | import com.alibaba.fastjson.JSONObject; 9 | import com.alibaba.fastjson2.JSONArray; 10 | 11 | import lombok.AllArgsConstructor; 12 | import lombok.Builder; 13 | import lombok.Data; 14 | import lombok.NoArgsConstructor; 15 | 16 | /** 17 | * 模组信息 18 | * @author KevinHuangwl 19 | * 20 | */ 21 | @Data 22 | @Builder 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | public class ModuleRuntimeDescription { 26 | /** 27 | * 模组名称 28 | */ 29 | private String moduleName; 30 | /** 31 | * 模组启用状态 32 | */ 33 | private boolean enabled; 34 | /*** 35 | * 模组状态 36 | */ 37 | private ModuleState moduleState; 38 | /** 39 | * 模组账户描述 40 | */ 41 | private ModuleAccountRuntimeDescription moduleAccountRuntime; 42 | /** 43 | * 模组关联账户描述 44 | */ 45 | private List accountRuntimes; 46 | /** 47 | * 合约指标集 48 | */ 49 | private Map> indicatorMap; 50 | /** 51 | * 行情与指标数据 52 | */ 53 | private Map dataMap; 54 | /** 55 | * 模组计算状态(持久化数据) 56 | */ 57 | private JSONObject storeObject; 58 | /** 59 | * 策略信息描述 60 | */ 61 | private List strategyInfos; 62 | } 63 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/NsUser.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.io.Serializable; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /** 10 | * 用户信息 11 | * @author KevinHuangwl 12 | * 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class NsUser implements Serializable{ 18 | 19 | /** 20 | * 21 | */ 22 | private static final long serialVersionUID = 8553220725430453845L; 23 | 24 | private String userName; 25 | 26 | private String password; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/NumberValue.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class NumberValue implements Value{ 13 | 14 | private String name; 15 | 16 | private double value; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/OptionItem.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | /** 4 | * 选项 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public record OptionItem(String label, String value) { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/OrderRecall.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 撤单委托 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Data 17 | public class OrderRecall { 18 | 19 | private String originOrderId; 20 | 21 | private String gatewayId; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/OrderRequest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import org.dromara.northstar.strategy.constant.PriceType; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | * 下单委托 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | @Builder 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Data 19 | public class OrderRequest { 20 | 21 | /** 22 | * 合约名称 23 | */ 24 | private String contractId; 25 | /** 26 | * 委托价 27 | */ 28 | private String price; 29 | /** 30 | * 止损价 31 | */ 32 | private String stopPrice; 33 | /** 34 | * 委托数量 35 | */ 36 | private int volume; 37 | /** 38 | * 价格类型 39 | */ 40 | private PriceType priceType; 41 | /** 42 | * 买卖开平仓 43 | */ 44 | private TradeOperation tradeOpr; 45 | /** 46 | * 账户ID 47 | */ 48 | private String gatewayId; 49 | 50 | public static enum TradeOperation { 51 | BK, //买开 52 | BP, //买平 53 | SK, //卖开 54 | SP; //卖平 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/PlaybackRuntimeDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | * 回放状态 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class PlaybackRuntimeDescription { 20 | 21 | private String gatewayId; 22 | 23 | private LocalDateTime playbackTimeState; 24 | } 25 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/ResultBean.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import org.dromara.northstar.common.constant.ReturnCode; 4 | 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | 9 | @NoArgsConstructor //测试用 10 | @Data 11 | public class ResultBean { 12 | /** 13 | * 返回码 14 | */ 15 | private int status = ReturnCode.ERROR; 16 | /** 17 | * 异常信息 18 | */ 19 | private String message; 20 | /** 21 | * 返回值 22 | */ 23 | private T data; 24 | 25 | public ResultBean(T t) { 26 | this.status = ReturnCode.SUCCESS; 27 | this.data = t; 28 | } 29 | 30 | public ResultBean(int returnCode, String message) { 31 | this.status = returnCode; 32 | this.message = message; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/Setting.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import static java.lang.annotation.ElementType.FIELD; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | import org.dromara.northstar.common.SettingOptionsProvider; 10 | import org.dromara.northstar.common.constant.FieldType; 11 | 12 | /** 13 | * 配置项定义 14 | * @author KevinHuangwl 15 | * 16 | */ 17 | @Retention(RUNTIME) 18 | @Target(FIELD) 19 | public @interface Setting { 20 | 21 | /** 22 | * 前端显示的label 23 | * @return 24 | */ 25 | String label() default ""; 26 | /** 27 | * 数值单位 28 | * @return 29 | */ 30 | String unit() default ""; 31 | /** 32 | * 配置项顺序 33 | * @return 34 | */ 35 | int order() default 0; 36 | /** 37 | * 配置项可选项label 38 | * @return 39 | */ 40 | String[] options() default {}; 41 | /** 42 | * 配置项可选项value 43 | * @return 44 | */ 45 | String[] optionsVal() default {}; 46 | /** 47 | * 配置项实现类(此接口的实现类提供的值将覆盖options与optionsVal的值) 48 | * @return 49 | */ 50 | Class optionProvider() default SettingOptionsProvider.class; 51 | /** 52 | * 占位文字 53 | * @return 54 | */ 55 | String placeholder() default ""; 56 | /** 57 | * 配置项类型 58 | * @return 59 | */ 60 | FieldType type() default FieldType.TEXT; 61 | /** 62 | * 是否必填 63 | * @return 64 | */ 65 | boolean required() default true; 66 | } 67 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/SimAccountDescription.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | * 模拟账户信息描述 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Builder 18 | @Data 19 | public class SimAccountDescription { 20 | /** 21 | * 模拟账户ID 22 | */ 23 | private String gatewayId; 24 | /** 25 | * 累计平仓盈亏 26 | */ 27 | private double totalCloseProfit; 28 | /** 29 | * 累计手续费 30 | */ 31 | private double totalCommission; 32 | /** 33 | * 累计入金 34 | */ 35 | private double totalDeposit; 36 | /** 37 | * 累计出金 38 | */ 39 | private double totalWithdraw; 40 | /** 41 | * 未平仓(开仓)成交 42 | */ 43 | private List openTrades; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/StringValue.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class StringValue implements Value{ 13 | 14 | private String name; 15 | 16 | private String value; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/TimeSeriesValue.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | import lombok.EqualsAndHashCode; 4 | import lombok.Getter; 5 | 6 | @EqualsAndHashCode 7 | @Getter 8 | public class TimeSeriesValue implements Comparable { 9 | 10 | private double value; 11 | 12 | private long timestamp; 13 | 14 | private boolean unsettled; 15 | 16 | /** 17 | * @param value 时序值 18 | * @param timestamp 值对应的时间 19 | */ 20 | public TimeSeriesValue(double value, long timestamp) { 21 | this.value = value; 22 | this.timestamp = timestamp; 23 | } 24 | 25 | /** 26 | * @param value 时序值 27 | * @param timestamp 值对应的时间 28 | * @param unsettled 是否为未确定值(会发生变化) 29 | */ 30 | public TimeSeriesValue(double value, long timestamp, boolean unsettled) { 31 | this.value = value; 32 | this.timestamp = timestamp; 33 | this.unsettled = unsettled; 34 | } 35 | 36 | @Override 37 | public int compareTo(TimeSeriesValue o) { 38 | return timestamp < o.timestamp ? -1 : 1; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/Tuple.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | /** 4 | * 双元素元组 5 | * @author KevinHuangwl 6 | * 7 | * @param 8 | * @param 9 | */ 10 | public record Tuple(T1 t1, T2 t2) { 11 | 12 | public static Tuple of(T1 t1, T2 t2){ 13 | return new Tuple<>(t1, t2); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/Value.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model; 2 | 3 | 4 | public interface Value { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/core/Account.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import lombok.Builder; 4 | import xyz.redtorch.pb.CoreEnum.CurrencyEnum; 5 | import xyz.redtorch.pb.CoreField.AccountField; 6 | 7 | @Builder 8 | public record Account( 9 | String accountId, 10 | CurrencyEnum currency, // 币种 11 | double preBalance, // 昨日账户结算净值 12 | double balance, // 账户余额 13 | double available, // 可用资金 14 | double commission, // 今日手续费 15 | double margin, // 保证金占用 16 | double closeProfit, // 平仓盈亏 17 | double positionProfit, // 持仓盈亏 18 | double deposit, // 入金金额 19 | double withdraw, // 出金金额 20 | long updateTimestamp, 21 | String gatewayId 22 | ) { 23 | 24 | public AccountField toAccountField() { 25 | AccountField.Builder builder = AccountField.newBuilder(); 26 | if(accountId != null) { 27 | builder.setAccountId(accountId); 28 | } 29 | if(gatewayId != null) { 30 | builder.setGatewayId(gatewayId); 31 | } 32 | if (currency != null) { 33 | builder.setCurrency(currency); 34 | } 35 | return builder 36 | .setPreBalance(preBalance) 37 | .setBalance(balance) 38 | .setAvailable(available) 39 | .setCommission(commission) 40 | .setMargin(margin) 41 | .setCloseProfit(closeProfit) 42 | .setPositionProfit(positionProfit) 43 | .setDeposit(deposit) 44 | .setWithdraw(withdraw) 45 | .build(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/core/ContractDefinition.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | import org.dromara.northstar.common.IDataSource; 6 | 7 | import lombok.Builder; 8 | import xyz.redtorch.pb.CoreEnum.ExchangeEnum; 9 | import xyz.redtorch.pb.CoreEnum.ProductClassEnum; 10 | 11 | @Builder 12 | public record ContractDefinition( 13 | /** 14 | * 品种类别 15 | */ 16 | ProductClassEnum productClass, 17 | /** 18 | * 交易所 19 | */ 20 | ExchangeEnum exchange, 21 | /** 22 | * 合约代码特征 23 | */ 24 | Pattern symbolPattern, 25 | /** 26 | * 手续费(单位:元) 27 | */ 28 | double commissionFee, 29 | /** 30 | * 手续费率 31 | */ 32 | double commissionRate, 33 | /** 34 | * 交易时间 35 | */ 36 | TradeTimeDefinition tradeTimeDef, 37 | /** 38 | * 合约的历史数据源 39 | */ 40 | IDataSource dataSource, 41 | /** 42 | * 名称 43 | */ 44 | String name 45 | 46 | ) { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/core/Notice.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import lombok.Builder; 4 | import xyz.redtorch.pb.CoreEnum.CommonStatusEnum; 5 | import xyz.redtorch.pb.CoreField.NoticeField; 6 | 7 | @Builder 8 | public record Notice( 9 | CommonStatusEnum status, 10 | String content 11 | ) { 12 | 13 | public NoticeField toNoticeField() { 14 | return NoticeField.newBuilder() 15 | .setContent(content) 16 | .setStatus(status) 17 | .build(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/core/TimeSlot.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import java.time.LocalTime; 4 | import java.util.Objects; 5 | 6 | import lombok.Builder; 7 | 8 | /** 9 | * 时间槽 10 | */ 11 | @Builder 12 | public record TimeSlot( 13 | 14 | /** 15 | * 开始时间 16 | */ 17 | LocalTime start, 18 | /** 19 | * 结束时间 20 | */ 21 | LocalTime end) { 22 | 23 | @Override 24 | public int hashCode() { 25 | return Objects.hash(end, start); 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | if (this == obj) 31 | return true; 32 | if (obj == null) 33 | return false; 34 | if (getClass() != obj.getClass()) 35 | return false; 36 | TimeSlot other = (TimeSlot) obj; 37 | return Objects.equals(end, other.end) && Objects.equals(start, other.start); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/model/core/TradeTimeDefinition.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import java.util.List; 4 | import java.util.Objects; 5 | 6 | import lombok.Builder; 7 | 8 | @Builder 9 | public record TradeTimeDefinition( 10 | List timeSlots // 交易时段列表(必须按出现的先后顺序排列) 11 | ) { 12 | 13 | @Override 14 | public int hashCode() { 15 | return Objects.hash(timeSlots); 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj) { 20 | if (this == obj) 21 | return true; 22 | if (obj == null) 23 | return false; 24 | if (getClass() != obj.getClass()) 25 | return false; 26 | TradeTimeDefinition other = (TradeTimeDefinition) obj; 27 | return Objects.equals(timeSlots, other.timeSlots); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/utils/DateTimeUtils.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalTime; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.springframework.util.Assert; 9 | 10 | public class DateTimeUtils { 11 | 12 | private static final Map cacheTimeMap = new HashMap<>(); 13 | private static final LocalTime DAILY_CUTOFF = DateTimeUtils.fromCacheTime(19, 0); 14 | 15 | public LocalDate convertTradingDayForCNMarket(LocalDate actionDay, LocalTime actionTime) { 16 | if(actionTime.isBefore(DAILY_CUTOFF) && actionDay.getDayOfWeek().getValue() < 6) { 17 | return actionDay; 18 | } 19 | if(actionTime.isAfter(DAILY_CUTOFF) && actionDay.getDayOfWeek().getValue() < 5) { 20 | return actionDay.plusDays(1); 21 | } 22 | return actionDay.plusDays(8 - actionDay.getDayOfWeek().getValue()); 23 | } 24 | 25 | public static LocalTime fromCacheTime(LocalTime time) { 26 | Assert.isTrue(time.getSecond() == 0 && time.getNano() == 0, "只能缓存整分钟"); 27 | cacheTimeMap.putIfAbsent(time, time); 28 | return cacheTimeMap.get(time); 29 | } 30 | 31 | public static LocalTime fromCacheTime(int hour, int min) { 32 | return fromCacheTime(LocalTime.of(hour, min)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/utils/MessagePrinter.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import com.google.protobuf.MessageOrBuilder; 4 | import com.google.protobuf.TextFormat; 5 | 6 | public class MessagePrinter { 7 | 8 | private MessagePrinter() {} 9 | 10 | public static String print(MessageOrBuilder pbObject) { 11 | return TextFormat.printer().escapingNonAscii(false).printToString(pbObject); 12 | } 13 | 14 | public static String shortPrint(MessageOrBuilder pbObject) { 15 | return TextFormat.printer().escapingNonAscii(false).shortDebugString(pbObject); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/common/utils/TradeTimeUtil.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import java.time.LocalTime; 4 | import java.util.BitSet; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import org.dromara.northstar.common.model.core.TradeTimeDefinition; 9 | 10 | public class TradeTimeUtil { 11 | 12 | private static final int SEC_PER_MIN = 60; 13 | private static final int MINS_OF_DAY = 1440; 14 | 15 | private BitSet tradeTimeBitmap = new BitSet(MINS_OF_DAY); 16 | 17 | private Set endsOfSection = new HashSet<>(); 18 | 19 | public TradeTimeUtil(TradeTimeDefinition ttd) { 20 | ttd.timeSlots().forEach(ts -> { 21 | LocalTime start = ts.start(); 22 | LocalTime end = ts.end(); 23 | if(end.isBefore(start)) { 24 | tradeTimeBitmap.set(start.plusMinutes(1).toSecondOfDay() / SEC_PER_MIN, MINS_OF_DAY); 25 | tradeTimeBitmap.set(0, end.toSecondOfDay() / SEC_PER_MIN); 26 | } else { 27 | tradeTimeBitmap.set(start.plusMinutes(1).toSecondOfDay() / SEC_PER_MIN, end.toSecondOfDay() / SEC_PER_MIN); 28 | } 29 | endsOfSection.add(end); 30 | }); 31 | } 32 | 33 | public boolean withinTradeTime(LocalTime t) { 34 | LocalTime checkTime = t.withSecond(0).withNano(0).plusMinutes(1); 35 | return endsOfSection.contains(t) || tradeTimeBitmap.get(checkTime.toSecondOfDay() / SEC_PER_MIN); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/data/IGatewayRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.model.GatewayDescription; 6 | 7 | /** 8 | * 网关持久化 9 | * @author KevinHuangwl 10 | * 11 | */ 12 | public interface IGatewayRepository { 13 | 14 | /** 15 | * 新增网关 16 | * @param gatewayDescription 17 | */ 18 | void insert(GatewayDescription gatewayDescription); 19 | /** 20 | * 更新网关 21 | * @param gatewayDescription 22 | */ 23 | void save(GatewayDescription gatewayDescription); 24 | /** 25 | * 删除网关 26 | * @param gatewayId 27 | */ 28 | void deleteById(String gatewayId); 29 | /** 30 | * 查询网关 31 | * @return 32 | */ 33 | List findAll(); 34 | /** 35 | * 查询网关 36 | * @param gatewayId 37 | * @return 38 | */ 39 | GatewayDescription findById(String gatewayId); 40 | } 41 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/data/IMarketDataRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | import org.dromara.northstar.common.model.core.Bar; 7 | import org.dromara.northstar.gateway.IContract; 8 | 9 | /** 10 | * 行情数据持久化 11 | * @author KevinHuangwl 12 | * 13 | */ 14 | public interface IMarketDataRepository { 15 | 16 | /** 17 | * 保存数据 18 | * @param bar 19 | */ 20 | void insert(Bar bar); 21 | 22 | /** 23 | * 加载历史行情分钟K线数据 24 | * @param unifiedSymbol 25 | * @param startDate 26 | * @param endDate 27 | * @return 28 | */ 29 | List loadBars(IContract contract, LocalDate startDate, LocalDate endDate); 30 | 31 | 32 | /** 33 | * 加载历史行情日K线数据 34 | * @param unifiedSymbol 35 | * @param startDate 36 | * @param endDate 37 | * @return 38 | */ 39 | List loadDailyBars(IContract contract, LocalDate startDate, LocalDate endDate); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/data/IMessageSenderRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.MessageSenderSettings; 6 | import org.dromara.northstar.common.event.NorthstarEventType; 7 | 8 | /** 9 | * 消息发送器配置持久化 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | public interface IMessageSenderRepository { 14 | 15 | void save(MessageSenderSettings settings); 16 | 17 | MessageSenderSettings get(Class settingsClz); 18 | 19 | void save(List subEvents); 20 | 21 | List getSubEvents(); 22 | } 23 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/data/IPlaybackRuntimeRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data; 2 | 3 | import org.dromara.northstar.common.model.PlaybackRuntimeDescription; 4 | 5 | public interface IPlaybackRuntimeRepository { 6 | 7 | /** 8 | * 保存回放状态 9 | * @param playbackRtDescription 10 | */ 11 | void save(PlaybackRuntimeDescription playbackRtDescription); 12 | 13 | /** 14 | * 查询回放状态 15 | * @param playbackGatewayId 16 | * @return 17 | */ 18 | PlaybackRuntimeDescription findById(String playbackGatewayId); 19 | 20 | /** 21 | * 移除回放状态 22 | * @param playbackGatewayId 23 | */ 24 | void deleteById(String playbackGatewayId); 25 | } 26 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/data/ISimAccountRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data; 2 | 3 | import org.dromara.northstar.common.model.SimAccountDescription; 4 | 5 | public interface ISimAccountRepository { 6 | 7 | /** 8 | * 保存账户信息 9 | * @param simAccountDescription 10 | */ 11 | void save(SimAccountDescription simAccountDescription); 12 | /** 13 | * 查找账户信息 14 | * @param accountId 15 | * @return 16 | */ 17 | SimAccountDescription findById(String accountId); 18 | /** 19 | * 删除账户信息 20 | * @param accountId 21 | */ 22 | void deleteById(String accountId); 23 | } 24 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/Gateway.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import org.dromara.northstar.common.constant.ConnectionState; 4 | import org.dromara.northstar.common.model.GatewayDescription; 5 | 6 | public interface Gateway { 7 | 8 | /** 9 | * 获取网关配置 10 | * 11 | * @return 12 | */ 13 | GatewayDescription gatewayDescription(); 14 | /** 15 | * 网关ID 16 | * @return 17 | */ 18 | String gatewayId(); 19 | 20 | /** 21 | * 连接 22 | */ 23 | void connect(); 24 | 25 | /** 26 | * 断开 27 | */ 28 | void disconnect(); 29 | 30 | /** 31 | * 获取登录错误标记 32 | * 33 | * @return 34 | */ 35 | boolean getAuthErrorFlag(); 36 | 37 | /** 38 | * 获取连接状态 39 | * @return 40 | */ 41 | ConnectionState getConnectionState(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/GatewayFactory.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import org.dromara.northstar.common.model.GatewayDescription; 4 | 5 | public interface GatewayFactory { 6 | 7 | public abstract Gateway newInstance(GatewayDescription gatewayDescription); 8 | } 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/IContract.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.Subscribable; 6 | 7 | /** 8 | * 抽象合约 9 | * @author KevinHuangwl 10 | * 11 | */ 12 | public interface IContract extends Subscribable, Instrument { 13 | 14 | /** 15 | * 网关ID 16 | * @return 17 | */ 18 | String gatewayId(); 19 | 20 | /** 21 | * 获取成份合约 22 | * @return 23 | */ 24 | default List memberContracts() { 25 | throw new UnsupportedOperationException(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/IContractManager.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.dromara.northstar.common.constant.ChannelType; 7 | import org.dromara.northstar.common.model.Identifier; 8 | import org.dromara.northstar.common.model.core.ContractDefinition; 9 | 10 | import xyz.redtorch.pb.CoreEnum.ExchangeEnum; 11 | import xyz.redtorch.pb.CoreEnum.ProductClassEnum; 12 | 13 | public interface IContractManager { 14 | 15 | /** 16 | * 根据合约唯一标识获取合约 17 | * @param identifier 18 | * @return 19 | */ 20 | IContract getContract(Identifier identifier); 21 | 22 | /** 23 | * 根据网关与编码获取合约 24 | * @param channelType 25 | * @param symbol 可以是symbol或unifiedSymbol 26 | * @return 27 | */ 28 | IContract getContract(ChannelType channelType, String symbol); 29 | 30 | /** 31 | * 根据网关ID获取合约 32 | * @param gatewayId 33 | * @return 34 | */ 35 | List getContracts(String gatewayId); 36 | 37 | /** 38 | * 根据网关渠道获取合约 39 | * @param channelType 40 | * @return 41 | */ 42 | List getContracts(ChannelType channelType); 43 | 44 | /** 45 | * 获取合约定义 46 | * @param unifiedSymbol 47 | * @return 48 | */ 49 | Optional getDefinition(ExchangeEnum exchange, ProductClassEnum productClass, String unifiedSymbol); 50 | } 51 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/IMarketCenter.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.dromara.northstar.common.TickDataAware; 7 | import org.dromara.northstar.common.constant.ChannelType; 8 | import org.dromara.northstar.common.model.core.Contract; 9 | import org.dromara.northstar.common.model.core.ContractDefinition; 10 | import org.dromara.northstar.common.model.core.Tick; 11 | 12 | public interface IMarketCenter extends IContractManager, TickDataAware { 13 | 14 | /** 15 | * 增加合约定义 16 | */ 17 | void addDefinitions(List contractDefs); 18 | 19 | /** 20 | * 注册合约 21 | * @param ins 22 | */ 23 | void addInstrument(Instrument ins); 24 | 25 | /** 26 | * 注册网关 27 | * @param gateway 28 | */ 29 | void addGateway(MarketGateway gateway); 30 | 31 | /** 32 | * 获取网关 33 | * @param channelType 34 | */ 35 | MarketGateway getGateway(ChannelType channelType); 36 | 37 | /** 38 | * 加载合约组 39 | * @param gatewayId 40 | */ 41 | void loadContractGroup(ChannelType channelType); 42 | 43 | /** 44 | * 获取最近一个TICK数据 45 | * @param contract 46 | * @return 47 | */ 48 | Optional lastTick(Contract contract); 49 | } 50 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/Instrument.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import org.dromara.northstar.common.IDataSource; 4 | import org.dromara.northstar.common.constant.ChannelType; 5 | import org.dromara.northstar.common.model.Identifier; 6 | import org.dromara.northstar.common.model.core.Contract; 7 | import org.dromara.northstar.common.model.core.ContractDefinition; 8 | 9 | import xyz.redtorch.pb.CoreEnum.ExchangeEnum; 10 | import xyz.redtorch.pb.CoreEnum.ProductClassEnum; 11 | 12 | /** 13 | * (可交易的)投资品种 14 | * @author KevinHuangwl 15 | * 16 | */ 17 | public interface Instrument { 18 | 19 | /** 20 | * 名称 21 | * @return 22 | */ 23 | String name(); 24 | 25 | /** 26 | * 唯一标识 27 | * @return 28 | */ 29 | Identifier identifier(); 30 | 31 | /** 32 | * 种类 33 | * @return 34 | */ 35 | ProductClassEnum productClass(); 36 | 37 | /** 38 | * 交易所 39 | * @return 40 | */ 41 | ExchangeEnum exchange(); 42 | 43 | /** 44 | * 网关渠道类型 45 | * @return 46 | */ 47 | ChannelType channelType(); 48 | 49 | /** 50 | * 数据源 51 | * @return 52 | */ 53 | default IDataSource dataSource() { 54 | throw new UnsupportedOperationException(); 55 | } 56 | 57 | /** 58 | * 设置合约定义 59 | */ 60 | default void setContractDefinition(ContractDefinition contractDef) { 61 | throw new UnsupportedOperationException(); 62 | } 63 | 64 | /** 65 | * 转换为合约信息 66 | * @return 67 | */ 68 | default Contract contract() { 69 | throw new UnsupportedOperationException(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/MarketGateway.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import org.dromara.northstar.common.constant.ChannelType; 4 | import org.dromara.northstar.common.model.core.Contract; 5 | 6 | public interface MarketGateway extends Gateway { 7 | 8 | /** 9 | * 订阅 10 | * @param subscribeReq 11 | */ 12 | boolean subscribe(Contract contract); 13 | 14 | /** 15 | * 退订 16 | * @param subscribeReq 17 | */ 18 | boolean unsubscribe(Contract contract); 19 | 20 | /** 21 | * 检测是否有行情数据 22 | * @return 23 | */ 24 | boolean isActive(); 25 | 26 | /** 27 | * 网关类型 28 | * @return 29 | */ 30 | ChannelType channelType(); 31 | } 32 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/TradeGateway.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway; 2 | 3 | import org.dromara.northstar.common.model.core.SubmitOrderReq; 4 | 5 | public interface TradeGateway extends Gateway { 6 | 7 | /** 8 | * 提交定单 9 | * 10 | * @param orderReq 11 | * @return 12 | */ 13 | String submitOrder(SubmitOrderReq submitOrderReq); 14 | 15 | /** 16 | * 撤销定单 17 | * 18 | * @param cancelOrderReq 19 | * @return 20 | */ 21 | boolean cancelOrder(String originOrderId); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/gateway/mktdata/EmptyDataSource.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.mktdata; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import org.dromara.northstar.common.IDataSource; 8 | import org.dromara.northstar.common.constant.ChannelType; 9 | import org.dromara.northstar.common.model.core.Bar; 10 | import org.dromara.northstar.common.model.core.Contract; 11 | 12 | /** 13 | * 空数据源,用于占位 14 | */ 15 | 16 | public class EmptyDataSource implements IDataSource{ 17 | 18 | @Override 19 | public List getMinutelyData(Contract contract, LocalDate startDate, LocalDate endDate) { 20 | return Collections.emptyList(); 21 | } 22 | 23 | @Override 24 | public List getQuarterlyData(Contract contract, LocalDate startDate, LocalDate endDate) { 25 | return Collections.emptyList(); 26 | } 27 | 28 | @Override 29 | public List getHourlyData(Contract contract, LocalDate startDate, LocalDate endDate) { 30 | return Collections.emptyList(); 31 | } 32 | 33 | @Override 34 | public List getDailyData(Contract contract, LocalDate startDate, LocalDate endDate) { 35 | return Collections.emptyList(); 36 | } 37 | 38 | @Override 39 | public List getHolidays(ChannelType channelType, LocalDate startDate, LocalDate endDate) { 40 | return Collections.emptyList(); 41 | } 42 | 43 | @Override 44 | public List getAllContracts() { 45 | return Collections.emptyList(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/Indicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.model.Configuration; 6 | import org.dromara.northstar.indicator.model.Num; 7 | 8 | public interface Indicator { 9 | 10 | /** 11 | * 获取指标回溯值对象 12 | * @param step 回溯步长,取值范围为(-size, 0]。0代表当前值,-1代表回溯上一步,-2代表回溯上两步,如此类推 13 | * @return 14 | */ 15 | public Num get(int step); 16 | /** 17 | * 获取指标回溯值 18 | * @param step 回溯步长,取值范围为(-size, 0]。0代表当前值,-1代表回溯上一步,-2代表回溯上两步,如此类推 19 | * @return 20 | */ 21 | public double value(int step); 22 | /** 23 | * 指标是否已完成初始化 24 | * @return 25 | */ 26 | public boolean isReady(); 27 | /** 28 | * 获取系列值 29 | * @return 返回一个按时间升序的列表数据 30 | */ 31 | public List getData(); 32 | /** 33 | * 值更新 34 | * 此接口为幂等设计:同一个Num对象,更新多次与更新一次的效果相等。这个设计主要是使用户编写策略时可以避免考虑同一个指标可能存在的多次更新问题。 35 | * 具体的例子可以参考布林带指标 36 | * @param num 37 | */ 38 | public void update(Num num); 39 | /** 40 | * 获取该指标的依赖指标 41 | * 此接口主要用于暴露指标的依赖关系,从而可以让模组上下文通过该接口递归获取指标的依赖树关系,为指标更新与图表可视化提供入口 42 | * @return 43 | */ 44 | public List dependencies(); 45 | /** 46 | * 获取指标配置信息 47 | * @return 48 | */ 49 | public Configuration getConfiguration(); 50 | } 51 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/constant/PeriodUnit.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.constant; 2 | 3 | /** 4 | * 周期单位 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public enum PeriodUnit{ 9 | /** 10 | * 分钟 11 | */ 12 | MINUTE("m"), 13 | /** 14 | * 小时 15 | */ 16 | HOUR("hr"), 17 | /** 18 | * 天 19 | */ 20 | DAY("d"); 21 | 22 | String symbol; 23 | private PeriodUnit(String unitSymbol) { 24 | symbol = unitSymbol; 25 | } 26 | 27 | public String symbol() { 28 | return symbol; 29 | } 30 | } -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/DiffIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.AbstractIndicator; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | 10 | /** 11 | * 求两指标值之差 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public class DiffIndicator extends AbstractIndicator implements Indicator { 16 | 17 | private Indicator line1; 18 | private Indicator line2; 19 | private double multiplier1; 20 | private double multiplier2; 21 | 22 | public DiffIndicator(Configuration cfg, Indicator line1, Indicator line2) { 23 | this(cfg, line1, 1, line2, 1); 24 | } 25 | 26 | public DiffIndicator(Configuration cfg, Indicator line1, double multiplier1, Indicator line2, double multiplier2) { 27 | super(cfg); 28 | this.line1 = line1; 29 | this.line2 = line2; 30 | this.multiplier1 = multiplier1; 31 | this.multiplier2 = multiplier2; 32 | } 33 | 34 | protected Num evaluate(Num num) { 35 | return Num.of(line1.value(0) * multiplier1 - line2.value(0) * multiplier2, num.timestamp(), num.unstable()); 36 | } 37 | 38 | @Override 39 | public List dependencies() { 40 | return List.of(line1, line2); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/HHVIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.AbstractIndicator; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | 10 | /** 11 | * 最大值指标 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public class HHVIndicator extends AbstractIndicator implements Indicator{ 16 | 17 | private Indicator srcIndicator; 18 | 19 | public HHVIndicator(Configuration cfg, Indicator indicator) { 20 | super(cfg); 21 | this.srcIndicator = indicator; 22 | } 23 | 24 | @Override 25 | public List dependencies() { 26 | return List.of(srcIndicator); 27 | } 28 | 29 | @Override 30 | protected Num evaluate(Num num) { 31 | if(!srcIndicator.isReady()) { 32 | return Num.NaN(); 33 | } 34 | double val = srcIndicator.getData().stream().filter(nm -> !nm.isNaN()).mapToDouble(Num::value).max().getAsDouble(); 35 | return Num.of(val, num.timestamp(), num.unstable()); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/LLVIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.AbstractIndicator; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | 10 | /** 11 | * 最小值指标 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public class LLVIndicator extends AbstractIndicator implements Indicator{ 16 | 17 | private Indicator srcIndicator; 18 | 19 | public LLVIndicator(Configuration cfg, Indicator indicator) { 20 | super(cfg); 21 | this.srcIndicator = indicator; 22 | } 23 | 24 | @Override 25 | public List dependencies() { 26 | return List.of(srcIndicator); 27 | } 28 | 29 | @Override 30 | protected Num evaluate(Num num) { 31 | if(!srcIndicator.isReady()) { 32 | return Num.NaN(); 33 | } 34 | double val = srcIndicator.getData().stream().filter(nm -> !nm.isNaN()).mapToDouble(Num::value).min().getAsDouble(); 35 | return Num.of(val, num.timestamp(), num.unstable()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/NormalizeIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; 6 | import org.dromara.northstar.indicator.AbstractIndicator; 7 | import org.dromara.northstar.indicator.Indicator; 8 | import org.dromara.northstar.indicator.model.Configuration; 9 | import org.dromara.northstar.indicator.model.Num; 10 | 11 | /** 12 | * 对源指标的计算值进行归一化处理 13 | * @author KevinHuangwl 14 | * 15 | */ 16 | public class NormalizeIndicator extends AbstractIndicator implements Indicator{ 17 | 18 | private Indicator srcIndicator; 19 | 20 | public NormalizeIndicator(Configuration cfg, Indicator srcIndicator) { 21 | super(cfg); 22 | this.srcIndicator = srcIndicator; 23 | } 24 | 25 | @Override 26 | public List dependencies() { 27 | return List.of(srcIndicator); 28 | } 29 | 30 | @Override 31 | protected Num evaluate(Num num) { 32 | if(!srcIndicator.isReady() || num.unstable()) { 33 | return Num.NaN(); 34 | } 35 | StandardDeviation std = new StandardDeviation(); 36 | double[] data = srcIndicator.getData().stream().mapToDouble(Num::value).toArray(); 37 | double stdVal = std.evaluate(data, 0); 38 | return Num.of(srcIndicator.value(0) / stdVal, num.timestamp()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/SimpleValueIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import org.dromara.northstar.indicator.AbstractIndicator; 4 | import org.dromara.northstar.indicator.Indicator; 5 | import org.dromara.northstar.indicator.model.Configuration; 6 | import org.dromara.northstar.indicator.model.Num; 7 | 8 | /** 9 | * 简单值指标 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | public class SimpleValueIndicator extends AbstractIndicator implements Indicator { 14 | 15 | public SimpleValueIndicator(Configuration cfg) { 16 | super(cfg); 17 | } 18 | 19 | @Override 20 | protected Num evaluate(Num num) { 21 | return num; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/SumIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.AbstractIndicator; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | 10 | /** 11 | * 求两指标值之和 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public class SumIndicator extends AbstractIndicator implements Indicator { 16 | 17 | private Indicator line1; 18 | private double multiplier1; 19 | private Indicator line2; 20 | private double multiplier2; 21 | 22 | public SumIndicator(Configuration cfg, Indicator line1, Indicator line2) { 23 | this(cfg, line1, 1, line2, 1); 24 | } 25 | 26 | public SumIndicator(Configuration cfg, Indicator line1, double multiplier1, Indicator line2, double multiplier2) { 27 | super(cfg); 28 | this.line1 = line1; 29 | this.line2 = line2; 30 | this.multiplier1 = multiplier1; 31 | this.multiplier2 = multiplier2; 32 | } 33 | 34 | protected Num evaluate(Num num) { 35 | return Num.of(line1.value(0) * multiplier1 + line2.value(0) * multiplier2, num.timestamp(), num.unstable()); 36 | } 37 | 38 | @Override 39 | public List dependencies() { 40 | return List.of(line1, line2); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/helper/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.helper; -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/model/Num.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.model; 2 | 3 | /** 4 | * 值对象 5 | * @param 数据值 6 | * @param 值对应的时间戳 7 | * @param 不稳定标识 8 | * @author KevinHuangwl 9 | * 10 | */ 11 | public record Num(double value, long timestamp, boolean unstable) { 12 | 13 | public static Num of(double value, long timestamp) { 14 | return new Num(value, timestamp, false); 15 | } 16 | 17 | public static Num of(double value, long timestamp, boolean unstable) { 18 | return new Num(value, timestamp, unstable); 19 | } 20 | 21 | public static Num NaN() { 22 | return Num.of(Double.NaN, 0, true); 23 | } 24 | 25 | public boolean isNaN() { 26 | return Double.isNaN(value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/momentum/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.momentum; 2 | /** 3 | * 4 | * 动量类指标集 5 | * 动量指标用于衡量价格变化的速度,帮助投资者确定市场的力量和潜在反转点。常见的动量指标有相对强弱指数(Relative Strength Index, RSI)、随机指标(Stochastic Oscillator)等。 6 | * 7 | * 8 | * */ 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/trend/PuBuIndicator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.trend; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.indicator.AbstractIndicator; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | 10 | /** 11 | * 瀑布线指标 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public class PuBuIndicator extends AbstractIndicator implements Indicator{ 16 | 17 | private Indicator ema; 18 | private Indicator ma1; 19 | private Indicator ma2; 20 | 21 | public PuBuIndicator(Configuration cfg, int barCount) { 22 | super(cfg); 23 | ema = new EMAIndicator(cfg.toBuilder().indicatorName(cfg.indicatorName() + "_ema").visible(false).build(), barCount); 24 | ma1 = new MAIndicator(cfg.toBuilder().indicatorName(cfg.indicatorName() + "_ma1").visible(false).build(), barCount * 2); 25 | ma2 = new MAIndicator(cfg.toBuilder().indicatorName(cfg.indicatorName() + "_ma2").visible(false).build(), barCount * 4); 26 | } 27 | 28 | @Override 29 | public List dependencies() { 30 | return List.of(ema, ma1, ma2); 31 | } 32 | 33 | @Override 34 | protected Num evaluate(Num num) { 35 | if(!ema.isReady() || !ma1.isReady() || !ma2.isReady()) { 36 | return Num.NaN(); 37 | } 38 | return Num.of((ema.value(0) + ma1.value(0) + ma2.value(0)) / 3, num.timestamp(), num.unstable()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/trend/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.trend; 2 | /** 3 | * 4 | * 趋势类指标集 5 | * 趋势指标用于确定市场的方向,帮助投资者识别并跟随市场趋势。常见的趋势指标包括移动平均线(Moving Averages, MA)、趋势线(Trend Lines)、平滑异同平均线(Moving Average Convergence Divergence, MACD)等。 6 | * 7 | * 8 | * */ 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/volatility/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.volatility; 2 | /** 3 | * 4 | * 波动率类指标集 5 | * 波动率指标用于衡量市场价格变动的幅度,以判断市场的不稳定性。常见的波动率指标有平均真实范围(Average True Range, ATR)、布林带(Bollinger Bands)等 6 | * 7 | * 8 | * */ 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/volume/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.volume; 2 | /** 3 | * 4 | * 成交量类指标集 5 | * 成交量指标用于衡量市场中交易量的大小,帮助投资者分析市场的活跃程度和买卖力道。常见的成交量指标有成交量(Volume)、成交量加权平均价格(Volume Weighted Average Price, VWAP)、累积/派发线(Accumulation/Distribution Line, A/D Line)等。 6 | * 7 | * 8 | * */ 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/indicator/wave/package-info.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.wave; 2 | /** 3 | * 4 | * 波段类指标 5 | * 6 | * */ 7 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/ContextAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | 4 | public interface ContextAware { 5 | 6 | void setContext(IModuleContext context); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/DynamicParamsAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.model.DynamicParams; 4 | 5 | public interface DynamicParamsAware { 6 | 7 | /** 8 | * 获取配置类 9 | * @return 10 | */ 11 | DynamicParams getDynamicParams(); 12 | 13 | /** 14 | * 通过配置类初始化 15 | * @param params 16 | */ 17 | void initWithParams(DynamicParams params); 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/IDisposablePriceListener.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | public interface IDisposablePriceListener { 4 | 5 | void invalidate(); 6 | 7 | void setCallback(Runnable callback); 8 | } 9 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/IEmbededRule.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.BarDataAware; 4 | import org.dromara.northstar.common.TickDataAware; 5 | import org.dromara.northstar.common.model.core.Bar; 6 | import org.dromara.northstar.common.model.core.Tick; 7 | 8 | /** 9 | * 嵌入式策略接口 10 | * 用于模组策略内部定义子策略 11 | * @author KevinHuangwl 12 | * 13 | */ 14 | public interface IEmbededRule extends BarDataAware, TickDataAware { 15 | 16 | /** 17 | * 响应TICK数据 18 | */ 19 | @Override 20 | default void onTick(Tick tick) {} 21 | 22 | /** 23 | * 响应BAR数据 24 | */ 25 | @Override 26 | default void onBar(Bar bar) {} 27 | 28 | } 29 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/IMessageSender.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.event.NorthstarEvent; 4 | 5 | public interface IMessageSender { 6 | 7 | /** 8 | * 发送信息 9 | * 该方法可以是阻塞方法 10 | * @param title 标题 11 | * @param message 内容 12 | */ 13 | void send(String title, String content); 14 | /** 15 | * 发送信息 16 | * 该方法可以是阻塞方法 17 | * @param content 内容 18 | */ 19 | void send(String content); 20 | /** 21 | * 处理系统事件 22 | * @param e 23 | */ 24 | void onEvent(NorthstarEvent e); 25 | } 26 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/IModule.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.event.NorthstarEvent; 4 | import org.dromara.northstar.common.model.ModuleDescription; 5 | import org.dromara.northstar.common.model.ModuleRuntimeDescription; 6 | import org.dromara.northstar.common.model.core.Contract; 7 | 8 | /** 9 | * 模组抽象接口 10 | * @author KevinHuangwl 11 | * 12 | */ 13 | public interface IModule { 14 | 15 | /** 16 | * 模组名称 17 | * @return 18 | */ 19 | String getName(); 20 | /** 21 | * 设置运行状态 22 | * @param enabled 23 | */ 24 | void setEnabled(boolean enabled); 25 | /** 26 | * 获取运行状态 27 | * @return 28 | */ 29 | boolean isEnabled(); 30 | /** 31 | * 监听事件 32 | * @param event 33 | */ 34 | void onEvent(NorthstarEvent event); 35 | /** 36 | * 获取合约关联的交易账户 37 | * @param contract 38 | * @return 39 | */ 40 | IAccount getAccount(Contract contract); 41 | /** 42 | * 获取模组状态描述 43 | * @return 44 | */ 45 | ModuleRuntimeDescription getRuntimeDescription(); 46 | /** 47 | * 获取模组描述 48 | * @return 49 | */ 50 | ModuleDescription getModuleDescription(); 51 | /** 52 | * 获取模组上下文 53 | * @return 54 | */ 55 | IModuleContext getModuleContext(); 56 | /** 57 | * 获取交易策略 58 | * @return 59 | */ 60 | TradeStrategy getTradeStrategy(); 61 | } 62 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/IModuleAccount.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.TickDataAware; 4 | import org.dromara.northstar.common.TransactionAware; 5 | import org.dromara.northstar.common.model.core.Contract; 6 | 7 | import xyz.redtorch.pb.CoreEnum.DirectionEnum; 8 | 9 | /** 10 | * 模组账户代表一个模组内部的逻辑账户 11 | * 若模组绑定了多个实体账户,也被看作是一个逻辑账户 12 | * @author KevinHuangwl 13 | * 14 | */ 15 | public interface IModuleAccount extends TickDataAware, TransactionAware { 16 | 17 | /** 18 | * 总持仓盈亏 19 | * @return 20 | */ 21 | double totalHoldingProfit(); 22 | /** 23 | * 可用金额 24 | * @return 25 | */ 26 | double availableAmount(); 27 | /** 28 | * 获取指定合约指定方向的持仓数 29 | * @param unifiedSymbol 30 | * @param direction 31 | * @return 32 | */ 33 | int getNonclosedPosition(Contract contract, DirectionEnum direction); 34 | /** 35 | * 获取指定合约指定方向的持仓数 36 | * @param unifiedSymbol 37 | * @param direction 38 | * @param isPresentTradingDay 是否为今日仓 39 | * @return 40 | */ 41 | int getNonclosedPosition(Contract contract, DirectionEnum direction, boolean isPresentTradingDay); 42 | /** 43 | * 获取指定合约的净持仓数量 44 | * @param unifiedSymbol 45 | * @return 正数代表净多头持仓,负数代表净空头持仓 46 | */ 47 | int getNonclosedNetPosition(Contract contract); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/MergedBarListener.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.model.core.Bar; 4 | 5 | /** 6 | * 复合行情BAR监听 7 | * @author KevinHuangwl 8 | * 9 | */ 10 | public interface MergedBarListener { 11 | 12 | void onMergedBar(Bar bar); 13 | } 14 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/OrderRequestFilter.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import org.dromara.northstar.common.TickDataAware; 4 | import org.dromara.northstar.common.model.core.SubmitOrderReq; 5 | 6 | /** 7 | * 委托请求过滤器 8 | * 用于过滤风险,例如因程序漏洞导致连续发单,该过滤器可以作为发送订单前的最后一道安全屏障 9 | * @author KevinHuangwl 10 | * 11 | */ 12 | public interface OrderRequestFilter extends TickDataAware { 13 | /** 14 | * 风控过滤 15 | * @param orderReq 16 | */ 17 | void doFilter(SubmitOrderReq orderReq); 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/StrategicComponent.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import static java.lang.annotation.ElementType.TYPE; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.stereotype.Component; 10 | 11 | @Retention(RUNTIME) 12 | @Target(TYPE) 13 | @Component 14 | public @interface StrategicComponent { 15 | 16 | //策略名称 17 | String value(); 18 | } 19 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/TradeStrategy.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.TickDataAware; 6 | import org.dromara.northstar.common.TransactionAware; 7 | import org.dromara.northstar.common.constant.ModuleType; 8 | import org.dromara.northstar.common.model.Value; 9 | import org.dromara.northstar.common.model.core.Bar; 10 | import org.dromara.northstar.common.model.core.Tick; 11 | 12 | import com.alibaba.fastjson.JSONObject; 13 | 14 | public interface TradeStrategy extends TickDataAware, MergedBarListener, TransactionAware, ContextAware, DynamicParamsAware{ 15 | 16 | /* 状态与设置信息 */ 17 | /** 18 | * 适用模组类型 19 | * @return 20 | */ 21 | default ModuleType type() { 22 | return ModuleType.SPECULATION; 23 | } 24 | 25 | /** 26 | * 获取计算状态 27 | * @return 28 | */ 29 | JSONObject getStoreObject(); 30 | /** 31 | * 设置计算状态 32 | * @param storeObj 33 | */ 34 | void setStoreObject(JSONObject storeObj); 35 | 36 | /* 响应事件 */ 37 | /** 38 | * TICK事件 39 | * 当模组状态为停用时,也不排除策略会有相应的数据更新逻辑,所以即使模组状态为停用,该方法仍会被调用 40 | * @param tick 41 | */ 42 | void onTick(Tick tick); 43 | /** 44 | * BAR事件 45 | * 当模组状态为停用时,也不排除策略会有相应的数据更新逻辑,所以即使模组状态为停用,该方法仍会被调用 46 | * @param bar 47 | */ 48 | void onMergedBar(Bar bar); 49 | /** 50 | * 获取策略信息 51 | * @return 52 | */ 53 | default List strategyInfos() { 54 | return List.of(); 55 | } 56 | /** 57 | * 策略名称 58 | * @return 59 | */ 60 | String name(); 61 | } 62 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/constant/DisposablePriceListenerType.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy.constant; 2 | 3 | public enum DisposablePriceListenerType { 4 | /** 5 | * 止盈 6 | */ 7 | TAKE_PROFIT, 8 | /** 9 | * 止损 10 | */ 11 | STOP_LOSS; 12 | } 13 | -------------------------------------------------------------------------------- /northstar-api/src/main/java/org/dromara/northstar/strategy/tester/ModuleTesterRunner.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.strategy.tester; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.stereotype.Component; 9 | 10 | import lombok.extern.slf4j.Slf4j; 11 | 12 | @Slf4j 13 | @Order(Ordered.LOWEST_PRECEDENCE) 14 | @ConditionalOnProperty(prefix = "spring.profiles", name = "active", havingValue = "test") 15 | @Component 16 | public class ModuleTesterRunner implements CommandLineRunner { 17 | 18 | @Autowired 19 | AbstractTester tester; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | new Thread(() -> { 24 | log.info("模组自动化测试准备开始"); 25 | try { 26 | Thread.sleep(5000); 27 | tester.start(); 28 | } catch (InterruptedException e) { 29 | log.warn("", e); 30 | } 31 | 32 | log.info("模组自动化测试结束"); 33 | }).start(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/model/core/AccountTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import static org.junit.jupiter.api.Assertions.*; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import xyz.redtorch.pb.CoreEnum; 7 | import xyz.redtorch.pb.CoreField; 8 | 9 | class AccountTest { 10 | 11 | @Test 12 | void testToAccountField() { 13 | Account account = Account.builder() 14 | .accountId("accountId") 15 | .available(1.0) 16 | .balance(2.0) 17 | .closeProfit(3.0) 18 | .commission(4.0) 19 | .currency(CoreEnum.CurrencyEnum.CNY) 20 | .deposit(5.0) 21 | .gatewayId("gatewayId") 22 | .margin(6.0) 23 | .positionProfit(7.0) 24 | .preBalance(8.0) 25 | .withdraw(9.0) 26 | .build(); 27 | CoreField.AccountField accountField = account.toAccountField(); 28 | assertEquals("accountId", accountField.getAccountId()); 29 | assertEquals(1.0, accountField.getAvailable()); 30 | assertEquals(2.0, accountField.getBalance()); 31 | assertEquals(3.0, accountField.getCloseProfit()); 32 | assertEquals(4.0, accountField.getCommission()); 33 | assertEquals(CoreEnum.CurrencyEnum.CNY, accountField.getCurrency()); 34 | assertEquals(5.0, accountField.getDeposit()); 35 | assertEquals("gatewayId", accountField.getGatewayId()); 36 | assertEquals(6.0, accountField.getMargin()); 37 | assertEquals(7.0, accountField.getPositionProfit()); 38 | assertEquals(8.0, accountField.getPreBalance()); 39 | assertEquals(9.0, accountField.getWithdraw()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/model/core/NoticeTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import static org.junit.jupiter.api.Assertions.*; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | import xyz.redtorch.pb.CoreEnum.CommonStatusEnum; 8 | 9 | class NoticeTest { 10 | 11 | @Test 12 | void testToNoticeField() { 13 | Notice notice = Notice.builder() 14 | .content("content") 15 | .status(CommonStatusEnum.COMS_INFO) 16 | .build(); 17 | xyz.redtorch.pb.CoreField.NoticeField noticeField = notice.toNoticeField(); 18 | assertEquals(notice.content(), noticeField.getContent()); 19 | assertEquals(notice.status(), noticeField.getStatus()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/model/core/SubmitOrderReqTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | import xyz.redtorch.pb.CoreEnum.ContingentConditionEnum; 8 | import xyz.redtorch.pb.CoreEnum.DirectionEnum; 9 | import xyz.redtorch.pb.CoreEnum.OffsetFlagEnum; 10 | import xyz.redtorch.pb.CoreEnum.OrderPriceTypeEnum; 11 | import xyz.redtorch.pb.CoreEnum.TimeConditionEnum; 12 | import xyz.redtorch.pb.CoreEnum.VolumeConditionEnum; 13 | 14 | class SubmitOrderReqTest { 15 | 16 | @Test 17 | void testToString() { 18 | SubmitOrderReq orderReq = SubmitOrderReq.builder() 19 | .gatewayId("testGatewayId") 20 | .contract(Contract.builder() 21 | .unifiedSymbol("testSymbol") 22 | .symbol("testSymbol") 23 | .build()) 24 | .originOrderId("testTradeId") 25 | .direction(DirectionEnum.D_Buy) 26 | .offsetFlag(OffsetFlagEnum.OF_Open) 27 | .price(1.0) 28 | .volume(2) 29 | .orderPriceType(OrderPriceTypeEnum.OPT_AnyPrice) 30 | .timeCondition(TimeConditionEnum.TC_GFD) 31 | .volumeCondition(VolumeConditionEnum.VC_AV) 32 | .minVolume(1) 33 | .contingentCondition(ContingentConditionEnum.CC_Immediately) 34 | .stopPrice(1.0) 35 | .build(); 36 | assertDoesNotThrow(() -> { 37 | System.out.println(orderReq); 38 | }); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/model/core/TradeTimeDefinitionTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.model.core; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.time.LocalTime; 6 | import java.util.List; 7 | 8 | import org.junit.jupiter.api.Test; 9 | 10 | class TradeTimeDefinitionTest { 11 | 12 | @Test 13 | void test() { 14 | TradeTimeDefinition tt1 = TradeTimeDefinition.builder() 15 | .timeSlots(List.of( 16 | TimeSlot.builder().start(LocalTime.of(9, 0)).end(LocalTime.of(18, 0)).build(), 17 | TimeSlot.builder().start(LocalTime.of(20, 0)).end(LocalTime.of(23, 30)).build() 18 | )) 19 | .build(); 20 | TradeTimeDefinition tt2 = TradeTimeDefinition.builder() 21 | .timeSlots(List.of( 22 | TimeSlot.builder().start(LocalTime.of(9, 0)).end(LocalTime.of(18, 0)).build(), 23 | TimeSlot.builder().start(LocalTime.of(20, 0)).end(LocalTime.of(23, 30)).build() 24 | )) 25 | .build(); 26 | assertThat(tt1).isEqualTo(tt2); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/utils/ContractSymbolPatternTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.regex.Pattern; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | public class ContractSymbolPatternTest { 10 | 11 | @Test 12 | void testOPTION() { 13 | Pattern ptn = Pattern.compile("[A-z]+[0-9]{3,4}[^@].+"); 14 | assertThat(ptn.matcher("m2207-C-2600@CTP").matches()).isTrue(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/utils/DateTimeUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.time.LocalTime; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | class DateTimeUtilsTest { 10 | 11 | @Test 12 | void testTimeCache() { 13 | LocalTime t1 = LocalTime.of(1, 13); 14 | LocalTime t2 = LocalTime.of(1, 13); 15 | assertThat(t1).isNotSameAs(t2); 16 | 17 | LocalTime t3 = DateTimeUtils.fromCacheTime(t1); 18 | LocalTime t4 = DateTimeUtils.fromCacheTime(t2); 19 | assertThat(t3).isSameAs(t4); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/common/utils/LocalEnvUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.common.utils; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | class LocalEnvUtilsTest { 6 | 7 | @Test 8 | void testMAC() throws Exception { 9 | System.out.println(LocalEnvUtils.getMACAddress()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/gateway/mktdata/EmptyDataSourceTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.mktdata; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.mockito.Mockito.mock; 5 | 6 | import java.time.LocalDate; 7 | 8 | import org.dromara.northstar.common.constant.ChannelType; 9 | import org.dromara.northstar.common.model.core.Contract; 10 | import org.junit.jupiter.api.Test; 11 | 12 | class EmptyDataSourceTest { 13 | 14 | @Test 15 | void test() { 16 | EmptyDataSource source = new EmptyDataSource(); 17 | assertThat(source.getAllContracts()).isEmpty(); 18 | assertThat(source.getMinutelyData(mock(Contract.class), LocalDate.now(), LocalDate.now())).isEmpty(); 19 | assertThat(source.getQuarterlyData(mock(Contract.class), LocalDate.now(), LocalDate.now())).isEmpty(); 20 | assertThat(source.getHourlyData(mock(Contract.class), LocalDate.now(), LocalDate.now())).isEmpty(); 21 | assertThat(source.getDailyData(mock(Contract.class), LocalDate.now(), LocalDate.now())).isEmpty(); 22 | assertThat(source.getHolidays(ChannelType.SIM, LocalDate.now(), LocalDate.now())).isEmpty(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/indicator/model/ConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.model; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.jupiter.api.Assertions.*; 5 | 6 | import org.dromara.northstar.common.model.core.Contract; 7 | import org.dromara.northstar.indicator.constant.PeriodUnit; 8 | import org.dromara.northstar.indicator.constant.ValueType; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class ConfigurationTest { 12 | 13 | Contract c = Contract.builder().unifiedSymbol("testSymbol").build(); 14 | 15 | @Test 16 | void testDefaultValue() { 17 | Configuration cfg = Configuration.builder().indicatorName("testIndicator").contract(c).build(); 18 | assertThat(cfg.numOfUnits()).isEqualTo(1); 19 | assertThat(cfg.period()).isEqualTo(PeriodUnit.MINUTE); 20 | assertThat(cfg.valueType()).isEqualTo(ValueType.CLOSE); 21 | assertThat(cfg.cacheLength()).isEqualTo(16); 22 | assertThat(cfg.ifPlotPerBar()).isFalse(); 23 | assertThat(cfg.visible()).isTrue(); 24 | } 25 | 26 | @Test 27 | void testException() { 28 | assertThrows(IllegalArgumentException.class, () -> { 29 | Configuration.builder().build(); 30 | }); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /northstar-api/src/test/java/org/dromara/northstar/indicator/volume/VWAPIndicatorTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.indicator.volume; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import org.dromara.northstar.common.model.core.Contract; 6 | import org.dromara.northstar.indicator.Indicator; 7 | import org.dromara.northstar.indicator.model.Configuration; 8 | import org.dromara.northstar.indicator.model.Num; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class VWAPIndicatorTest { 12 | 13 | Contract contract = Contract.builder().build(); 14 | 15 | @Test 16 | void test() { 17 | double[] prices = { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0 }; 18 | int[] volumes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 19 | Indicator vwap = new VWAPIndicator(Configuration.builder().contract(contract).build(), 10); 20 | for(int i=0; i 2 | 3 | 4.0.0 4 | 5 | org.dromara 6 | northstar 7 | ${revision} 8 | 9 | northstar-external-archetype 10 | maven-archetype 11 | northstar-external-archetype 12 | 13 | true 14 | 15 | 16 | 17 | 18 | org.apache.maven.archetype 19 | archetype-packaging 20 | 3.1.1 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /northstar-external-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | src/main/java 9 | 10 | 11 | src/test/java 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /northstar-external-archetype/src/main/resources/archetype-resources/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | ${groupId} 5 | ${artifactId} 6 | ${version} 7 | 8 | 17 9 | UTF-8 10 | UTF-8 11 | ${java.version} 12 | ${java.version} 13 | 14 | 15 | 16 | org.dromara 17 | northstar-api 18 | ${version} 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /northstar-external-archetype/src/main/resources/archetype-resources/src/main/java/ExternalConfig.java: -------------------------------------------------------------------------------- 1 | #set( $symbol_pound = '#' ) 2 | #set( $symbol_dollar = '$' ) 3 | #set( $symbol_escape = '\' ) 4 | package ${package}; 5 | 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | @Slf4j 11 | @Configuration 12 | public class ExternalConfig { 13 | 14 | static { 15 | log.info("====================================================="); 16 | log.info(" 加载northstar-external "); 17 | log.info("====================================================="); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /northstar-external-archetype/src/main/resources/archetype-resources/src/main/java/gateway/package-info.java: -------------------------------------------------------------------------------- 1 | #set( $symbol_pound = '#' ) 2 | #set( $symbol_dollar = '$' ) 3 | #set( $symbol_escape = '\' ) 4 | package ${package}.gateway; 5 | /** 6 | * 用户如果要实现自定义的网关,可以此目录提供实现 7 | * 8 | * */ -------------------------------------------------------------------------------- /northstar-external-archetype/src/main/resources/archetype-resources/src/main/java/indicator/package-info.java: -------------------------------------------------------------------------------- 1 | #set( $symbol_pound = '#' ) 2 | #set( $symbol_dollar = '$' ) 3 | #set( $symbol_escape = '\' ) 4 | package ${package}.indicator; 5 | /** 6 | * 建议把自定义的指标放在些目录下 7 | * 8 | * 9 | */ 10 | -------------------------------------------------------------------------------- /northstar-gateway-playback/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/IPlaybackContext.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback; 2 | 3 | public interface IPlaybackContext { 4 | 5 | void start(); 6 | 7 | void stop(); 8 | 9 | boolean isRunning(); 10 | 11 | void onStopCallback(Runnable callback); 12 | } 13 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/PlaybackConfig.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback; 2 | 3 | import org.dromara.northstar.common.event.FastEventEngine; 4 | import org.dromara.northstar.data.IPlaybackRuntimeRepository; 5 | import org.dromara.northstar.gateway.IContractManager; 6 | import org.dromara.northstar.gateway.mktdata.NorthstarDataSource; 7 | import org.dromara.northstar.gateway.mktdata.QuantitDataServiceManager; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.retry.annotation.EnableRetry; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | @EnableRetry 14 | @Configuration 15 | public class PlaybackConfig { 16 | 17 | @Bean 18 | QuantitDataServiceManager dataService(RestTemplate restTemplate) { 19 | return new QuantitDataServiceManager(restTemplate); 20 | } 21 | 22 | @Bean 23 | NorthstarDataSource playbackDataServiceManager(QuantitDataServiceManager dataService) { 24 | return new NorthstarDataSource(dataService); 25 | } 26 | 27 | @Bean 28 | PlaybackGatewayFactory playbackGatewayFactory(FastEventEngine feEngine, IContractManager contractMgr, IPlaybackRuntimeRepository pbrtRepo) { 29 | return new PlaybackGatewayFactory(feEngine, contractMgr, pbrtRepo); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/model/DataFrame.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.model; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.dromara.northstar.common.Timed; 7 | 8 | /** 9 | * 一份时间帧相同的数据 10 | * @auth KevinHuangwl 11 | */ 12 | public class DataFrame implements Timed{ 13 | 14 | private Set buf; 15 | 16 | private final long timestamp; 17 | 18 | private T sample; 19 | 20 | public DataFrame(long timestamp) { 21 | 22 | this.timestamp = timestamp; 23 | } 24 | 25 | public void add(T item) { 26 | if(item.getTimestamp() == timestamp) { 27 | if(isEmpty()) { 28 | buf = new HashSet<>(); 29 | } 30 | buf.add(item); 31 | sample = item; 32 | } 33 | } 34 | 35 | public boolean isEmpty() { 36 | return buf == null || buf.isEmpty(); 37 | } 38 | 39 | public Set items(){ 40 | return buf; 41 | } 42 | 43 | @Override 44 | public long getTimestamp() { 45 | return timestamp; 46 | } 47 | 48 | public T getSample() { 49 | return sample; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/ticker/SimpleCloseSimulation.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.ticker; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.model.core.Bar; 6 | 7 | /** 8 | * 收盘价生成策略 9 | * @author KevinHuangwl 10 | * 11 | */ 12 | public class SimpleCloseSimulation implements TickSimulationAlgorithm { 13 | 14 | @Override 15 | public List generateFrom(Bar bar) { 16 | double priceTick = bar.contract().priceTick(); 17 | double askPrice = bar.closePrice() > bar.openPrice() ? bar.closePrice() : bar.closePrice() + priceTick; 18 | double bidPrice = bar.closePrice() > bar.openPrice() ? bar.closePrice() - priceTick : bar.closePrice(); 19 | return List.of(TickEntry.of(bar.closePrice(), askPrice, bidPrice, bar.volumeDelta(), bar.openInterestDelta(), bar.actionTimestamp() - 30000)); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/ticker/SimplePriceSimulation.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.ticker; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ThreadLocalRandom; 5 | 6 | import org.dromara.northstar.common.model.core.Bar; 7 | 8 | public class SimplePriceSimulation implements TickSimulationAlgorithm { 9 | 10 | @Override 11 | public List generateFrom(Bar bar) { 12 | double priceTick = bar.contract().priceTick(); 13 | return List.of( 14 | randomAskBid(bar.openPrice(), priceTick, bar.volumeDelta() / 4, bar.openInterestDelta() / 4, bar.actionTimestamp() - 50000), 15 | randomAskBid(bar.highPrice(), priceTick, bar.volumeDelta() / 4, bar.openInterestDelta() / 4, bar.actionTimestamp() - 40000), 16 | randomAskBid(bar.lowPrice(), priceTick, bar.volumeDelta() / 4, bar.openInterestDelta() / 4, bar.actionTimestamp() - 30000), 17 | randomAskBid(bar.closePrice(), priceTick, bar.volumeDelta() / 4, bar.openInterestDelta() / 4, bar.actionTimestamp() - 20000) 18 | ); 19 | } 20 | 21 | private TickEntry randomAskBid(double price, double priceTick, long volumeDelta, double openInterestDelta, long tickTime) { 22 | double askPrice = price + ThreadLocalRandom.current().nextInt(2) * priceTick; 23 | double bidPrice = askPrice - priceTick; 24 | return TickEntry.of(price, askPrice, bidPrice, volumeDelta, openInterestDelta, tickTime); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/ticker/TickEntry.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.ticker; 2 | 3 | /** 4 | * TICK基数 5 | * @author KevinHuangwl 6 | * 7 | */ 8 | public record TickEntry(double price, double askPrice0, double bidPrice0, long volume, double openInterestDelta, long timestamp) { 9 | 10 | public static TickEntry of(double price, double askPrice0, double bidPrice0, long volume, double openInterestDelta, long timestamp) { 11 | return new TickEntry(price, askPrice0, bidPrice0, volume, openInterestDelta, timestamp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/main/java/org/dromara/northstar/gateway/playback/ticker/TickSimulationAlgorithm.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.ticker; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.common.model.core.Bar; 6 | 7 | /** 8 | * TICK生成算法 9 | * @author KevinHuangwl 10 | * 11 | */ 12 | public interface TickSimulationAlgorithm { 13 | 14 | /** 15 | * 根据BAR生成TICK 16 | * @param bar 17 | * @return 18 | */ 19 | List generateFrom(Bar bar); 20 | } 21 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/test/java/org/dromara/northstar/gateway/playback/PlaybackContractDefProviderTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class PlaybackContractDefProviderTest { 8 | 9 | @Test 10 | void test() { 11 | PlaybackContractDefProvider pvd = new PlaybackContractDefProvider(); 12 | assertThat(pvd.get()).isNotEmpty(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /northstar-gateway-playback/src/test/java/org/dromara/northstar/gateway/playback/model/DataFrameTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.playback.model; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.dromara.northstar.common.model.core.Bar; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class DataFrameTest { 9 | 10 | DataFrame bars = new DataFrame<>(50000); 11 | 12 | @Test 13 | void test() { 14 | Bar bar1 = Bar.builder().actionTimestamp(50000).build(); 15 | Bar bar2 = Bar.builder().actionTimestamp(1).build(); 16 | bars.add(bar1); 17 | bars.add(bar2); 18 | 19 | assertThat(bars.items()).hasSize(1); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /northstar-gateway-sim/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /northstar-gateway-sim/src/main/java/org/dromara/northstar/gateway/sim/SimLoader.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.sim; 2 | 3 | import org.dromara.northstar.common.constant.ChannelType; 4 | import org.dromara.northstar.gateway.GatewayMetaProvider; 5 | import org.dromara.northstar.gateway.sim.trade.SimGatewayFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.CommandLineRunner; 8 | import org.springframework.core.annotation.Order; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Order(0) 12 | @Component 13 | public class SimLoader implements CommandLineRunner{ 14 | 15 | @Autowired 16 | private GatewayMetaProvider gatewayMetaProvider; 17 | 18 | @Autowired 19 | private SimGatewayFactory simGatewayFactory; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | gatewayMetaProvider.add(ChannelType.SIM, null, simGatewayFactory); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /northstar-gateway-sim/src/main/java/org/dromara/northstar/gateway/sim/trade/Deal.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.sim.trade; 2 | 3 | import org.dromara.northstar.common.model.core.Trade; 4 | import org.dromara.northstar.common.utils.FieldUtils; 5 | 6 | import cn.hutool.core.lang.Assert; 7 | import lombok.Builder; 8 | import lombok.NonNull; 9 | 10 | @Builder 11 | public class Deal { 12 | @NonNull 13 | private Trade openTrade; 14 | @NonNull 15 | private Trade closeTrade; 16 | 17 | public Deal(Trade openTrade, Trade closeTrade) { 18 | this.openTrade = openTrade; 19 | this.closeTrade = closeTrade; 20 | Assert.isTrue(openTrade.contract().equals(closeTrade.contract())); 21 | Assert.isTrue(FieldUtils.isOpen(openTrade.offsetFlag())); 22 | Assert.isTrue(FieldUtils.isClose(closeTrade.offsetFlag())); 23 | } 24 | 25 | public Trade getCloseTrade() { 26 | return closeTrade; 27 | } 28 | 29 | public double profit() { 30 | int factor = FieldUtils.directionFactor(openTrade.direction()); 31 | return factor * (closeTrade.price() - openTrade.price()) * closeTrade.volume() * closeTrade.contract().multiplier(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /northstar-gateway-sim/src/main/java/org/dromara/northstar/gateway/sim/trade/SimTradeGateway.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.sim.trade; 2 | 3 | import org.dromara.northstar.common.TickDataAware; 4 | import org.dromara.northstar.gateway.TradeGateway; 5 | 6 | public interface SimTradeGateway extends TradeGateway, TickDataAware{ 7 | 8 | /** 9 | * 出入金 10 | * @param money 11 | * @return 最新余额 12 | */ 13 | int moneyIO(int money); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /northstar-gateway-sim/src/test/java/org/dromara/northstar/gateway/sim/trade/SimContractGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.sim.trade; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class SimContractGeneratorTest { 8 | 9 | @Test 10 | void test() { 11 | SimContractGenerator gen = new SimContractGenerator("test"); 12 | assertThat(gen.getContract()).isNotNull(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /northstar-gateway-sim/src/test/java/org/dromara/northstar/gateway/sim/trade/SimGatewayFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.gateway.sim.trade; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.mockito.Mockito.mock; 5 | 6 | import java.util.Map; 7 | 8 | import org.dromara.northstar.common.constant.ChannelType; 9 | import org.dromara.northstar.common.constant.GatewayUsage; 10 | import org.dromara.northstar.common.event.FastEventEngine; 11 | import org.dromara.northstar.common.model.GatewayDescription; 12 | import org.dromara.northstar.data.ISimAccountRepository; 13 | import org.dromara.northstar.gateway.IMarketCenter; 14 | import org.junit.jupiter.api.Test; 15 | 16 | class SimGatewayFactoryTest { 17 | 18 | @Test 19 | void test() { 20 | ISimAccountRepository accRepo = mock(ISimAccountRepository.class); 21 | SimGatewayFactory factory = new SimGatewayFactory(mock(FastEventEngine.class), accRepo, mock(IMarketCenter.class), mock(Map.class)); 22 | GatewayDescription gd = GatewayDescription.builder().gatewayId("gatewayid").channelType(ChannelType.SIM) 23 | .gatewayUsage(GatewayUsage.TRADE).build(); 24 | assertThat(factory.newInstance(gd)).isNotNull(); 25 | 26 | GatewayDescription gd2 = GatewayDescription.builder().gatewayId("gatewayid").channelType(ChannelType.SIM) 27 | .gatewayUsage(GatewayUsage.MARKET_DATA).build(); 28 | assertThat(factory.newInstance(gd2)).isNotNull(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /northstar-intelligence/.gitignore: -------------------------------------------------------------------------------- 1 | /data/ 2 | -------------------------------------------------------------------------------- /northstar-intelligence/src/test/java/org/dromara/northstar/ai/sampling/SampleDataWriterTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.ai.sampling; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 | 5 | import java.io.File; 6 | import java.util.Random; 7 | 8 | import org.dromara.northstar.ai.SampleData; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class SampleDataWriterTest { 12 | 13 | @Test 14 | void test() { 15 | assertDoesNotThrow(() -> { 16 | SampleDataWriter sdw = new SampleDataWriter(new File("data/test2.csv")); 17 | Random r = new Random(); 18 | for(int i=0; i<10; i++) { 19 | sdw.append(SampleData.builder() 20 | .actionDate("20231230") 21 | .actionTime("00:00:02") 22 | .states(new float[] {r.nextFloat(), r.nextFloat(), r.nextFloat()}) 23 | .marketPrice(r.nextDouble()) 24 | .build()); 25 | } 26 | }); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /northstar-main/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | logs/ 4 | test-output/ 5 | .mvn/** 6 | !**/src/main/** 7 | !**/src/test/** 8 | 9 | ### STS ### 10 | .apt_generated 11 | .classpath 12 | .factorypath 13 | .project 14 | .settings 15 | .springBeans 16 | .sts4-cache 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | /null/ 35 | /data/ 36 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/NorthstarApplication.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | @EnableScheduling 10 | @EnableAutoConfiguration 11 | @EnableJpaRepositories(basePackages = "org.dromara.northstar.data.jdbc") 12 | @SpringBootApplication 13 | public class NorthstarApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(NorthstarApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/YamlAndPropertySourceFactory.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar; 2 | 3 | import java.io.IOException; 4 | import java.util.List; 5 | import java.util.Properties; 6 | 7 | import org.springframework.boot.env.YamlPropertySourceLoader; 8 | import org.springframework.core.env.PropertiesPropertySource; 9 | import org.springframework.core.env.PropertySource; 10 | import org.springframework.core.io.Resource; 11 | import org.springframework.core.io.support.DefaultPropertySourceFactory; 12 | import org.springframework.core.io.support.EncodedResource; 13 | 14 | public class YamlAndPropertySourceFactory extends DefaultPropertySourceFactory { 15 | @Override 16 | public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { 17 | if (resource == null) { 18 | return super.createPropertySource(name, resource); 19 | } 20 | Resource resourceResource = resource.getResource(); 21 | if (!resourceResource.exists()) { 22 | return new PropertiesPropertySource(null, new Properties()); 23 | } else if (resourceResource.getFilename().endsWith(".yml") || resourceResource.getFilename().endsWith(".yaml")) { 24 | List> sources = new YamlPropertySourceLoader().load(resourceResource.getFilename(), resourceResource); 25 | return sources.get(0); 26 | } 27 | return super.createPropertySource(name, resource); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/account/AccountManager.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.account; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import java.util.concurrent.ConcurrentMap; 6 | 7 | import org.dromara.northstar.common.ObjectManager; 8 | import org.dromara.northstar.common.model.Identifier; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * 账户管理器 13 | * @author KevinHuangwl 14 | * 15 | */ 16 | @Component 17 | public class AccountManager implements ObjectManager{ 18 | 19 | private ConcurrentMap accountMap = new ConcurrentHashMap<>(); 20 | 21 | @Override 22 | public void add(TradeAccount account) { 23 | accountMap.put(Identifier.of(account.accountId()), account); 24 | } 25 | 26 | @Override 27 | public void remove(Identifier id) { 28 | accountMap.remove(id); 29 | } 30 | 31 | @Override 32 | public TradeAccount get(Identifier id) { 33 | return accountMap.get(id); 34 | } 35 | 36 | @Override 37 | public boolean contains(Identifier id) { 38 | return accountMap.containsKey(id); 39 | } 40 | 41 | public List allAccounts(){ 42 | return accountMap.values().stream().toList(); 43 | } 44 | 45 | @Override 46 | public List findAll() { 47 | return allAccounts(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/config/CacheConfig.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.config; 2 | 3 | import org.springframework.beans.factory.InitializingBean; 4 | import org.springframework.cache.annotation.EnableCaching; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | @Slf4j 11 | @EnableCaching 12 | @Configuration 13 | @Profile("!prod") 14 | public class CacheConfig implements InitializingBean{ 15 | 16 | @Override 17 | public void afterPropertiesSet() throws Exception { 18 | log.info("启用缓存管理"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/config/EngineConfig.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.config; 2 | 3 | import org.dromara.northstar.common.event.FastEventEngine; 4 | import org.dromara.northstar.event.DisruptorFastEventEngine; 5 | import org.dromara.northstar.event.DisruptorFastEventEngine.WaitStrategyEnum; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import lombok.extern.slf4j.Slf4j; 10 | 11 | /** 12 | * 引擎配置 13 | * @author KevinHuangwl 14 | * 15 | */ 16 | @Slf4j 17 | @Configuration 18 | class EngineConfig { 19 | 20 | @Bean 21 | FastEventEngine eventEngine() throws Exception { 22 | log.debug("创建EventEngine"); 23 | return new DisruptorFastEventEngine(WaitStrategyEnum.BlockingWaitStrategy); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/config/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.config; 2 | 3 | import org.dromara.northstar.common.event.FastEventEngine; 4 | import org.dromara.northstar.data.IPlaybackRuntimeRepository; 5 | import org.dromara.northstar.data.ISimAccountRepository; 6 | import org.dromara.northstar.gateway.GatewayMetaProvider; 7 | import org.dromara.northstar.gateway.IMarketCenter; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | class GatewayConfig { 13 | 14 | @Bean 15 | GatewayMetaProvider gatewayMetaProvider(FastEventEngine fastEventEngine, IMarketCenter mktCenter, 16 | IPlaybackRuntimeRepository rtRepo, ISimAccountRepository accRepo) { 17 | return new GatewayMetaProvider(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/config/UserInfo.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.config; 2 | 3 | import java.util.Optional; 4 | 5 | import org.dromara.northstar.common.constant.Constants; 6 | 7 | import lombok.Getter; 8 | 9 | /** 10 | * 用户信息 11 | * @author KevinHuangwl 12 | * 13 | */ 14 | @Getter 15 | public class UserInfo { 16 | 17 | protected String userId; 18 | protected String password; 19 | 20 | public UserInfo() { 21 | String user = System.getenv(Constants.NS_USER); 22 | String pwd = System.getenv(Constants.NS_PWD); 23 | userId = Optional.ofNullable(user).orElse(Constants.DEFAULT_USERID); 24 | password = Optional.ofNullable(pwd).orElse(Constants.DEFAULT_PASSWORD); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/GatewayDescriptionRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.GatewayDescriptionDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface GatewayDescriptionRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/MarketDataRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.data.jdbc.entity.BarDO; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | public interface MarketDataRepository extends CrudRepository { 9 | 10 | List findByUnifiedSymbolAndTradingDay(String unifiedSymbol, String tradingDay); 11 | 12 | void deleteByExpiredAtBefore(long expiredAt); 13 | } 14 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/MessageSenderSettingsRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.MessageSenderSettingsDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface MessageSenderSettingsRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/ModuleDealRecordRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import java.util.List; 4 | 5 | import org.dromara.northstar.data.jdbc.entity.ModuleDealRecordDO; 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | public interface ModuleDealRecordRepository extends CrudRepository{ 9 | 10 | List findByModuleName(String moduleName); 11 | 12 | void deleteByModuleName(String moduleName); 13 | } 14 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/ModuleDescriptionRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.ModuleDescriptionDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface ModuleDescriptionRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/ModuleRuntimeDescriptionRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.ModuleRuntimeDescriptionDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface ModuleRuntimeDescriptionRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/NotificationEventRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.SubscriptionEventsDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface NotificationEventRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/PlaybackRuntimeRepoAdapter.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import java.util.Objects; 4 | 5 | import org.dromara.northstar.common.model.PlaybackRuntimeDescription; 6 | import org.dromara.northstar.data.IPlaybackRuntimeRepository; 7 | import org.dromara.northstar.data.jdbc.entity.PlaybackRuntimeDescriptionDO; 8 | 9 | public class PlaybackRuntimeRepoAdapter implements IPlaybackRuntimeRepository{ 10 | 11 | private PlaybackRuntimeRepository delegate; 12 | 13 | public PlaybackRuntimeRepoAdapter(PlaybackRuntimeRepository delegate) { 14 | this.delegate = delegate; 15 | } 16 | 17 | @Override 18 | public void save(PlaybackRuntimeDescription playbackRtDescription) { 19 | delegate.save(PlaybackRuntimeDescriptionDO.convertFrom(playbackRtDescription)); 20 | } 21 | 22 | @Override 23 | public PlaybackRuntimeDescription findById(String playbackGatewayId) { 24 | PlaybackRuntimeDescriptionDO obj = delegate.findById(playbackGatewayId).orElse(null); 25 | if(Objects.isNull(obj)) { 26 | return null; 27 | } 28 | return obj.convertTo(); 29 | } 30 | 31 | @Override 32 | public void deleteById(String playbackGatewayId) { 33 | if(delegate.existsById(playbackGatewayId)) { 34 | delegate.deleteById(playbackGatewayId); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/PlaybackRuntimeRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.PlaybackRuntimeDescriptionDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface PlaybackRuntimeRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/SimAccountRepoAdapter.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import java.util.Collections; 4 | import java.util.Objects; 5 | 6 | import org.dromara.northstar.common.model.SimAccountDescription; 7 | import org.dromara.northstar.data.ISimAccountRepository; 8 | import org.dromara.northstar.data.jdbc.entity.SimAccountDescriptionDO; 9 | 10 | public class SimAccountRepoAdapter implements ISimAccountRepository { 11 | 12 | private SimAccountRepository delegate; 13 | 14 | public SimAccountRepoAdapter(SimAccountRepository delegate) { 15 | this.delegate = delegate; 16 | } 17 | 18 | @Override 19 | public void save(SimAccountDescription simAccountDescription) { 20 | delegate.save(SimAccountDescriptionDO.convertFrom(simAccountDescription)); 21 | } 22 | 23 | @Override 24 | public SimAccountDescription findById(String accountId) { 25 | SimAccountDescriptionDO obj = delegate.findById(accountId).orElse(null); 26 | if(Objects.isNull(obj)) { 27 | SimAccountDescription simAccount = new SimAccountDescription(); 28 | simAccount.setGatewayId(accountId); 29 | simAccount.setOpenTrades(Collections.emptyList()); 30 | return simAccount; 31 | } 32 | return obj.convertTo(); 33 | } 34 | 35 | @Override 36 | public void deleteById(String accountId) { 37 | if(delegate.existsById(accountId)) { 38 | delegate.deleteById(accountId); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/SimAccountRepository.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc; 2 | 3 | import org.dromara.northstar.data.jdbc.entity.SimAccountDescriptionDO; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface SimAccountRepository extends CrudRepository{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/BarDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Index; 8 | import jakarta.persistence.Lob; 9 | import jakarta.persistence.Table; 10 | 11 | import lombok.AllArgsConstructor; 12 | import lombok.Builder; 13 | import lombok.Data; 14 | import lombok.NoArgsConstructor; 15 | 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | @Data 20 | @Entity 21 | @Table(name="BAR", indexes = { 22 | @Index(name="idx_symbol_tradingDay", columnList = "unifiedSymbol, tradingDay"), 23 | @Index(name="idx_expiredAt", columnList = "expiredAt") 24 | }) 25 | public class BarDO { 26 | 27 | @Id 28 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 29 | private int id; 30 | 31 | private String unifiedSymbol; 32 | 33 | private String tradingDay; 34 | 35 | private long expiredAt; 36 | @Lob 37 | private byte[] barData; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/GatewayDescriptionDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | import jakarta.persistence.Index; 6 | import jakarta.persistence.Lob; 7 | import jakarta.persistence.Table; 8 | 9 | import org.dromara.northstar.common.model.GatewayDescription; 10 | 11 | import com.alibaba.fastjson2.JSON; 12 | 13 | import lombok.AllArgsConstructor; 14 | import lombok.Data; 15 | import lombok.NoArgsConstructor; 16 | 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Data 20 | @Entity 21 | @Table(name="GATEWAY", indexes = { 22 | @Index(name="idx_gatewayId", columnList = "gatewayId") 23 | }) 24 | public class GatewayDescriptionDO { 25 | 26 | @Id 27 | private String gatewayId; 28 | @Lob 29 | private String dataStr; 30 | 31 | public static GatewayDescriptionDO convertFrom(GatewayDescription gd) { 32 | return new GatewayDescriptionDO(gd.getGatewayId(), JSON.toJSONString(gd)); 33 | } 34 | 35 | public GatewayDescription convertTo() { 36 | return JSON.parseObject(dataStr, GatewayDescription.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/MessageSenderSettingsDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | import jakarta.persistence.Lob; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Data 14 | @Entity 15 | public class MessageSenderSettingsDO { 16 | 17 | @Id 18 | private String className; 19 | 20 | @Lob 21 | private String settingsData; 22 | } 23 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/ModuleDescriptionDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | import jakarta.persistence.Index; 6 | import jakarta.persistence.Lob; 7 | import jakarta.persistence.Table; 8 | 9 | import org.dromara.northstar.common.model.ModuleDescription; 10 | 11 | import com.alibaba.fastjson2.JSON; 12 | 13 | import lombok.AllArgsConstructor; 14 | import lombok.Data; 15 | import lombok.NoArgsConstructor; 16 | 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Data 20 | @Entity 21 | @Table(name="MODULE_DESCRIPTION", indexes = { 22 | @Index(name="idx_moduleName", columnList = "moduleName"), 23 | }) 24 | public class ModuleDescriptionDO { 25 | 26 | @Id 27 | private String moduleName; 28 | @Lob 29 | private String dataStr; 30 | 31 | public static ModuleDescriptionDO convertFrom(ModuleDescription moduleDescription) { 32 | return new ModuleDescriptionDO(moduleDescription.getModuleName(), JSON.toJSONString(moduleDescription)); 33 | } 34 | 35 | public ModuleDescription convertTo() { 36 | return JSON.parseObject(dataStr, ModuleDescription.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/ModuleRuntimeDescriptionDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | import jakarta.persistence.Index; 6 | import jakarta.persistence.Lob; 7 | import jakarta.persistence.Table; 8 | 9 | import org.dromara.northstar.common.model.ModuleRuntimeDescription; 10 | 11 | import com.alibaba.fastjson2.JSON; 12 | 13 | import lombok.AllArgsConstructor; 14 | import lombok.Data; 15 | import lombok.NoArgsConstructor; 16 | 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Data 20 | @Entity 21 | @Table(name="MODULE_RT", indexes = { 22 | @Index(name="idx_rt_moduleName", columnList = "moduleName"), 23 | }) 24 | public class ModuleRuntimeDescriptionDO { 25 | 26 | @Id 27 | private String moduleName; 28 | @Lob 29 | private String dataStr; 30 | 31 | public static ModuleRuntimeDescriptionDO convertFrom(ModuleRuntimeDescription moduleRtDescription) { 32 | return new ModuleRuntimeDescriptionDO(moduleRtDescription.getModuleName(), JSON.toJSONString(moduleRtDescription)); 33 | } 34 | 35 | public ModuleRuntimeDescription convertTo() { 36 | return JSON.parseObject(dataStr, ModuleRuntimeDescription.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/PlaybackRuntimeDescriptionDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import jakarta.persistence.Entity; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Table; 8 | 9 | import org.dromara.northstar.common.model.PlaybackRuntimeDescription; 10 | 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Data 18 | @Entity 19 | @Table(name="PLAYBACK_RT") 20 | public class PlaybackRuntimeDescriptionDO { 21 | 22 | @Id 23 | private String gatewayId; 24 | 25 | private LocalDateTime playbackTimeState; 26 | 27 | public static PlaybackRuntimeDescriptionDO convertFrom(PlaybackRuntimeDescription playbackRtDescription) { 28 | return new PlaybackRuntimeDescriptionDO(playbackRtDescription.getGatewayId(), playbackRtDescription.getPlaybackTimeState()); 29 | } 30 | 31 | public PlaybackRuntimeDescription convertTo() { 32 | return PlaybackRuntimeDescription.builder() 33 | .gatewayId(gatewayId) 34 | .playbackTimeState(playbackTimeState) 35 | .build(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/SimAccountDescriptionDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | import jakarta.persistence.Index; 6 | import jakarta.persistence.Lob; 7 | import jakarta.persistence.Table; 8 | 9 | import org.dromara.northstar.common.model.SimAccountDescription; 10 | 11 | import com.alibaba.fastjson2.JSON; 12 | 13 | import lombok.AllArgsConstructor; 14 | import lombok.Data; 15 | import lombok.NoArgsConstructor; 16 | 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @Data 20 | @Entity 21 | @Table(name="SIM_ACCOUNT", indexes = { 22 | @Index(name="idx_accountId", columnList = "accountId") 23 | }) 24 | public class SimAccountDescriptionDO { 25 | 26 | @Id 27 | private String accountId; 28 | @Lob 29 | private String dataStr; 30 | 31 | public static SimAccountDescriptionDO convertFrom(SimAccountDescription simAccountDescription) { 32 | return new SimAccountDescriptionDO(simAccountDescription.getGatewayId(), JSON.toJSONString(simAccountDescription)); 33 | } 34 | 35 | public SimAccountDescription convertTo() { 36 | return JSON.parseObject(dataStr, SimAccountDescription.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/data/jdbc/entity/SubscriptionEventsDO.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.data.jdbc.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.Id; 5 | 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @NoArgsConstructor 10 | @Data 11 | @Entity 12 | public class SubscriptionEventsDO { 13 | 14 | public static final String FIXED_ID = "SUB_EVENT"; 15 | 16 | @Id 17 | private String id = FIXED_ID; 18 | 19 | private String subEvents; 20 | } 21 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/event/IllegalOrderHandler.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.event; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedList; 5 | import java.util.Objects; 6 | import java.util.Queue; 7 | 8 | import org.dromara.northstar.common.event.AbstractEventHandler; 9 | import org.dromara.northstar.common.event.GenericEventHandler; 10 | import org.dromara.northstar.common.event.NorthstarEvent; 11 | import org.dromara.northstar.common.event.NorthstarEventType; 12 | import org.dromara.northstar.common.model.core.Order; 13 | 14 | import xyz.redtorch.pb.CoreEnum.OrderStatusEnum; 15 | 16 | /** 17 | * 废单收集器 18 | * 专门收集废单,用于风控警报 19 | * @author KevinHuangwl 20 | * 21 | */ 22 | public class IllegalOrderHandler extends AbstractEventHandler implements GenericEventHandler{ 23 | 24 | private Queue records = new LinkedList<>(); 25 | 26 | @Override 27 | public boolean canHandle(NorthstarEventType eventType) { 28 | return eventType == NorthstarEventType.ORDER; 29 | } 30 | 31 | @Override 32 | protected void doHandle(NorthstarEvent e) { 33 | Order order = (Order) e.getData(); 34 | if(!records.isEmpty() && !Objects.equals(order.tradingDay(), records.peek().tradingDay())) { 35 | records.clear(); // 每日清零 36 | } 37 | if(order.orderStatus() == OrderStatusEnum.OS_Rejected) { 38 | records.add(order); 39 | } 40 | } 41 | 42 | public Collection getIllegalOrders(){ 43 | return records; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/event/ModuleHandler.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.event; 2 | 3 | import java.util.EnumSet; 4 | import java.util.Set; 5 | 6 | import org.dromara.northstar.common.event.AbstractEventHandler; 7 | import org.dromara.northstar.common.event.GenericEventHandler; 8 | import org.dromara.northstar.common.event.NorthstarEvent; 9 | import org.dromara.northstar.common.event.NorthstarEventType; 10 | import org.dromara.northstar.module.ModuleManager; 11 | 12 | 13 | 14 | public class ModuleHandler extends AbstractEventHandler implements GenericEventHandler{ 15 | 16 | private ModuleManager moduleMgr; 17 | 18 | private static final Set TARGET_TYPE = EnumSet.of( 19 | NorthstarEventType.TICK, 20 | NorthstarEventType.BAR, 21 | NorthstarEventType.TRADE, 22 | NorthstarEventType.ORDER 23 | ); 24 | 25 | public ModuleHandler(ModuleManager moduleMgr) { 26 | this.moduleMgr = moduleMgr; 27 | } 28 | 29 | @Override 30 | public boolean canHandle(NorthstarEventType eventType) { 31 | return TARGET_TYPE.contains(eventType); 32 | } 33 | 34 | @Override 35 | protected void doHandle(NorthstarEvent e) { 36 | moduleMgr.allModules().parallelStream().forEach(module -> module.onEvent(e)); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/module/ModuleManager.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.module; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import java.util.concurrent.ConcurrentMap; 6 | 7 | import org.dromara.northstar.common.ObjectManager; 8 | import org.dromara.northstar.common.model.Identifier; 9 | import org.dromara.northstar.strategy.IModule; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 模组管理器 14 | * @author KevinHuangwl 15 | * 16 | */ 17 | @Component 18 | public class ModuleManager implements ObjectManager{ 19 | 20 | private ConcurrentMap moduleMap = new ConcurrentHashMap<>(); 21 | 22 | @Override 23 | public void add(IModule module) { 24 | moduleMap.put(Identifier.of(module.getName()), module); 25 | } 26 | 27 | @Override 28 | public void remove(Identifier id) { 29 | moduleMap.remove(id); 30 | } 31 | 32 | @Override 33 | public IModule get(Identifier id) { 34 | return moduleMap.get(id); 35 | } 36 | 37 | @Override 38 | public boolean contains(Identifier id) { 39 | return moduleMap.containsKey(id); 40 | } 41 | 42 | public List allModules(){ 43 | return moduleMap.values().stream().toList(); 44 | } 45 | 46 | @Override 47 | public List findAll() { 48 | return allModules(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/support/ServiceLoader.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support; 2 | 3 | import org.dromara.northstar.web.service.GatewayService; 4 | import org.dromara.northstar.web.service.ModuleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.CommandLineRunner; 7 | import org.springframework.core.Ordered; 8 | import org.springframework.core.annotation.Order; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Order(Ordered.LOWEST_PRECEDENCE - 100) 12 | @Component 13 | public class ServiceLoader implements CommandLineRunner{ 14 | 15 | @Autowired 16 | GatewayService gatewayService; 17 | 18 | @Autowired 19 | ModuleService moduleService; 20 | 21 | @Override 22 | public void run(String... args) throws Exception { 23 | gatewayService.postLoad(); 24 | moduleService.postLoad(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/support/utils/BarCacheKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support.utils; 2 | 3 | import java.lang.reflect.Method; 4 | import java.time.LocalDate; 5 | 6 | import org.dromara.northstar.common.model.core.Contract; 7 | import org.springframework.cache.interceptor.KeyGenerator; 8 | import org.springframework.stereotype.Component; 9 | 10 | @Component 11 | public class BarCacheKeyGenerator implements KeyGenerator{ 12 | 13 | @Override 14 | public Object generate(Object target, Method method, Object... params) { 15 | Contract contract = (Contract) params[0]; 16 | LocalDate startDate = (LocalDate) params[1]; 17 | LocalDate endDate = (LocalDate) params[2]; 18 | return String.format("%s:%s:%s:%s", method.getName(), contract.unifiedSymbol(), startDate, endDate); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/support/utils/ExceptionLogChecker.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.Reader; 5 | import java.time.LocalTime; 6 | import java.util.List; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | import org.apache.commons.io.IOUtils; 11 | 12 | /** 13 | * 异常日志检查器 14 | * @author KevinHuangwl 15 | * 16 | */ 17 | public class ExceptionLogChecker { 18 | 19 | private Reader reader; 20 | 21 | private static final Pattern timePtn = Pattern.compile("(\\d{2}):(\\d{2}):(\\d{2}).\\d{3}"); 22 | private static final Pattern levelPtn = Pattern.compile("ERROR"); 23 | 24 | public ExceptionLogChecker(Reader reader) { 25 | this.reader = reader; 26 | } 27 | 28 | public List getExceptionLog(LocalTime fromTime, LocalTime toTime) throws IOException{ 29 | return IOUtils.readLines(reader).stream() 30 | .filter(line -> levelPtn.matcher(line).find()) 31 | .filter(line -> { 32 | Matcher m = timePtn.matcher(line); 33 | if(m.find()) { 34 | int hour = Integer.parseInt(m.group(1)); 35 | int min = Integer.parseInt(m.group(2)); 36 | int sec = Integer.parseInt(m.group(3)); 37 | LocalTime t = LocalTime.of(hour, min, sec); 38 | return fromTime.isBefore(t) && toTime.isAfter(t); 39 | } 40 | return false; 41 | }) 42 | .toList(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/support/utils/NamingValidator.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support.utils; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class NamingValidator { 6 | 7 | private static final Pattern ptn = Pattern.compile("^[\\u4e00-\\u9fa5a-zA-Z0-9_]+$"); 8 | 9 | public boolean isValid(String name) { 10 | return ptn.matcher(name).matches(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/web/PostLoadAware.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.web; 2 | 3 | public interface PostLoadAware { 4 | 5 | void postLoad(); 6 | } 7 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/web/interceptor/AuthorizationInterceptor.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.web.interceptor; 2 | 3 | import jakarta.servlet.http.HttpServletRequest; 4 | import jakarta.servlet.http.HttpServletResponse; 5 | 6 | import org.dromara.northstar.common.constant.Constants; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.web.servlet.HandlerInterceptor; 9 | 10 | import lombok.extern.slf4j.Slf4j; 11 | 12 | @Slf4j 13 | public class AuthorizationInterceptor implements HandlerInterceptor{ 14 | 15 | @Override 16 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 17 | throws Exception { 18 | HttpServletRequest req = (HttpServletRequest) request; 19 | String path = req.getRequestURI(); 20 | if(path.startsWith("/northstar/auth/login") || path.startsWith("/redirect") || !path.startsWith("/northstar")) { 21 | return true; 22 | } 23 | 24 | Object user = req.getSession().getAttribute(Constants.KEY_USER); 25 | if(user != null) { 26 | return true; 27 | } 28 | 29 | String msg = "token校验失败,IP:" + request.getRemoteAddr(); 30 | response.sendError(HttpStatus.UNAUTHORIZED.value(), msg); 31 | log.warn(msg); 32 | return false; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /northstar-main/src/main/java/org/dromara/northstar/web/restful/VersionController.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.web.restful; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.info.BuildProperties; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | @RequestMapping("/version") 11 | public class VersionController { 12 | 13 | @Autowired(required = false) 14 | BuildProperties buildProperties; 15 | 16 | @GetMapping 17 | public String getVersion() { 18 | if(buildProperties == null) { 19 | return "dev-only"; 20 | } 21 | return buildProperties.getVersion(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /northstar-main/src/main/resources/.gitignore: -------------------------------------------------------------------------------- 1 | /static/ 2 | -------------------------------------------------------------------------------- /northstar-main/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | /$$ /$$ /$$ /$$ /$$ 4 | | $$$ | $$ | $$ | $$ | $$ 5 | | $$$$| $$ /$$$$$$ /$$$$$$ /$$$$$$ | $$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ 6 | | $$ $$ $$ /$$__ $$ /$$__ $$|_ $$_/ | $$__ $$ /$$_____/|_ $$_/ |____ $$ /$$__ $$ 7 | | $$ $$$$| $$ \ $$| $$ \__/ | $$ | $$ \ $$| $$$$$$ | $$ /$$$$$$$| $$ \__/ 8 | | $$\ $$$| $$ | $$| $$ | $$ /$$| $$ | $$ \____ $$ | $$ /$$ /$$__ $$| $$ 9 | | $$ \ $$| $$$$$$/| $$ | $$$$/| $$ | $$ /$$$$$$$/ | $$$$/| $$$$$$$| $$ 10 | |__/ \__/ \______/ |__/ \___/ |__/ |__/|_______/ \___/ \_______/|__/ 11 | 12 | -------------------------------------------------------------------------------- /northstar-main/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | java.lang.String 10 | java.util.List 11 | 12 | 720 13 | 14 | 15 | 10000 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /northstar-main/src/main/resources/keystore/northstarKeyStore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-main/src/main/resources/keystore/northstarKeyStore.p12 -------------------------------------------------------------------------------- /northstar-main/src/test/java/org/dromara/northstar/support/log/ModuleLoggerFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support.log; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import ch.qos.logback.classic.Level; 6 | import ch.qos.logback.classic.Logger; 7 | 8 | class ModuleLoggerFactoryTest { 9 | 10 | static { 11 | System.setProperty("LOG_PATH", "logs"); 12 | } 13 | ModuleLoggerFactory factory = new ModuleLoggerFactory("单元测试"); 14 | 15 | @Test 16 | void test() { 17 | Logger logger = (Logger) factory.getLogger("test"); 18 | logger.setLevel(Level.TRACE); 19 | logger.trace("TRACE LOG"); 20 | logger.debug("DEBUG LOG"); 21 | logger.info("INFO LOG"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /northstar-main/src/test/java/org/dromara/northstar/support/utils/NamingValidatorTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.support.utils; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class NamingValidatorTest { 8 | 9 | @Test 10 | void test() { 11 | NamingValidator validator = new NamingValidator(); 12 | 13 | assertThat(validator.isValid("666")).isTrue(); 14 | assertThat(validator.isValid("sss")).isTrue(); 15 | assertThat(validator.isValid("好好好")).isTrue(); 16 | assertThat(validator.isValid("策略_a1")).isTrue(); 17 | assertThat(validator.isValid("//\\\\")).isFalse(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /northstar-main/src/test/java/org/dromara/northstar/utils/CodecUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.dromara.northstar.utils; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.dromara.northstar.support.utils.CodecUtils; 6 | import org.junit.jupiter.api.AfterEach; 7 | import org.junit.jupiter.api.BeforeEach; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class CodecUtilsTest { 11 | 12 | @BeforeEach 13 | public void setUp() throws Exception { 14 | } 15 | 16 | @AfterEach 17 | public void tearDown() throws Exception { 18 | } 19 | 20 | @Test 21 | public void test() { 22 | String message = "hello world"; 23 | assertThat(CodecUtils.encrypt(message)).isNotEqualTo(message); 24 | assertThat(CodecUtils.decrypt(CodecUtils.encrypt(message))).isEqualTo(message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /northstar-monitor/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead -------------------------------------------------------------------------------- /northstar-monitor/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: ['plugin:vue/essential', 'eslint:recommended', 'prettier'], 7 | parserOptions: { 8 | parser: 'babel-eslint' 9 | }, 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /northstar-monitor/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .vscode -------------------------------------------------------------------------------- /northstar-monitor/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 100, //一行的字符数,如果超过会进行换行,默认为80 3 | tabWidth: 2, //一个tab代表几个空格数,默认为80 4 | useTabs: false, //是否使用tab进行缩进,默认为false,表示用空格进行缩减 5 | singleQuote: true, //字符串是否使用单引号,默认为false,使用双引号 6 | semi: false, //行位是否使用分号,默认为true 7 | trailingComma: 'none', //是否使用尾逗号,有三个可选值"" 8 | bracketSpacing: true //对象大括号直接是否有空格,默认为true,效果:{ foo: bar } 9 | // parser: 'babel' //代码的解析引擎,默认为babylon,与babel相同。 10 | } 11 | -------------------------------------------------------------------------------- /northstar-monitor/README.md: -------------------------------------------------------------------------------- 1 | # Northstar 盈富量化平台网页监控端 2 | 3 | ## 参考项目 4 | [KLineChart](https://github.com/liihuu/KLineChart),一个很牛逼的K线控件库。 5 | - 参考示例:https://liihuu.github.io/KLineChart/ (可能需要翻墙) 6 | - 代码示例:https://github.com/liihuu/KLineChartSample 7 | - 参考文档:https://www.yuque.com/liihuu/klinechart 8 | -------------------------------------------------------------------------------- /northstar-monitor/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["@vue/cli-plugin-babel/preset"], 3 | }; 4 | -------------------------------------------------------------------------------- /northstar-monitor/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | [[ $(pgrep node | wc -l) > 0 ]] && bash ./shutdown.sh 6 | 7 | echo "准备环境依赖..." 8 | yum install git nodejs -y 9 | 10 | echo "构建项目" 11 | npm config set registry http://registry.npm.taobao.org/ 12 | npm i 13 | npm run build 14 | cd server 15 | npm i 16 | cd .. 17 | bash ./startup.sh -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/fixtures/example.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Using fixtures to represent data", 3 | "email": "hello@cypress.io", 4 | "body": "Fixtures are a great way to mock data for responses to routes" 5 | } 6 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | // *********************************************************** 3 | // This example plugins/index.js can be used to load plugins 4 | // 5 | // You can change the location of this file or turn off loading 6 | // the plugins file with the 'pluginsFile' configuration option. 7 | // 8 | // You can read more here: 9 | // https://on.cypress.io/plugins-guide 10 | // *********************************************************** 11 | 12 | // This function is called when a project is opened or re-opened (e.g. due to 13 | // the project's config changing) 14 | 15 | /** 16 | * @type {Cypress.PluginConfig} 17 | */ 18 | // eslint-disable-next-line no-unused-vars 19 | module.exports = (on, config) => { 20 | // `on` is used to hook into various events Cypress emits 21 | // `config` is the resolved Cypress config 22 | } 23 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | // *********************************************** 2 | // This example commands.js shows you how to 3 | // create various custom commands and overwrite 4 | // existing commands. 5 | // 6 | // For more comprehensive examples of custom 7 | // commands please read more here: 8 | // https://on.cypress.io/custom-commands 9 | // *********************************************** 10 | // 11 | // 12 | // -- This is a parent command -- 13 | // Cypress.Commands.add('login', (email, password) => { ... }) 14 | // 15 | // 16 | // -- This is a child command -- 17 | // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) 18 | // 19 | // 20 | // -- This is a dual command -- 21 | // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) 22 | // 23 | // 24 | // -- This will overwrite an existing command -- 25 | // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) 26 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/support/component-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Components App 8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/support/component.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/component.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands' 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | 22 | import { mount } from 'cypress/vue2' 23 | 24 | Cypress.Commands.add('mount', mount) 25 | 26 | // Example use: 27 | // cy.mount(MyComponent) -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/support/e2e.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/e2e.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands' 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') -------------------------------------------------------------------------------- /northstar-monitor/e2e/cypress/support/index.js: -------------------------------------------------------------------------------- 1 | // *********************************************************** 2 | // This example support/index.js is processed and 3 | // loaded automatically before your test files. 4 | // 5 | // This is a great place to put global configuration and 6 | // behavior that modifies Cypress. 7 | // 8 | // You can change the location of this file or turn off 9 | // automatically serving support files with the 10 | // 'supportFile' configuration option. 11 | // 12 | // You can read more here: 13 | // https://on.cypress.io/configuration 14 | // *********************************************************** 15 | 16 | // Import commands.js using ES2015 syntax: 17 | import './commands' 18 | 19 | // Alternatively you can use CommonJS syntax: 20 | // require('./commands') 21 | -------------------------------------------------------------------------------- /northstar-monitor/e2e/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "northstar-e2e", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "e2e": "./node_modules/.bin/cypress open", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "KevinHuangwl", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "cypress": "^9.6.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | out/ 3 | logs/ 4 | run/ 5 | .idea/ 6 | package-lock.json 7 | data/ 8 | .vscode/launch.json 9 | public/electron/ 10 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: node_js 3 | node_js: 4 | - '8' 5 | - '10' 6 | - '12' 7 | before_install: 8 | - npm i npminstall -g 9 | install: 10 | - npminstall 11 | script: 12 | - npm run ci 13 | after_script: 14 | - npminstall codecov && codecov 15 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '8' 4 | - nodejs_version: '10' 5 | - nodejs_version: '12' 6 | 7 | install: 8 | - ps: Install-Product node $env:nodejs_version 9 | - npm i npminstall && node_modules\.bin\npminstall 10 | 11 | test_script: 12 | - node --version 13 | - npm --version 14 | - npm run test 15 | 16 | build: off 17 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/extraResources/placeholder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/extraResources/placeholder.txt -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/icons/256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/icons/256x256.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/icons/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/icons/32x32.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/icons/512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/icons/512x512.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/icons/64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/icons/64x64.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/build/icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/build/icons/icon.ico -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/addon/example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * example插件 3 | * @class 4 | */ 5 | class ExampleAddon { 6 | 7 | constructor(app) { 8 | this.app = app; 9 | } 10 | 11 | /** 12 | * hello 13 | * 14 | * @function 15 | * @since 1.0.0 16 | */ 17 | hello () { 18 | return 'hello'; 19 | } 20 | } 21 | 22 | ExampleAddon.toString = () => '[class ExampleAddon]'; 23 | module.exports = ExampleAddon; -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/addon/security/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 安全插件 3 | * @class 4 | */ 5 | class SecurityAddon { 6 | 7 | constructor(app) { 8 | this.app = app; 9 | } 10 | 11 | /** 12 | * 创建 13 | */ 14 | create () { 15 | this.app.console.info('[addon:security] load'); 16 | const runWithDebug = process.argv.find(function(e){ 17 | let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port"); 18 | return isHasDebug; 19 | }) 20 | 21 | // 不允许远程调试 22 | if (runWithDebug) { 23 | this.app.logger.error('[error] Remote debugging is not allowed, runWithDebug:', runWithDebug); 24 | this.app.appQuit(); 25 | } 26 | } 27 | } 28 | 29 | SecurityAddon.toString = () => '[class SecurityAddon]'; 30 | module.exports = SecurityAddon; -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/config/config.local.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | * test 5 | */ 6 | exports.testConfig = { 7 | login: 'http://local.com/api/login', 8 | }; 9 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/config/config.prod.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | * test 5 | */ 6 | module.exports = () => { 7 | return { 8 | openDevTools: false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/config/encrypt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 加密配置 3 | */ 4 | module.exports = { 5 | type: 'confusion', 6 | directory: [ 7 | 'electron' 8 | ], 9 | fileExt: ['.js'], 10 | confusionOptions: { 11 | compact: true, 12 | stringArray: true, 13 | stringArrayEncoding: ['base64'], 14 | deadCodeInjection: false, 15 | } 16 | }; -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/config/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": [ 3 | "electron/", 4 | "main.js" 5 | ], 6 | "ignore": [], 7 | "ext": "js,json", 8 | "verbose": true, 9 | "exec": "electron . --env=local --hot-reload=1", 10 | "restartable": "hr", 11 | "colours": true, 12 | "events": {} 13 | } -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/preload/bridge.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 如果启用了上下文隔离,渲染进程无法使用electron的api, 3 | * 可通过contextBridge 导出api给渲染进程使用 4 | */ 5 | 6 | const { contextBridge, ipcRenderer } = require('electron') 7 | 8 | contextBridge.exposeInMainWorld('electron', { 9 | ipcRenderer: ipcRenderer, 10 | }) -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/electron/preload/index.js: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | ** preload为预加载模块,该文件将会在程序启动时加载 ** 3 | *************************************************/ 4 | 5 | /** 6 | * 预加载模块入口 7 | * @param {Object} app - 全局app对象 8 | */ 9 | module.exports = async (app) => { 10 | 11 | //已实现的功能模块,可选择性使用和修改 12 | const trayAddon = app.addon.tray; 13 | const securityAddon = app.addon.security; 14 | const awakenAddon = app.addon.awaken; 15 | const autoUpdaterAddon = app.addon.autoUpdater; 16 | 17 | trayAddon.create(); 18 | securityAddon.create(); 19 | awakenAddon.create(); 20 | autoUpdaterAddon.create(); 21 | } -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/html/loading.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 |
19 | 20 |
21 | 22 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/html/view_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 |
19 | 这是一个html页面 20 |
21 | 22 | -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/images/loding.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/public/images/loding.gif -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/images/logo-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/public/images/logo-32.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/public/images/logo.png -------------------------------------------------------------------------------- /northstar-monitor/electron-egg/public/images/tray_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/electron-egg/public/images/tray_logo.png -------------------------------------------------------------------------------- /northstar-monitor/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /northstar-monitor/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Northstar盈富量化平台 15 | 16 | 17 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /northstar-monitor/public/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/public/logo/logo.png -------------------------------------------------------------------------------- /northstar-monitor/public/ns.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/public/ns.ico -------------------------------------------------------------------------------- /northstar-monitor/public/static/index.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | margin: 0px; 4 | padding: 0px; 5 | height: 100%; 6 | background-color: #545c64; 7 | color: white; 8 | font-size: 14px; 9 | user-select: none; 10 | } 11 | 12 | .ns-page { 13 | padding: 15px; 14 | width: 100%; 15 | display: flex; 16 | } 17 | 18 | .ns-block { 19 | width: 100%; 20 | height: 100%; 21 | } 22 | 23 | div::-webkit-scrollbar { 24 | /*滚动条整体样式*/ 25 | width: 6px; /*高宽分别对应横竖滚动条的尺寸*/ 26 | height: 6px; 27 | scrollbar-arrow-color: red; 28 | } 29 | div::-webkit-scrollbar-thumb { 30 | /*滚动条里面小方块*/ 31 | border-radius: 5px; 32 | -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); 33 | background: rgba(0, 0, 0, 0.2); 34 | scrollbar-arrow-color: red; 35 | } 36 | div::-webkit-scrollbar-track { 37 | /*滚动条里面轨道*/ 38 | -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); 39 | border-radius: 0; 40 | background: rgba(0, 0, 0, 0.1); 41 | } 42 | 43 | .color-red { 44 | color: #ee9090; 45 | } 46 | 47 | .color-green { 48 | color: #93c57a; 49 | } 50 | 51 | .el-dialog { 52 | min-width: 370px; 53 | } 54 | .el-menu { 55 | height: 100%; 56 | } 57 | .text-selectable { 58 | user-select: all !important; 59 | } 60 | .el-select__input{ 61 | color: white; 62 | } -------------------------------------------------------------------------------- /northstar-monitor/public/static/theme/fonts/element-icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/public/static/theme/fonts/element-icons.ttf -------------------------------------------------------------------------------- /northstar-monitor/public/static/theme/fonts/element-icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/public/static/theme/fonts/element-icons.woff -------------------------------------------------------------------------------- /northstar-monitor/shutdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | kill `pgrep node` -------------------------------------------------------------------------------- /northstar-monitor/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 25 | 26 | 32 | -------------------------------------------------------------------------------- /northstar-monitor/src/api/alertingApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | subEvents(){ 5 | return baseService.get(`/alerting/events`) 6 | }, 7 | saveEvents(events){ 8 | return baseService.post(`/alerting/events`, events) 9 | }, 10 | getSettings(){ 11 | return baseService.get('/alerting/settings') 12 | }, 13 | saveSettings(settings){ 14 | return baseService.post('/alerting/settings', settings) 15 | }, 16 | testSettings(settings){ 17 | return baseService.post('/alerting/test', settings) 18 | } 19 | } -------------------------------------------------------------------------------- /northstar-monitor/src/api/contractApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | getGatewayContracts(channelType, query){ 5 | return baseService.get(`/contracts?channelType=${channelType}&query=${query||''}`) 6 | }, 7 | getSubscribedContracts(gatewayId, query){ 8 | return baseService.get(`/contracts/subscribed?gatewayId=${gatewayId}&query=${query||''}`) 9 | } 10 | } -------------------------------------------------------------------------------- /northstar-monitor/src/api/gatewayDataApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | loadWeeklyBarData(gatewayId, unifiedSymbol, refStartTimestamp, firstLoad){ 5 | return baseService.get(`/data/bar/min?gatewayId=${gatewayId}&unifiedSymbol=${unifiedSymbol}&refStartTimestamp=${refStartTimestamp}&firstLoad=${firstLoad}`) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /northstar-monitor/src/api/gatewayMgmtApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | create(gateway) { 5 | return baseService.post('/gateway', gateway) 6 | }, 7 | remove(gatewayId) { 8 | return baseService.delete('/gateway?gatewayId=' + gatewayId) 9 | }, 10 | update(gateway) { 11 | return baseService.put('/gateway', gateway) 12 | }, 13 | findAll(gatewayUsage) { 14 | return baseService.get('/gateway?usage=' + gatewayUsage) 15 | }, 16 | find(gatewayId){ 17 | return baseService.get('/gateway/specific?gatewayId=' + gatewayId) 18 | }, 19 | connect(gatewayId) { 20 | return baseService.get('/gateway/connection?gatewayId=' + gatewayId) 21 | }, 22 | disconnect(gatewayId) { 23 | return baseService.delete('/gateway/connection?gatewayId=' + gatewayId) 24 | }, 25 | moneyIO(gatewayId, money) { 26 | return baseService.post(`/gateway/moneyio?gatewayId=${gatewayId}&money=${money}`) 27 | }, 28 | isActive(gatewayId) { 29 | return baseService.get('/gateway/active?gatewayId=' + gatewayId) 30 | }, 31 | getGatewayTypeDescriptions(){ 32 | return baseService.get('/gateway/types') 33 | }, 34 | getGatewaySettingsMetaInfo(channelType){ 35 | return baseService.get('/gateway/settings?channelType=' + channelType) 36 | }, 37 | resetPlayback(gatewayId){ 38 | return baseService.get(`/gateway/reset?gatewayId=${gatewayId}`) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /northstar-monitor/src/api/logApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | tailPlatformLog(positionOffset, maxLinesToLoad){ 5 | return baseService.get(`/log?positionOffset=${positionOffset}&tailNumOfLines=${maxLinesToLoad}`) 6 | }, 7 | tailModuleLog(moduleName, positionOffset, maxLinesToLoad){ 8 | return baseService.get(`/log/module?name=${moduleName}&positionOffset=${positionOffset}&tailNumOfLines=${maxLinesToLoad}`) 9 | }, 10 | getPlatformLogLevel(){ 11 | return baseService.get('/log/level') 12 | }, 13 | setPlatformLogLevel(level){ 14 | return baseService.put('/log/level?level=' + level) 15 | }, 16 | getModuleLogLevel(moduleName){ 17 | return baseService.get(`/log/${moduleName}/level`) 18 | }, 19 | setModuleLogLevel(moduleName, level){ 20 | return baseService.put(`/log/${moduleName}/level?level=${level}`) 21 | }, 22 | } -------------------------------------------------------------------------------- /northstar-monitor/src/api/loginApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | import md5 from 'js-md5' 3 | 4 | export default { 5 | login(username, password) { 6 | const salt = new Date().getTime() 7 | return baseService.post(`/auth/login?timestamp=${salt}`, { 8 | userName: username, 9 | password: md5(password + salt) 10 | }) 11 | }, 12 | logout(){ 13 | return baseService.get('/auth/logout') 14 | }, 15 | healthyCheck(){ 16 | return baseService.head(`/auth/login`) 17 | }, 18 | test() { 19 | return baseService.get('/auth/test') 20 | }, 21 | socketioPort(){ 22 | return baseService.get('/auth/socketio') 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /northstar-monitor/src/api/moduleApi.js: -------------------------------------------------------------------------------- 1 | import baseService from './baseRequest' 2 | 3 | export default { 4 | getStrategies() { 5 | return baseService.get('/module/strategies') 6 | }, 7 | componentParams(metaInfo) { 8 | return baseService.post(`/module/strategy/params`, metaInfo) 9 | }, 10 | insertModule(module) { 11 | return baseService.post('/module', module) 12 | }, 13 | updateModule(module, reset) { 14 | return baseService.put(`/module?reset=${!!reset}`, module) 15 | }, 16 | getAllModules() { 17 | return baseService.get('/module') 18 | }, 19 | toggleModuleState(name) { 20 | return baseService.get('/module/toggle?name=' + name) 21 | }, 22 | removeModule(name) { 23 | return baseService.delete('/module?name=' + name) 24 | }, 25 | getModuleRuntime(name) { 26 | return baseService.get('/module/rt/info?name=' + name) 27 | }, 28 | getModuleState(name){ 29 | return baseService.get('/module/rt/state?name=' + name) 30 | }, 31 | getModuleStatus(name){ 32 | return baseService.get('/module/rt/status?name=' + name) 33 | }, 34 | getModuleDealRecords(name) { 35 | return baseService.get('/module/deal/records?name=' + name) 36 | }, 37 | mockTradeAdjustment(moduleName, mockTrade) { 38 | return baseService.post(`/module/${moduleName}/mockTrade`, mockTrade) 39 | }, 40 | } 41 | -------------------------------------------------------------------------------- /northstar-monitor/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/src/assets/logo.png -------------------------------------------------------------------------------- /northstar-monitor/src/assets/style/config.json: -------------------------------------------------------------------------------- 1 | {"global":{"$--color-primary":"#F7C139","$--color-white":"#545C64","$--color-text-regular":"#FFFFFF","$--background-color-base":"#545C64","$--color-warning":"#F1F43C","$--color-danger":"#EE9090","$--color-success":"#93C57A","$--color-text-primary":"#FFFFFF","$--color-info":"#C2CCD2","$--border-color-extra-light":"#EFF0F1","$--border-color-lighter":"#ECEDEF","$--border-color-light":"#E0E3E7","$--border-color-base":"#D8DBE1"},"local":{}} -------------------------------------------------------------------------------- /northstar-monitor/src/assets/wx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/src/assets/wx.jpg -------------------------------------------------------------------------------- /northstar-monitor/src/assets/知识星球.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dromara/northstar/4d7f512604b901d87fae91784c10448f2f37f122/northstar-monitor/src/assets/知识星球.jpg -------------------------------------------------------------------------------- /northstar-monitor/src/components/ModulePerformancePopup.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 51 | 52 | 57 | -------------------------------------------------------------------------------- /northstar-monitor/src/components/SidePanel.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /northstar-monitor/src/filter/number-filter.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export default { 4 | accountingFormatter(val) { 5 | return val.toFixed(0).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') 6 | }, 7 | smartFormatter(val){ 8 | if(val === 0 || val === '0' || isNaN(val) || typeof val !== 'number'){ 9 | return val 10 | } 11 | let precision 12 | for(precision = 0; precision<10; precision++) { 13 | const number = val * Math.pow(10, precision) 14 | if(parseInt(number) - number === 0){ 15 | break; 16 | } 17 | } 18 | if(precision < 4){ 19 | return val.toFixed(precision) 20 | } 21 | return val.toExponential(3) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /northstar-monitor/src/lib/indicator/open-interest.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Object.defineProperty(exports, '__esModule', { 4 | value: true 5 | }) 6 | exports.default = void 0 7 | 8 | var _default = { 9 | name: 'OPI', 10 | series: 'volume', 11 | shouldCheckParamCount: false, 12 | shouldFormatBigNumber: false, 13 | plots: [ 14 | { 15 | key: 'openInterest', 16 | title: '持仓量:', 17 | type: 'bar', 18 | baseValue: 0, 19 | color: function color(data, options) { 20 | var currentData = data.current 21 | if (currentData.technicalIndicatorData.openInterestDelta > 0) { 22 | return options.bar.downColor 23 | } else if (currentData.technicalIndicatorData.openInterestDelta < 0) { 24 | return options.bar.upColor 25 | } else { 26 | return options.bar.noChangeColor 27 | } 28 | } 29 | } 30 | ], 31 | 32 | calcTechnicalIndicator: (dataList) => { 33 | return dataList.map((kLineData) => { 34 | const openInterest = kLineData.openInterest || 0 35 | return { 36 | openInterest 37 | } 38 | }) 39 | } 40 | } 41 | exports.default = _default 42 | -------------------------------------------------------------------------------- /northstar-monitor/src/lib/indicator/volume-pure.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Object.defineProperty(exports, '__esModule', { 4 | value: true 5 | }) 6 | exports.default = void 0 7 | 8 | var _default = { 9 | name: 'CJL', 10 | series: 'volume', 11 | precision: 0, 12 | shouldCheckParamCount: false, 13 | shouldFormatBigNumber: false, 14 | plots: [ 15 | { 16 | key: 'volume', 17 | title: '成交量:', 18 | type: 'bar', 19 | baseValue: 0, 20 | minValue: 0, 21 | color: function color(data, options) { 22 | var kLineData = data.current.kLineData || {} 23 | 24 | if (kLineData.close > kLineData.open) { 25 | return options.bar.upColor 26 | } else if (kLineData.close < kLineData.open) { 27 | return options.bar.downColor 28 | } 29 | return options.bar.noChangeColor 30 | } 31 | } 32 | ], 33 | calcTechnicalIndicator: (dataList) => { 34 | return dataList.map((kLineData) => { 35 | const volume = kLineData.volume || 0 36 | return { 37 | volume 38 | } 39 | }) 40 | } 41 | } 42 | exports.default = _default 43 | -------------------------------------------------------------------------------- /northstar-monitor/src/main.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | // import Vue from 'vue' 3 | // import ELEMENT from 'element-ui' 4 | import App from './App.vue' 5 | import router from './router' 6 | import store from './store' 7 | 8 | import NumberFilter from '@/filter/number-filter' 9 | import '@/assets/style/index.css' 10 | import './utils' 11 | 12 | Vue.use(ELEMENT, { size: 'mini' }) 13 | 14 | Vue.config.productionTip = false 15 | 16 | Vue.filter('accountingFormatter', NumberFilter.accountingFormatter) 17 | Vue.filter('smartFormatter', NumberFilter.smartFormatter) 18 | 19 | // 统一异常处理 20 | Vue.config.errorHandler = function (e, v) { 21 | console.warn('统一异常处理', e) 22 | ELEMENT.Message({ 23 | message: e.message || '遇到未知异常', 24 | type: 'error', 25 | duration: 5 * 1000 26 | }) 27 | if (v) { 28 | v.loading = false 29 | } 30 | console.error(e) 31 | } 32 | 33 | new Vue({ 34 | router, 35 | store, 36 | render: (h) => h(App) 37 | }).$mount('#app') 38 | -------------------------------------------------------------------------------- /northstar-monitor/src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | 4 | Vue.use(Vuex) 5 | 6 | // https://webpack.js.org/guides/dependency-management/#requirecontext 7 | const modulesFiles = require.context('./modules', true, /\.js$/) 8 | 9 | // you do not need `import app from './modules/app'` 10 | // it will auto require all vuex module from modules file 11 | const modules = modulesFiles.keys().reduce((modules, modulePath) => { 12 | // set './app.js' => 'app' 13 | const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1') 14 | const value = modulesFiles(modulePath) 15 | modules[moduleName] = value.default 16 | return modules 17 | }, {}) 18 | 19 | export default new Vuex.Store({ 20 | modules: modules 21 | }) 22 | -------------------------------------------------------------------------------- /northstar-monitor/src/store/modules/moduleInfoModule.js: -------------------------------------------------------------------------------- 1 | 2 | const moduleInfoModule = { 3 | state: () => ({ 4 | list: [] 5 | }), 6 | mutations: { 7 | updateList: (state, val) => { 8 | state.list = val 9 | } 10 | }, 11 | actions: {}, 12 | getters: { 13 | moduleList: (state) => { 14 | return state.list 15 | }, 16 | module: (state) => (moduleName) => { 17 | return state.list.find(item => item.moduleName === moduleName) 18 | } 19 | } 20 | } 21 | 22 | export default moduleInfoModule -------------------------------------------------------------------------------- /northstar-monitor/src/utils.js: -------------------------------------------------------------------------------- 1 | // 对Date的扩展,将 Date 转化为指定格式的String 2 | // 月(M)、日(d)、小时(H)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, 3 | // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 4 | // 例子: 5 | // (new Date()).Format("yyyy-MM-dd HH:mm:ss.S") ==> 2006-07-02 08:09:04.423 6 | // (new Date()).Format("yyyy-M-d H:m:s.S") ==> 2006-7-2 8:9:4.18 7 | Date.prototype.format = function(fmt) 8 | { //author: meizz 9 | var o = { 10 | "M+" : this.getMonth()+1, //月份 11 | "d+" : this.getDate(), //日 12 | "h+" : this.getHours(), //小时 13 | "m+" : this.getMinutes(), //分 14 | "s+" : this.getSeconds(), //秒 15 | "q+" : Math.floor((this.getMonth()+3)/3), //季度 16 | "S" : this.getMilliseconds() //毫秒 17 | }; 18 | if(/(y+)/.test(fmt)) 19 | fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 20 | for(var k in o) 21 | if(new RegExp("("+ k +")").test(fmt)) 22 | fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 23 | return fmt; 24 | } 25 | -------------------------------------------------------------------------------- /northstar-monitor/src/utils/file-utils.js: -------------------------------------------------------------------------------- 1 | export function downloadData(data, filename, type) { 2 | var file = new Blob(["\ufeff" + data], { type: type }); 3 | if (window.navigator.msSaveOrOpenBlob) 4 | // IE10+ 5 | window.navigator.msSaveOrOpenBlob(file, filename); 6 | else { 7 | // Others 8 | var a = document.createElement("a"), 9 | url = URL.createObjectURL(file); 10 | a.href = url; 11 | a.download = filename; 12 | document.body.appendChild(a); 13 | a.click(); 14 | setTimeout(function() { 15 | document.body.removeChild(a); 16 | window.URL.revokeObjectURL(url); 17 | }, 0); 18 | } 19 | } -------------------------------------------------------------------------------- /northstar-monitor/src/utils/media-utils.js: -------------------------------------------------------------------------------- 1 | export default class MediaListener { 2 | constructor(onResize){ 3 | if(typeof onResize !== 'function'){ 4 | throw new TypeError('期望传入一个函数') 5 | } 6 | this.eventHandler = () => { 7 | onResize() 8 | } 9 | window.addEventListener('resize', this.eventHandler) 10 | } 11 | 12 | isMobile(){ 13 | return window.matchMedia("(max-width: 660px)").matches 14 | } 15 | 16 | destroy(){ 17 | window.removeEventListener('resize', this.eventHandler) 18 | } 19 | } -------------------------------------------------------------------------------- /northstar-monitor/src/views/NotImplemented.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /northstar-monitor/startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd server 3 | nohup npm start 2>&1 >monitor.log & -------------------------------------------------------------------------------- /northstar-monitor/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // 选项... 3 | productionSourceMap: false, 4 | configureWebpack: { 5 | externals: { 6 | vue: 'Vue', 7 | 'element-ui': 'ELEMENT' 8 | } 9 | }, 10 | devServer: { 11 | port: 8090, 12 | proxy: { 13 | '/version': { 14 | target: `http://localhost` 15 | }, 16 | '/northstar': { 17 | target: `http://localhost` 18 | }, 19 | '/redirect*': { 20 | target: `http://localhost`, 21 | }, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /northstar-strategy-example/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.dromara 6 | northstar 7 | ${revision} 8 | 9 | northstar-strategy-example 10 | 11 | true 12 | 13 | 14 | 15 | org.dromara 16 | northstar-api 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | alimaven 14 | central 15 | aliyun maven 16 | http://maven.aliyun.com/nexus/content/repositories/central/ 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 启动服务 4 | nohup java -Xlog:gc*:gc.log -Xms2g -Xmx2g -Dloader.path=$(pwd) -Denv=prod -jar $(find /root/northstar-dist -name 'northstar-[0-9]*.*.jar') >/root/northstar-dist/ns.log & 5 | -------------------------------------------------------------------------------- /update-protobuf-obj.ps1: -------------------------------------------------------------------------------- 1 | # 假设本地环境已经配置好protoc 2 | $SRC_DIR="D:\workspace\northstar\northstar-api\src\main\resources\proto" 3 | $JAVA_DIR="D:\workspace\northstar\northstar-api\src\main\java" 4 | $JS_DIR="D:\workspace\northstar\northstar-monitor\src\lib" 5 | protoc --proto_path=$SRC_DIR --java_out=$JAVA_DIR --js_out=import_style=commonjs,binary:$JS_DIR $SRC_DIR/xyz/redtorch/pb/core_field.proto 6 | protoc --proto_path=$SRC_DIR --java_out=$JAVA_DIR --js_out=import_style=commonjs,binary:$JS_DIR $SRC_DIR/xyz/redtorch/pb/core_enum.proto --------------------------------------------------------------------------------