private void CmdReport(int type, string id, string connect) { try { //特殊消息处理 switch (type) { case FixApplication.msgTypeLogin: CmdCallBack( string.Format( string.Format(MsgFmt, "Fix", "OE", "-1", CmdRequestUserLogin, CmdPostfix), string.Empty)); return; case FixApplication.msgTypeLogout: CmdCallBack( string.Format( string.Format(MsgFmt, "Fix", "OE", "-1", CmdRequestUserLogout, CmdPostfix), string.Empty)); return; } //普通异步消息,将保存在内存的消息头与消息体结合回报即可 CmdCallBack(string.Format(dictID[id], connect)); } catch (Exception ex) { //如果内存中没有对应消息体的消息头,则只回报消息体 CmdCallBack(connect); Fix.Out(ex.ToString()); } }
private string CancelOrder(bool isbuy, string symbol, string id) { var co = MessageFactory.OrderCancelRequest(TradingSession()); var future = string.Empty; var contract = string.Empty; var maturity = string.Empty; var exchange = string.Empty; if (co == null || !SplitSymbol(symbol, ref future, ref contract, ref maturity, ref exchange)) { return(string.Empty); } var ClOrdID = AllocClOrdID(symbol); var buy = isbuy ? SideBuy : SideSell; Fix.Out("tag 11 : ClOrdID = " + ClOrdID); co.setField(11, ClOrdID); Fix.Out("tag41 : OrigClOrdID = " + id); co.setField(41, id); Fix.Out("tag54 : Side(1=buy,2=sell) = " + buy); co.setField(54, buy); Fix.Out("tag55 : Symbol = " + contract); co.setField(55, contract); co.setField(60, GetTimeString()); Fix.Out("tag1 : Account = " + Account.account); co.setField(1, Account.account); return(SendMessageToSession(co) ? ClOrdID : string.Empty); }
//同上 internal bool Add(string status, string symbol, int qty, string price, string clientID) { if (string.IsNullOrEmpty(symbol) || string.IsNullOrEmpty(price) || string.IsNullOrEmpty(clientID) || qty == 0) { return(false); } try { if (!ufos.ContainsKey(clientID)) { ufos.Add(clientID, new UFO(symbol, qty, price, status)); } var s = string.Format("SendOrder # ClientOrderID: {0} # T:{1} # S:{2} # P:{3} # Q:{4}", clientID, symbol, status, price, qty); Fix.Out(s); return(true); } catch (Exception) { return(false); } }
private static void fillFixMessageStructure(Dictionary <EFixTags, string> tagMap, ref QuickFix.Message fixMessage) { foreach (KeyValuePair <EFixTags, string> kvp in tagMap) { Fix.Out(string.Format("Tag {0}: {1}={2}", (int)kvp.Key, kvp.Key.ToString(), kvp.Value)); fixMessage.setField((int)kvp.Key, kvp.Value); } }
protected virtual string AllocClOrdID(string symbol) { lock (lockObj) { var id = ++lastClOrdID; var str = id.ToString(); SaveSymbol(str, symbol); Fix.Out("Last Client Order ID : " + str); return(str); } }
//登录成功 public void onLogon(SessionID sessionID) { Fix.Out("Logon"); sessionList.Remove(sessionID); sessionList.Add(sessionID); if (sessionList.Count == 1) { FixReport(msgTypeLogin, null, 0, string.Empty); } }
internal void Remove(string clientID) { try { ufos.Remove(clientID); Fix.Out(string.Format("RemoveOrder # ClientOrderID: {0}", clientID)); } catch (Exception ex) { Fix.Out(ex.ToString()); } }
//返回成交列表 internal void GetUnFillOrders() { try { foreach (var ufo in ufos) { var s = string.Format("ClientOrderID: {0} # T:{1} # S:{2} # P:{3} # Q:{4}", ufo.Key, ufo.Value.Symbol, ufo.Value.Status, ufo.Value.Price, ufo.Value.Qty); Fix.Out(s); } } catch (Exception) {} }
private string QueryOrder(bool isbuy, string symbol, string id) { var qo = MessageFactory.OrderStatusRequest(TradingSession()); if (qo == null) { return(string.Empty); } var ClOrdID = AllocClOrdID(symbol); var buy = isbuy ? SideBuy : SideSell; Fix.Out("tag11 : OrderID = " + id); qo.setField(11, id); Fix.Out("tag54 : Side(1=buy,2=sell) = " + buy); qo.setField(54, buy); Fix.Out("tag55 : Symbol = " + symbol); qo.setField(55, symbol); return(SendMessageToSession(qo) ? ClOrdID : string.Empty); }
private string SendNewOrder(bool isbuy, bool isopen, string symbol, string price, string qty) { var sno = MessageFactory.NewOrderSingle(TradingSession()); var future = string.Empty; var contract = string.Empty; var maturity = string.Empty; var exchange = string.Empty; if (sno == null || !SplitSymbol(symbol, ref future, ref contract, ref maturity, ref exchange)) { return(string.Empty); } var ClOrdID = AllocClOrdID(symbol); var open = isopen ? "O" : "C"; var buy = isbuy ? SideBuy : SideSell; sno.setField(1, Account.account); sno.setField(109, Account.clientid); Fix.Out("tag207 : SecurityExchange = " + exchange); sno.setField(207, exchange); Fix.Out("tag 77 : OpenClose = " + open); sno.setField(77, open); Fix.Out("tag 11 : ClOrdID = " + ClOrdID); sno.setField(11, ClOrdID); Fix.Out("tag40 : OrdType = 2(Limit)"); sno.setField(40, "2"); Fix.Out("tag54 : side(1=buy,2=sell) = " + buy); sno.setField(54, buy); sno.setField(21, "1"); Fix.Out("tag55 : Symbol = " + contract); sno.setField(55, contract); Fix.Out("tag38 : OrderQty = " + qty); sno.setField(38, qty); Fix.Out("tag44 : Price = " + price); sno.setField(44, price); sno.setField(60, GetTimeString()); return(SendMessageToSession(sno) ? ClOrdID : string.Empty); }
internal static void GetAccountInfo(SessionSettings ss) { foreach (var session in ss.getSessions()) { var dict = ss.get(session as SessionID); target = dict.getString("TargetCompID"); var dst = dict.getString("TargetCompID") + " : " + dict.getString("SocketConnectHost") + " : " + dict.getString("SocketConnectPort"); Fix.Out(dst); var acc = dict.getString("Account"); var cid = dict.getString("ClientID"); if (!string.IsNullOrEmpty(acc) && !string.IsNullOrEmpty(cid)) { account = acc; clientid = cid; } Fix.Out(Account.account + " / " + Account.clientid + "\n"); } }
public sealed override void onMessage(QuickFix43.OrderMassCancelRequest message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
//从网关返回的应用消息 public void fromApp(QuickFix.Message message, SessionID sessionID) { crack(message, sessionID); Fix.Out(message); }
//发送应用消息到网关(比如下单,撤单,查询相关消息等) public void toApp(QuickFix.Message message, SessionID sessionID) { Fix.Out(message); }
public sealed override void onMessage(QuickFix42.MarketDataRequestReject message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix42.IndicationofInterest message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.DerivativeSecurityList message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix42.SequenceReset message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.TradeCaptureReportRequest message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.TradingSessionStatus message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.SettlementInstructions message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.SecurityDefinitionRequest message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.MarketDataSnapshotFullRefresh message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.MassQuoteAcknowledgement message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.NewOrderMultileg message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); }
public sealed override void onMessage(QuickFix43.Reject message, SessionID session) { Fix.Out(new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().ToString()); MsgReject(message, session); }
static void Main(string[] args) { var cp = Process.GetCurrentProcess().MainModule.FileName; Directory.SetCurrentDirectory(Path.GetDirectoryName(cp)); try { var fe = new FixExecutor(); fe.AddCallBack(Om); fe.AddCallBack(Om); fe.Start(@"E:\FixEngine\FixEngine\myserver.cfg"); for ( ; ;) { Console.WriteLine("quit stop goon buy sell cbuy csell qbuy qsell?"); var cmd = Console.ReadLine();//.ToLower(); if ("quit" == cmd) { break; } Console.WriteLine(fe.DealCommand(cmd)); if ("buy" == cmd) { var open = Console.ReadLine(); if (open == "open" || open == "close") { // application.SendNewOrder(true, open == "open", "cffe", "IF1112", Console.ReadLine(), Console.ReadLine()); } } else if ("sell" == cmd) { var open = Console.ReadLine(); if (open == "open" || open == "close") { // application.SendNewOrder(false, open == "open", "cffe", "IF1112", Console.ReadLine(), Console.ReadLine()); } } else if ("cbuy" == cmd) { // application.CancelOrder(true, "IF1112", Console.ReadLine()); } else if ("csell" == cmd) { // application.CancelOrder(false, "IF1112", Console.ReadLine()); } else if ("qbuy" == cmd) { // application.QueryOrder(true, "IF1112", Console.ReadLine()); } else if ("qsell" == cmd) { // application.QueryOrder(false, "IF1112", Console.ReadLine()); } } fe.Stop(); Console.ReadLine(); } catch (Exception e) { Fix.Out(e.ToString()); Console.ReadLine(); } finally { Fix.Out("AtExit"); } }