import org.junit.Before;
import org.junit.Test;
import quickfix.ConfigError;
import quickfix.FieldConvertError;
import quickfix.StringField;
import quickfix.field.Account;
import quickfix.field.ClOrdID;
import quickfix.field.CumQty;
import quickfix.field.Currency;
import quickfix.field.ExecID;
import quickfix.field.ExecInst;
import quickfix.field.ExecType;
import quickfix.field.HandlInst;
import quickfix.field.LeavesQty;
import quickfix.field.OrdStatus;
import quickfix.field.OrdType;
import quickfix.field.OrderID;
import quickfix.field.OrderQty;
import quickfix.field.OrigClOrdID;
import quickfix.field.PartyID;
import quickfix.field.Product;
import quickfix.field.SecurityType;
import quickfix.field.SettlType;
import quickfix.field.Side;
import quickfix.field.Symbol;
import quickfix.field.Text;
import quickfix.field.TransactTime;
import quickfix.fix50.ExecutionReport;
import quickfix.fix50.NewOrderSingle;
import quickfix.fix50.OrderCancelRequest;
import quickfix.fix50.component.Parties;
import scaffolding.com.hsbc.efx.fog.io.FixClient;
import scaffolding.com.hsbc.efx.fog.poller.Poller;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class AcceptorFailOverTest {
private final Date someDateTime = Date.from(LocalDateTime.of(2016, 1, 2, 5, 34, 54).toInstant(ZoneOffset.UTC));
private SingleSessionFixAcceptorApplication acceptor1;
private SingleSessionFixAcceptorApplication acceptor2;
private Poller poller = new Poller(10000, 100);
private Poller poller2 = new Poller(10000, 100);
private FixClient fixClient;
@Before
public void setUp() throws ConfigError, InterruptedException, FieldConvertError {
Config config1 = mock(Config.class, "1");
Config config2 = mock(Config.class, "2");
when(config1.fixSettingsFile()).thenReturn("acceptor1.ini");
when(config2.fixSettingsFile()).thenReturn("acceptor2.ini");
acceptor1 = new SingleSessionFixAcceptorApplication(config1, message -> {
if(message instanceof NewOrderSingle) {
ExecutionReport execRpt = new ExecutionReport(new OrderID("1"), new ExecID("1-1"), new ExecType(ExecType.NEW), new OrdStatus(OrdStatus.NEW), new Side(Side.BUY), new LeavesQty(0d), new CumQty(0d));
execRpt.setField(new ClOrdID("some_id"));
acceptor1.send(execRpt);
System.out.println("+++++++++++++sending Exec Rpt+++++++++++++++++");
}
}, mock(ApplicationEvents.class, "1"), new FixConnectionListener() {
public void onConnect() {
}
public void onDisconnect() {
}
});
acceptor2 = new SingleSessionFixAcceptorApplication(config2, message -> {
if(message instanceof OrderCancelRequest){
ExecutionReport execRpt = new ExecutionReport(new OrderID("1"), new ExecID("1-2"), new ExecType(ExecType.CANCELED), new OrdStatus(OrdStatus.CANCELED), new Side(Side.BUY), new LeavesQty(0d), new CumQty(0d));
acceptor2.send(execRpt);
}
}, mock(ApplicationEvents.class, "2"), new FixConnectionListener() {
public void onConnect() {
}
public void onDisconnect() {
}
});
acceptor1.enableLatch(false);
acceptor2.enableLatch(false);
acceptor1.start();
//Have to start the client first, as the fixIO service is blocked until a client connects
fixClient = new FixClient("sender-failover.ini", true);
fixClient.start();
}
@Test
public void name() throws InterruptedException {
NewOrderSingle newOrderSingle = new NewOrderSingle();
newOrderSingle.set(new ClOrdID("some_id"));
Parties.NoPartyIDs noPartyIDs = new Parties.NoPartyIDs();
noPartyIDs.set(new PartyID("SomeClient"));
newOrderSingle.addGroup(noPartyIDs);
newOrderSingle.set(new Account("SomeAccount"));
newOrderSingle.set(new SettlType("SPT"));
newOrderSingle.set(new ExecInst("G"));
newOrderSingle.set(new HandlInst('1'));
newOrderSingle.set(new Symbol("EUR/USD"));
newOrderSingle.set(new Product(4));
newOrderSingle.set(new SecurityType("FXSPOT"));
newOrderSingle.set(new Side('1'));
newOrderSingle.set(new TransactTime(someDateTime));
newOrderSingle.set(new OrderQty(2_000_000));
newOrderSingle.set(new OrdType('Z'));
newOrderSingle.set(new Currency("EUR"));
newOrderSingle.setField(new StringField(9103, "WM"));
newOrderSingle.setField(new StringField(9105, "16:00"));
newOrderSingle.setField(new StringField(9106, "20160512"));
newOrderSingle.set(new Text("comment"));
fixClient.sendMessage(newOrderSingle);
poller.assertEventually(() -> {
assertThat(fixClient.receivedMsgs(), hasSize(1));
assertTrue(fixClient.receivedMsgs().get(0) instanceof ExecutionReport);
acceptor1.stop();
System.out.println("Acceptor1 stopped");
acceptor2.start();
System.out.println("Acceptor2 started");
Thread.sleep(6000);
System.out.println("Sending cancel request");
OrderCancelRequest cancelRequest = new OrderCancelRequest(new OrigClOrdID("some_id"), new ClOrdID("some_id-cxl"), new Side(Side.BUY), new TransactTime(new Date()));
cancelRequest.set(new OrderQty(2_000_000));
fixClient.sendMessage(cancelRequest);
poller2.assertEventually(()->{
assertThat(fixClient.receivedMsgs, hasSize(2));
assertTrue(fixClient.receivedMsgs().get(1) instanceof ExecutionReport);
});
});
}
}
分享到:
相关推荐
QuickFIXJ-Spring-Boot-Starter是专门为整合QuickFIXJ与Spring Boot设计的启动器,旨在简化在Java环境中使用QuickFIXJ进行金融 FIX(Financial Information eXchange)协议通信的过程。FIX协议是一种广泛用于金融...
QuickFixJ是一个开源项目,用于处理FIX(Financial Information eXchange)协议,这是一种广泛用于金融机构之间实时交易消息交换的标准格式。 QuickFixJ的核心功能包括: 1. **FIX消息解析与生成**:QuickFixJ能够...
2018年1月26日更新: Fix: Macro event DocumentChanged was not ...Fix: Search Results: Incorrect codepage might be used to display results for some searches using Lookup References and Search Files.
QuickFixJ是一款开源的、基于Java实现的金融消息协议(Financial Information eXchange,FIX)引擎,它使得在金融机构之间交换FIX格式的消息变得更加便捷。FIX协议是金融行业中广泛使用的通信标准,用于实时交易和...
QuickFIX / J 这是官方的QuickFIX / J项目存储库。介绍QuickFIX / J是用于FIX协议(FIX版本4.0-5.0SP2 / FIXT1.1)的全功能消息传递引擎。 它是流行的C ++ QuickFIX引擎的100%Java开源实现。 金融信息交换(FIX)...
QuickFix 是一个开源的金融信息交换(FIX)协议实现库,专为交易系统设计,用于高效、可靠地传输证券和衍生品交易相关的数据。FIX 协议是一种国际标准,广泛应用于金融机构之间,包括股票、债券、期货、期权等各种...
Added: Fix for Find dialog has problems with Umlaut chars Removed: CodeCompletion is fixed in RAD Studio 2007 April Update 2008-04-02: Added: Added fix for TCustomActionList.Notification memory ...
QuickFIX/J 2.2.0 是一个针对金融行业的开源消息引擎,专门处理基于FIX(Financial Information eXchange)协议的数据交换。FIX协议是全球金融市场广泛采用的标准,用于在金融机构之间传输交易和市场数据。QuickFIX/...
Interesting sample projects and a help file with a lot of sample code are included. V8.1.2 Released on 28 Feb 2013 Bugfix - JamFileList: When using the Search method, sorting distinguishes between...
Software Design X-Rays Fix Technical Debt with Behavioral Code Analysis 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
See exactly what makes Ruby and Rails code slow, and how to fix it. Alex Dymo will guide you through perils of memory and CPU optimization, profiling, measuring, performance testing, garbage ...
SAP Sybase ASE 16 JDBC 最新驱动. 要让你的程序保持与Server最新兼容,可以使用这个driver. 有很多Bug fix 在里边。 jconn4-16.0.03.11.30030.jar
Proficy HMI/SCADA iFIX 3.5 with FIX Desktop是GE Fanuc自动化推出的一款集成化的人机界面/监控和数据采集(HMI/SCADA)软件。该软件在Proficy HMI/SCADA-iFIX的基础上加入了FIX(现场信息交换)桌面操作员界面环境...
Fix: C/C++ Source File: added *.hh file association Fix: Project > Add and Remove Project Files - fixed keyboard short cut in prompt to add top level sub-directories. Fix: Crash could happen when ...
- FIX: Alpha should now work as expected with Linear lighting. - FIX: UICamera.isOverUI should now work properly for all types of input. - FIX: NGUIEditorTools.DrawProperty can now draw arrays. - FIX:...
修复utf8 根据,尽最大努力恢复丢失的...$ npm install fix-utf8 如何 const fixUtf8 = require ( 'fix-utf8' ) fixUtf8 ( "L'avenir des idÃ:copyright:es" ) // => "L'avenir des idées" 也可以看看 (PHP) 执照
WM_INPUT handling fix (might causing non-handled exceptions); Windows: UIAutomation support is back, but requres SciterSetOption(NULL,SCITER_ENABLE_UIAUTOMATION,TRUE); env.home(path) - returns ...
文件:test_iepngfix iepngfix.js是另一个JavaScript解决方案,专门用于修复IE6下的PNG透明问题。它使用滤镜技术来实现透明效果。在页面头部引入该脚本,然后对需要透明效果的PNG图像应用特定的CSS类,如`class="png...
- Fixed: IDEFixPack didn't take into account that DB.TFlatList uses late loading through GetCount - Fixed: fastdcc32/64/aarm in XE7 and XE8 didn't load the CompilerSpeedPack into the compiler's ...