`
seafront12
  • 浏览: 4642 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
文章分类
社区版块
存档分类
最新评论

FIX with JDBC Storage: Test Code quickfixj

阅读更多
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 Starter

    QuickFIXJ-Spring-Boot-Starter是专门为整合QuickFIXJ与Spring Boot设计的启动器,旨在简化在Java环境中使用QuickFIXJ进行金融 FIX(Financial Information eXchange)协议通信的过程。FIX协议是一种广泛用于金融...

    quickfixj-spring-boot-starter:QuickFixJ Spring Boot启动器

    QuickFixJ是一个开源项目,用于处理FIX(Financial Information eXchange)协议,这是一种广泛用于金融机构之间实时交易消息交换的标准格式。 QuickFixJ的核心功能包括: 1. **FIX消息解析与生成**:QuickFixJ能够...

    source insight 4.0.0089

    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源码

    QuickFixJ是一款开源的、基于Java实现的金融消息协议(Financial Information eXchange,FIX)引擎,它使得在金融机构之间交换FIX格式的消息变得更加便捷。FIX协议是金融行业中广泛使用的通信标准,用于实时交易和...

    quickfixj:QuickFIXJ是用于FIX协议的全功能消息传递引擎。 -这是官方项目资料库

    QuickFIX / J 这是官方的QuickFIX / J项目存储库。介绍QuickFIX / J是用于FIX协议(FIX版本4.0-5.0SP2 / FIXT1.1)的全功能消息传递引擎。 它是流行的C ++ QuickFIX引擎的100%Java开源实现。 金融信息交换(FIX)...

    QuickFix 实现代码例子

    QuickFix 是一个开源的金融信息交换(FIX)协议实现库,专为交易系统设计,用于高效、可靠地传输证券和衍生品交易相关的数据。FIX 协议是一种国际标准,广泛应用于金融机构之间,包括股票、债券、期货、期权等各种...

    delphi 2007 第三方补丁

    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 ...

    quickfixj-2.2.0.zip

    QuickFIX/J 2.2.0 是一个针对金融行业的开源消息引擎,专门处理基于FIX(Financial Information eXchange)协议的数据交换。FIX协议是全球金融市场广泛采用的标准,用于在金融机构之间传输交易和市场数据。QuickFIX/...

    Jam.ShellBrowser.8.1.2.2013-03-06

    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

    Software Design X-Rays Fix Technical Debt with Behavioral Code Analysis 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Ruby Performance Optimization, Why Ruby is Slow, and How to Fix It

    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 最新驱动:

    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简介.pdf

    Proficy HMI/SCADA iFIX 3.5 with FIX Desktop是GE Fanuc自动化推出的一款集成化的人机界面/监控和数据采集(HMI/SCADA)软件。该软件在Proficy HMI/SCADA-iFIX的基础上加入了FIX(现场信息交换)桌面操作员界面环境...

    sourceinsight4087

    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 ...

    NGUI Next-Gen UI 3.9.1

    - 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:...

    fix-utf8:修复Unicode编码错误

    修复utf8 根据,尽最大努力恢复丢失的...$ npm install fix-utf8 如何 const fixUtf8 = require ( 'fix-utf8' ) fixUtf8 ( "L'avenir des idÃ:copyright:es" ) // => "L'avenir des idées" 也可以看看 (PHP) 执照

    sciter-js-sdk-4.4.8.10.zip

    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 ...

    Pngd ie6下透明的解决方案

    文件:test_iepngfix iepngfix.js是另一个JavaScript解决方案,专门用于修复IE6下的PNG透明问题。它使用滤镜技术来实现透明效果。在页面头部引入该脚本,然后对需要透明效果的PNG图像应用特定的CSS类,如`class="png...

    IDEFixPack 5.91 for Delphi 2009,2010,XE,XE2,XE3,XE4,XE5,XE6,XE7,XE8

    - 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 ...

Global site tag (gtag.js) - Google Analytics