Package org.knowm.xchange.simulated
Class SimulatedExchange
java.lang.Object
org.knowm.xchange.BaseExchange
org.knowm.xchange.simulated.SimulatedExchange
- All Implemented Interfaces:
Exchange
A simple, in-memory implementation which mocks out the main elements of the XChange generic API
in a consistent way. The effect is to create a virtual "exchange" that you can connect to from
multiple threads and simulate a real exchange. Intended for integration testing of higher order
components.
This is not remotely suitable for use as a real-world exchange. The concurrency is extremely coarse-grained and most data transforms involve data mutation with no . If any errors occur midway through a trade, they are likely to leave the system in an inconsistent state. And nothing gets saved to a database anyway.
If you start using this for running a real exchange, you will suffer a stolen.
- Author:
- Graham Crockford
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAs withENGINE_FACTORY_PARAM, provides a default unshared but optionally shared instance ofAccountFactory.static final StringAllows the scope of the simulated exchange to be controlled.static final StringProvides aSimulatedExchangeOperationListener.Fields inherited from class org.knowm.xchange.BaseExchange
accountService, exchangeMetaData, exchangeSpecification, logger, marketDataService, tradeServiceFields inherited from interface org.knowm.xchange.Exchange
USE_SANDBOX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsi.mazi.rescu.SynchronizedValueFactory<Long>protected voidvoidMethods inherited from class org.knowm.xchange.BaseExchange
applySpecification, getExchangeInstruments, getExchangeMetaData, getExchangeSpecification, getMetaDataFileName, loadExchangeMetaData, loadMetaData, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.knowm.xchange.Exchange
getResilienceRegistries
-
Field Details
-
ENGINE_FACTORY_PARAM
Allows the scope of the simulated exchange to be controlled. Pass toExchangeSpecification.setExchangeSpecificParametersItem(String, Object)to choose one of:new MatchingEngineFactory()- default. Each instance ofSimulatedExchangeworks on a different virtual exchange with its own set of order books, thus the simulated exchange is single-user. Recommended for unit testing.- An existing, shared instance of
MatchingEngineFactory- Create your own factory and share it betweenSimulatedExchangeinstances to allow those specific instances to share the same order books and thus trade against each other. Recommended for integration testing.
- See Also:
-
ACCOUNT_FACTORY_PARAM
As withENGINE_FACTORY_PARAM, provides a default unshared but optionally shared instance ofAccountFactory.- See Also:
-
ON_OPERATION_PARAM
Provides aSimulatedExchangeOperationListener.- See Also:
-
-
Constructor Details
-
SimulatedExchange
public SimulatedExchange()
-
-
Method Details
-
getNonceFactory
- Specified by:
getNonceFactoryin interfaceExchange- Overrides:
getNonceFactoryin classBaseExchange
-
getDefaultExchangeSpecification
-
initServices
protected void initServices()- Specified by:
initServicesin classBaseExchange
-
remoteInit
- Specified by:
remoteInitin interfaceExchange- Overrides:
remoteInitin classBaseExchange- Throws:
IOExceptionExchangeException
-
getMarketDataService
- Specified by:
getMarketDataServicein interfaceExchange- Overrides:
getMarketDataServicein classBaseExchange
-
getAccountService
- Specified by:
getAccountServicein interfaceExchange- Overrides:
getAccountServicein classBaseExchange
-
getTradeService
- Specified by:
getTradeServicein interfaceExchange- Overrides:
getTradeServicein classBaseExchange
-