established a session
This commit is contained in:
1 parent
35a0074014
commit
7e4ad55d9d
2 files changed
+101
-4
No files matched your search
@@ -16,6 +16,14 @@ namespace bts.fix
|
||||
|
||||
public class Acceptor : QuickFix.MessageCracker, QuickFix.IApplication
|
||||
{
|
||||
static readonly decimal DEFAULT_MARKET_PRICE = 10;
|
||||
|
||||
int orderID = 0;
|
||||
int execID = 0;
|
||||
|
||||
private string GenOrderID() { return (++orderID).ToString(); }
|
||||
private string GenExecID() { return (++execID).ToString(); }
|
||||
|
||||
#region QuickFix.Application Methods
|
||||
|
||||
public void FromApp(Message message, SessionID sessionID)
|
||||
@@ -44,9 +52,98 @@ namespace bts.fix
|
||||
public void OnLogon(SessionID sessionID) { }
|
||||
#endregion
|
||||
|
||||
public void OnMessage(QuickFix.FIX42.BusinessMessageReject n, SessionID s) { }
|
||||
public void OnMessage(QuickFix.FIX43.BusinessMessageReject n, SessionID s) { }
|
||||
public void OnMessage(QuickFix.FIX44.BusinessMessageReject n, SessionID s) { }
|
||||
public void OnMessage(QuickFix.FIX50.BusinessMessageReject n, SessionID s) { }
|
||||
public void OnMessage(QuickFix.FIX44.News n, SessionID s) { }
|
||||
|
||||
public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s)
|
||||
{
|
||||
Symbol symbol = n.Symbol;
|
||||
Side side = n.Side;
|
||||
OrdType ordType = n.OrdType;
|
||||
OrderQty orderQty = n.OrderQty;
|
||||
Price price = new Price(DEFAULT_MARKET_PRICE);
|
||||
ClOrdID clOrdID = n.ClOrdID;
|
||||
|
||||
switch (ordType.getValue())
|
||||
{
|
||||
case OrdType.LIMIT:
|
||||
price = n.Price;
|
||||
if (price.Obj == 0)
|
||||
throw new IncorrectTagValue(price.Tag);
|
||||
break;
|
||||
case OrdType.MARKET: break;
|
||||
default: throw new IncorrectTagValue(ordType.Tag);
|
||||
}
|
||||
|
||||
QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport(
|
||||
new OrderID(GenOrderID()),
|
||||
new ExecID(GenExecID()),
|
||||
new ExecType(ExecType.FILL),
|
||||
new OrdStatus(OrdStatus.FILLED),
|
||||
symbol, //shouldn't be here?
|
||||
side,
|
||||
new LeavesQty(0),
|
||||
new CumQty(orderQty.getValue()),
|
||||
new AvgPx(price.getValue()));
|
||||
|
||||
exReport.Set(clOrdID);
|
||||
exReport.Set(symbol);
|
||||
exReport.Set(orderQty);
|
||||
exReport.Set(new LastQty(orderQty.getValue()));
|
||||
exReport.Set(new LastPx(price.getValue()));
|
||||
|
||||
if (n.IsSetAccount())
|
||||
exReport.SetField(n.Account);
|
||||
|
||||
try
|
||||
{
|
||||
Session.SendToTarget(exReport, s);
|
||||
}
|
||||
catch (SessionNotFound ex)
|
||||
{
|
||||
Console.WriteLine("==session not found exception!==");
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessage(QuickFix.FIX44.OrderCancelRequest msg, SessionID s)
|
||||
{
|
||||
string orderid = (msg.IsSetOrderID()) ? msg.OrderID.Obj : "unknown orderID";
|
||||
QuickFix.FIX44.OrderCancelReject ocj = new QuickFix.FIX44.OrderCancelReject(
|
||||
new OrderID(orderid), msg.ClOrdID, msg.OrigClOrdID, new OrdStatus(OrdStatus.REJECTED), new CxlRejResponseTo(CxlRejResponseTo.ORDER_CANCEL_REQUEST));
|
||||
ocj.CxlRejReason = new CxlRejReason(CxlRejReason.OTHER);
|
||||
ocj.Text = new Text("Executor does not support order cancels");
|
||||
|
||||
try
|
||||
{
|
||||
Session.SendToTarget(ocj, s);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessage(QuickFix.FIX44.OrderCancelReplaceRequest msg, SessionID s)
|
||||
{
|
||||
string orderid = (msg.IsSetOrderID()) ? msg.OrderID.Obj : "unknown orderID";
|
||||
QuickFix.FIX44.OrderCancelReject ocj = new QuickFix.FIX44.OrderCancelReject(
|
||||
new OrderID(orderid), msg.ClOrdID, msg.OrigClOrdID, new OrdStatus(OrdStatus.REJECTED), new CxlRejResponseTo(CxlRejResponseTo.ORDER_CANCEL_REPLACE_REQUEST));
|
||||
ocj.CxlRejReason = new CxlRejReason(CxlRejReason.OTHER);
|
||||
ocj.Text = new Text("Executor does not support order cancel/replaces");
|
||||
|
||||
try
|
||||
{
|
||||
Session.SendToTarget(ocj, s);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace bts
|
||||
{
|
||||
if (_acceptor)
|
||||
{
|
||||
Console.WriteLine("Starting FIX Acceptor using " + _config + " " + _http ?? string.Empty);
|
||||
Console.WriteLine("Starting FIX Acceptor using " + _config + " Http server " + _http ?? "no");
|
||||
return FixInit.start_acceptor(_config, (string.IsNullOrEmpty(_http) ? null : _http));
|
||||
}
|
||||
else if (_initiator)
|
||||
|
||||
Reference in new issue
Block a user