コード例 #1
0
ファイル: Program.cs プロジェクト: buybackoff/iFix
 public static void Main(string[] args)
 {
     try
     {
         string accessKey = "FIXME";
         string secretKey = "FIXME";
         var    ssl       = new SslOptions()
         {
             AllowExpiredCertificate = true,
             AllowPartialChain       = true,
             AllowAllErrors          = true,
         };
         var client = new Crust.Fix44.Client(
             new Crust.Fix44.ClientConfig()
         {
             SenderCompID   = accessKey,
             TargetCompID   = "BTCC-FIX-SERVER",
             Account        = accessKey,
             ReplaceEnabled = false,
             Extensions     = Crust.Fix44.Extensions.Btcc,
             SimulateFills  = true,
             SecretKey      = secretKey,
         },
             // Alternative host name: fix.btcc.com. These are different servers.
             // Both run on ap-northeast-1.compute.amazonaws.com, Asia Pacific (Tokyo).
             new TcpConnector("fix.btcchina.com", 9880, ssl));
         client.OnOrderEvent += e => _log.Info("Generated event: {0}", e);
         client.Connect().Wait();
         Thread.Sleep(10000);
         var req = new NewOrderRequest()
         {
             Symbol    = "BTCCNY",
             Side      = Side.Sell,
             Quantity  = 0.01m,
             OrderType = OrderType.Limit,
             Price     = 10000m,
         };
         _log.Warn("Sending new order");
         IOrderCtrl order = client.CreateOrder(req).Result;
         if (order == null)
         {
             throw new Exception("Null order");
         }
         while (true)
         {
             Thread.Sleep(5000);
             client.RequestMassOrderStatus("BTCCNY").Wait();
             client.RequestAccountInfo().Wait();
         }
         client.Dispose();
     }
     catch (Exception e)
     {
         _log.Fatal(e, "Unexpected exception. Terminating.");
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: romkatv/iFix
 public static void Main(string[] args)
 {
     try
     {
         // Get the keys from huobi.com.
         string accessKey = "FIXME";
         string secretKey = "FIXME";
         var ssl = new SslOptions()
         {
             AllowExpiredCertificate = true,
             AllowPartialChain = true,
             AllowAllErrors = true,
         };
         // "trade" or "market".
         string api = "trade";
         var client = new Crust.Fix44.Client(
             new Crust.Fix44.ClientConfig()
             {
                 Username = accessKey,
                 Password = secretKey,
                 SenderCompID = "market",
                 TargetCompID = "server",
                 Account = accessKey,
                 ReplaceEnabled = false,
                 // Huobi supports two symbols: btc and ltc.
                 // You can spell them as btccny and btc/cny if you want.
                 // It's the same when sending order requests.
                 MarketDataSymbols = api == "trade" ? null : new List<string> { "btc" },
                 Extensions = Crust.Fix44.Extensions.Huobi,
                 SimulateFills = true,
             },
             // One end-point for market data, another for trading.
             new TcpConnector("106.38.234.75", api == "trade" ? 5001 : 5000, ssl));
         client.OnOrderEvent += e => _log.Info("Generated event: {0}", e);
         client.Connect().Wait();
         if (api == "trade")
         {
             Thread.Sleep(5000);
             var req = new NewOrderRequest()
             {
                 Symbol = "btc",
                 Side = Side.Buy,
                 Quantity = 0.001m,
                 OrderType = OrderType.Limit,
                 Price = 7400.00m,
             };
             _log.Warn("Sending new order");
             IOrderCtrl order = client.CreateOrder(req).Result;
             if (order == null) throw new Exception("Null order");
             Thread.Sleep(3000);
             _log.Warn("Requesting status");
             order.RequestStatus().Wait();
             Thread.Sleep(3000);
             _log.Warn("Cancelling");
             order.Cancel().Wait();
             Thread.Sleep(3000);
             _log.Warn("Requesting status");
             order.RequestStatus().Wait();
         }
         while (true) Thread.Sleep(2000);
         client.Dispose();
     }
     catch (Exception e)
     {
         _log.Fatal(e, "Unexpected exception. Terminating.");
     }
 }