コード例 #1
0
ファイル: Program.cs プロジェクト: handayu/FTAPI-3.20.1
        static void Main(string[] args)
        {
            //API初始化
            FTAPI.Init();

            //FTAPI_Qot client = new FTAPI_Qot();
            //client.SetConnCallback(new SampleConnCallback());
            //client.SetQotCallback(new SampleQotCallback());
            //client.SetClientInfo("FTAPI4NET_Sample", 1);
            ////client.SetRSAPrivateKey(System.IO.File.ReadAllText(@"d:\rsa1024", Encoding.UTF8));
            //client.InitConnect("127.0.0.1", 11111, false);

            //交易API初始化
            FTAPI_Trd trd = new FTAPI_Trd();

            //注册连接回调
            trd.SetConnCallback(new SampleTrdConnCallback());

            //注册交易回调
            trd.SetTrdCallback(new SampleTrdCallback());

            //设置Clint信息
            trd.SetClientInfo("FTAPI4NET_Sample", 1);

            //开始链接
            trd.InitConnect("127.0.0.1", 11111, false);

            while (true)
            {
                Thread.Sleep(1000 * 60);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: zenchanhk/FTAPI4NET
        static void Main(string[] args)
        {
            FTAPI.Init();
            FTAPI_Qot client = new FTAPI_Qot();

            client.SetConnCallback(new SampleConnCallback());
            client.SetQotCallback(new SampleQotCallback());
            client.SetClientInfo("FTAPI4NET_Sample", 1);
            //client.SetRSAPrivateKey(System.IO.File.ReadAllText(@"d:\rsa1024", Encoding.UTF8));
            client.InitConnect("127.0.0.1", 11111, false);

            FTAPI_Trd trd = new FTAPI_Trd();

            trd.SetConnCallback(new SampleTrdConnCallback());
            trd.SetTrdCallback(new SampleTrdCallback());
            trd.SetClientInfo("FTAPI4NET_Sample", 1);
            trd.InitConnect("127.0.0.1", 11111, false);

            /*
             * FTClient client = new FTClient("127.0.0.1", 11111);
             * client.QotConnCallback.InitConnected += QotConnCallback_InitConnected;
             * client.QotConnCallback.Disconnected += QotConnCallback_Disconnected;
             * client.Connect();
             */

            while (true)
            {
                Thread.Sleep(1000);
                //client.Close();
                //client.Dispose();
                Thread.Sleep(1000 * 200);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: sokolovsa/StockSharp.FTAPI
 public void OnInitConnect(FTAPI_Conn client, long errCode, string desc)
 {
     Console.WriteLine("InitConnected");
     if (errCode == 0)
     {
         FTAPI_Trd trd = client as FTAPI_Trd;
         {
             TrdGetAccList.Request req = TrdGetAccList.Request.CreateBuilder().SetC2S(TrdGetAccList.C2S.CreateBuilder().SetUserID(0)).Build();
             uint serialNo             = trd.GetAccList(req);
             Console.WriteLine("Send GetAccList: {0}", serialNo);
         }
     }
 }
コード例 #4
0
 public void OnInitConnect(FTAPI_Conn client, long errCode, string desc)
 {
     SafeRaiseEvent("InitConnected");
     if (errCode == 0)
     {
         FTAPI_Trd trd = client as FTAPI_Trd;
         {
             //传入Trd,Connect连接成功,发送获取账户
             TrdGetAccList.Request req = TrdGetAccList.Request.CreateBuilder().SetC2S(TrdGetAccList.C2S.CreateBuilder().SetUserID(0)).Build();
             uint serialNo             = trd.GetAccList(req);
             SafeRaiseEvent(string.Format("Send GetAccList: {0}", serialNo));
             SafeRaiseEvent("ConnectedSuccessed");
         }
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: handayu/FTAPI-3.20.1
 public void OnReply_GetAccList(FTAPI_Conn client, int nSerialNo, TrdGetAccList.Response rsp)
 {
     Console.WriteLine("Recv GetAccList: {0} {1}", nSerialNo, rsp);
     if (rsp.RetType != (int)Common.RetType.RetType_Succeed)
     {
         Console.WriteLine("error code is {0}", rsp.RetMsg);
     }
     else
     {
         this.accID = rsp.S2C.AccListList[1].AccID;
         FTAPI_Trd trd              = client as FTAPI_Trd;
         MD5       md5              = MD5.Create();
         byte[]    encryptionBytes  = md5.ComputeHash(Encoding.UTF8.GetBytes("196910"));
         string    unlockPwdMd5     = BitConverter.ToString(encryptionBytes).Replace("-", "").ToLower();
         TrdUnlockTrade.Request req = TrdUnlockTrade.Request.CreateBuilder().SetC2S(TrdUnlockTrade.C2S.CreateBuilder().SetUnlock(true).SetPwdMD5(unlockPwdMd5)).Build();
         uint serialNo              = trd.UnlockTrade(req);
         Console.WriteLine("Send UnlockTrade: {0}", serialNo);
     }
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: handayu/FTAPI-3.20.1
            public void OnReply_UnlockTrade(FTAPI_Conn client, int nSerialNo, TrdUnlockTrade.Response rsp)
            {
                Console.WriteLine("Recv UnlockTrade: {0} {1}", nSerialNo, rsp);
                if (rsp.RetType != (int)Common.RetType.RetType_Succeed)
                {
                    Console.WriteLine("error code is {0}", rsp.RetMsg);
                }
                else
                {
                    FTAPI_Trd trd = client as FTAPI_Trd;

                    TrdPlaceOrder.Request.Builder req       = TrdPlaceOrder.Request.CreateBuilder();
                    TrdPlaceOrder.C2S.Builder     cs        = TrdPlaceOrder.C2S.CreateBuilder();
                    Common.PacketID.Builder       packetID  = Common.PacketID.CreateBuilder().SetConnID(trd.GetConnectID()).SetSerialNo(0);
                    TrdCommon.TrdHeader.Builder   trdHeader = TrdCommon.TrdHeader.CreateBuilder().SetAccID(this.accID).SetTrdEnv((int)TrdCommon.TrdEnv.TrdEnv_Real).SetTrdMarket((int)TrdCommon.TrdMarket.TrdMarket_US);
                    cs.SetPacketID(packetID).SetHeader(trdHeader).SetTrdSide((int)TrdCommon.TrdSide.TrdSide_Sell).SetOrderType((int)TrdCommon.OrderType.OrderType_Market).SetCode("AAPL").SetQty(100.00).SetPrice(10.2).SetAdjustPrice(true);
                    req.SetC2S(cs);

                    uint serialNo = trd.PlaceOrder(req.Build());
                    Console.WriteLine("Send PlaceOrder: {0}, {1}", serialNo, req);
                }
            }
コード例 #7
0
        private void Button1_Click(object sender, EventArgs e)
        {
            //API初始化
            FTAPI.Init();

            AppendLogInfo("Begin login op...");

            //交易API初始化
            trd = new FTAPI_Trd();

            //注册连接回调
            trd.SetConnCallback(m_stcon);

            //注册交易回调
            trd.SetTrdCallback(m_st);

            //设置Clint信息
            trd.SetClientInfo("FTAPI4NET_Sample", 1);

            //开始链接
            trd.InitConnect("127.0.0.1", 11111, false);
        }