本文整理汇总了C#中O2GSession类的典型用法代码示例。如果您正苦于以下问题:C# O2GSession类的具体用法?C# O2GSession怎么用?C# O2GSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
O2GSession类属于命名空间,在下文中一共展示了O2GSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateELSRequest
/// <summary>
/// Create entry order with attached stop and limit orders request
/// </summary>
private static O2GRequest CreateELSRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRate, double dRateLimit, double dRateStop, string sBuySell, string sOrderType)
{
O2GRequest request = null;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GValueMap valuemap = requestFactory.createValueMap();
valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
valuemap.setString(O2GRequestParamsEnum.OrderType, sOrderType);
valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID);
valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell);
valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount);
valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate);
valuemap.setDouble(O2GRequestParamsEnum.RateLimit, dRateLimit);
valuemap.setDouble(O2GRequestParamsEnum.RateStop, dRateStop);
valuemap.setString(O2GRequestParamsEnum.CustomID, "EntryOrderWithStopLimit");
request = requestFactory.createOrderRequest(valuemap);
if (request == null)
{
Console.WriteLine(requestFactory.getLastError());
}
return request;
}
示例2: ResponseListener
/// <summary>
/// ctor
/// </summary>
/// <param name="session"></param>
public ResponseListener(O2GSession session)
{
mRequestID = string.Empty;
mResponse = null;
mSyncResponseEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
mSession = session;
}
示例3: IsOrderExists
/// <summary>
/// Check if order exists
/// </summary>
/// <param name="session"></param>
/// <param name="sAccountID"></param>
/// <param name="sOrderID"></param>
/// <param name="responseListener"></param>
/// <returns></returns>
private static bool IsOrderExists(O2GSession session, string sAccountID, string sOrderID, ResponseListener responseListener)
{
bool bHasOrder = false;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Orders, sAccountID);
if (request == null)
{
throw new Exception("Cannot create request");
}
responseListener.SetRequestID(request.RequestID);
session.sendRequest(request);
if (!responseListener.WaitEvents())
{
throw new Exception("Response waiting timeout expired");
}
O2GResponse response = responseListener.GetResponse();
O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory();
O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(response);
for (int i = 0; i < responseReader.Count; i++)
{
O2GOrderRow orderRow = responseReader.getRow(i);
if (sOrderID.Equals(orderRow.OrderID))
{
bHasOrder = true;
break;
}
}
return bHasOrder;
}
示例4: GetReports
/// <summary>
/// Get reports for all accounts
/// </summary>
/// <param name="session"></param>
public static void GetReports(O2GSession session)
{
O2GLoginRules loginRules = session.getLoginRules();
if (loginRules == null)
{
throw new Exception("Cannot get login rules");
}
O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
O2GAccountsTableResponseReader accountsReader = responseFactory.createAccountsTableReader(accountsResponse);
System.Net.WebClient webClient = new System.Net.WebClient();
for (int i = 0; i < accountsReader.Count; i++)
{
O2GAccountRow account = accountsReader.getRow(i);
string url = session.getReportURL(account, DateTime.Now.AddMonths(-1), DateTime.Now, "html", null, null, 0);
Console.WriteLine("AccountID={0}; Balance={1}; UsedMargin={2}; Report URL={3}",
account.AccountID, account.Balance, account.UsedMargin, url);
string content = webClient.DownloadString(url);
string filename = account.AccountID + ".html";
System.IO.File.WriteAllText(filename, content);
Console.WriteLine("Report is saved to {0}", filename);
}
}
示例5: CreateEntryOrderRequest
/// <summary>
/// Create entry order request
/// </summary>
private static O2GRequest CreateEntryOrderRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRate, string sBuySell, string sOrderType, string sExpireDate)
{
O2GRequest request = null;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GValueMap valuemap = requestFactory.createValueMap();
valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
valuemap.setString(O2GRequestParamsEnum.OrderType, sOrderType);
valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID);
valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell);
valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount);
valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate);
valuemap.setString(O2GRequestParamsEnum.CustomID, "EntryOrder");
if (!string.IsNullOrEmpty(sExpireDate))
{
valuemap.setString(O2GRequestParamsEnum.TimeInForce, Constants.TIF.GTD);
valuemap.setString(O2GRequestParamsEnum.ExpireDateTime, sExpireDate); // UTCTimestamp format: "yyyyMMdd-HH:mm:ss.SSS" (milliseconds are optional)
}
request = requestFactory.createOrderRequest(valuemap);
if (request == null)
{
Console.WriteLine(requestFactory.getLastError());
}
return request;
}
示例6: AddOrderIntoGroupRequest
/// <summary>
/// Create request for adding existing order into existing contingency group
/// </summary>
private static O2GRequest AddOrderIntoGroupRequest(O2GSession session, string sAccountID, string sContingencyID, string sOrderID, int iContingencyType)
{
O2GRequest request = null;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GValueMap valuemapMain = requestFactory.createValueMap();
valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.JoinToExistingContingencyGroup);
valuemapMain.setInt(O2GRequestParamsEnum.ContingencyGroupType, iContingencyType);
valuemapMain.setString(O2GRequestParamsEnum.ContingencyID, sContingencyID);
O2GValueMap valuemapChild = requestFactory.createValueMap();
valuemapChild.setString(O2GRequestParamsEnum.OrderID, sOrderID);
valuemapChild.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemapMain.appendChild(valuemapChild);
request = requestFactory.createOrderRequest(valuemapMain);
if (request == null)
{
Console.WriteLine(requestFactory.getLastError());
}
return request;
}
示例7: Connection
public Connection(O2GSession session, LoginParams loginParams, SampleParams sampleParams, bool bIsFirstAccount)
{
mSession = session;
mLoginParams = loginParams;
mSampleParams = sampleParams;
mIsFirstAccount = bIsFirstAccount;
}
示例8: PrintOffers
/// <summary>
/// Store offers data from response and print it
/// </summary>
/// <param name="session"></param>
/// <param name="response"></param>
/// <param name="sInstrument"></param>
public void PrintOffers(O2GSession session, O2GResponse response, string sInstrument)
{
O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
if (readerFactory == null)
{
throw new Exception("Cannot create response reader factory");
}
O2GOffersTableResponseReader responseReader = readerFactory.createOffersTableReader(response);
for (int i = 0; i < responseReader.Count; i++)
{
O2GOfferRow offerRow = responseReader.getRow(i);
Offer offer;
if (mOffers.FindOffer(offerRow.OfferID, out offer))
{
if (offerRow.isTimeValid && offerRow.isBidValid && offerRow.isAskValid)
{
offer.Date = offerRow.Time;
offer.Bid = offerRow.Bid;
offer.Ask = offerRow.Ask;
}
}
else
{
offer = new Offer(offerRow.OfferID, offerRow.Instrument,
offerRow.Digits, offerRow.PointSize, offerRow.Time,
offerRow.Bid, offerRow.Ask);
mOffers.AddOffer(offer);
}
if (string.IsNullOrEmpty(sInstrument) || offerRow.Instrument.Equals(sInstrument))
{
Console.WriteLine("{0}, {1}, Bid={2}, Ask={3}", offer.OfferID, offer.Instrument, offer.Bid, offer.Ask);
}
}
}
示例9: SessionStatusListener
/// <summary>
/// ctor
/// </summary>
/// <param name="session"></param>
public SessionStatusListener(O2GSession session, string sSessionID, string sPin)
{
mSession = session;
mSessionID = sSessionID;
mPin = sPin;
Reset();
mSyncSessionEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
}
示例10: GetHistoryPrices
/// <summary>
/// Request historical prices for the specified timeframe of the specified period
/// </summary>
/// <param name="session"></param>
/// <param name="sInstrument"></param>
/// <param name="sTimeframe"></param>
/// <param name="dtFrom"></param>
/// <param name="dtTo"></param>
/// <param name="responseListener"></param>
public static void GetHistoryPrices(O2GSession session, string sInstrument, string sTimeframe, DateTime dtFrom, DateTime dtTo, ResponseListener responseListener)
{
O2GRequestFactory factory = session.getRequestFactory();
O2GTimeframe timeframe = factory.Timeframes[sTimeframe];
if (timeframe == null)
{
throw new Exception(string.Format("Timeframe '{0}' is incorrect!", sTimeframe));
}
O2GRequest request = factory.createMarketDataSnapshotRequestInstrument(sInstrument, timeframe, 300);
DateTime dtFirst = dtTo;
do // cause there is limit for returned candles amount
{
factory.fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
responseListener.SetRequestID(request.RequestID);
session.sendRequest(request);
if (!responseListener.WaitEvents())
{
throw new Exception("Response waiting timeout expired");
}
// shift "to" bound to oldest datetime of returned data
O2GResponse response = responseListener.GetResponse();
if (response != null && response.Type == O2GResponseType.MarketDataSnapshot)
{
O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
if (readerFactory != null)
{
O2GMarketDataSnapshotResponseReader reader = readerFactory.createMarketDataSnapshotReader(response);
if (reader.Count > 0)
{
if (DateTime.Compare(dtFirst, reader.getDate(0)) != 0)
{
dtFirst = reader.getDate(0); // earliest datetime of returned data
}
else
{
break;
}
}
else
{
Console.WriteLine("0 rows received");
break;
}
}
PrintPrices(session, response);
}
else
{
break;
}
} while (dtFirst > dtFrom);
}
示例11: FindOrder
/// <summary>
/// Find order by id and print it
/// </summary>
/// <param name="session"></param>
/// <param name="sAccountID"></param>
/// <param name="sOrderID"></param>
/// <param name="responseListener"></param>
private static void FindOrder(O2GSession session, string sAccountID, string sOrderID, ResponseListener responseListener)
{
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Orders, sAccountID);
if (request != null)
{
responseListener.SetRequestID(request.RequestID);
session.sendRequest(request);
if (!responseListener.WaitEvents())
{
throw new Exception("Response waiting timeout expired");
}
O2GResponse orderResponse = responseListener.GetResponse();
if (orderResponse != null)
{
if (orderResponse.Type == O2GResponseType.GetOrders)
{
O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory();
bool bFound = false;
O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(orderResponse);
for (int i = 0; i < responseReader.Count; i++)
{
O2GOrderRow orderRow = responseReader.getRow(i);
if (sOrderID.Equals(orderRow.OrderID))
{
Console.WriteLine("OrderID={0}; AccountID={1}; Type={2}; Status={3}; OfferID={4}; Amount={5}; BuySell={6}; Rate={7}",
orderRow.OrderID, orderRow.AccountID, orderRow.Type, orderRow.Status, orderRow.OfferID,
orderRow.Amount, orderRow.BuySell, orderRow.Rate);
bFound = true;
break;
}
}
if (!bFound)
{
Console.WriteLine("OrderID={0} is not found!", sOrderID);
}
}
}
}
else
{
Console.WriteLine("Cannot create request");
}
}
示例12: PrintAccounts
/// <summary>
/// Print accounts table
/// </summary>
/// <param name="session"></param>
private static void PrintAccounts(O2GSession session)
{
O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
if (readerFactory == null)
{
throw new Exception("Cannot create response reader factory");
}
O2GLoginRules loginRules = session.getLoginRules();
O2GResponse response = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
O2GAccountsTableResponseReader accountsResponseReader = readerFactory.createAccountsTableReader(response);
for (int i = 0; i < accountsResponseReader.Count; i++)
{
O2GAccountRow accountRow = accountsResponseReader.getRow(i);
Console.WriteLine("AccountID: {0}, Balance: {1}, Used margin: {2}", accountRow.AccountID, accountRow.Balance, accountRow.UsedMargin);
}
}
示例13: CreateTrueMarketOrderRequest
/// <summary>
/// Create true market order request
/// </summary>
private static O2GRequest CreateTrueMarketOrderRequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, string sBuySell)
{
O2GRequest request = null;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GValueMap valuemap = requestFactory.createValueMap();
valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.TrueMarketOpen);
valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID);
valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell);
valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount);
valuemap.setString(O2GRequestParamsEnum.CustomID, "TrueMarketOrder");
request = requestFactory.createOrderRequest(valuemap);
return request;
}
示例14: GetAccount
/// <summary>
/// Find valid account by ID or get the first valid account
/// </summary>
/// <param name="session"></param>
/// <returns>account</returns>
private static O2GAccountRow GetAccount(O2GSession session, string sAccountID)
{
O2GAccountRow account = null;
bool bHasAccount = false;
O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
if (readerFactory == null)
{
throw new Exception("Cannot create response reader factory");
}
O2GLoginRules loginRules = session.getLoginRules();
O2GResponse response = loginRules.getTableRefreshResponse(O2GTableType.Accounts);
O2GAccountsTableResponseReader accountsResponseReader = readerFactory.createAccountsTableReader(response);
for (int i = 0; i < accountsResponseReader.Count; i++)
{
account = accountsResponseReader.getRow(i);
string sAccountKind = account.AccountKind;
if (account.MaintenanceType.Equals("0")) // netting account
{
if (sAccountKind.Equals("32") || sAccountKind.Equals("36"))
{
if (account.MarginCallFlag.Equals("N"))
{
if (string.IsNullOrEmpty(sAccountID) || sAccountID.Equals(account.AccountID))
{
bHasAccount = true;
break;
}
}
}
}
}
if (!bHasAccount)
{
return null;
}
else
{
return account;
}
}
示例15: CreateOCORequest
/// <summary>
/// Create OCO request
/// </summary>
private static O2GRequest CreateOCORequest(O2GSession session, string sOfferID, string sAccountID, int iAmount, double dRateUp, double dRateDown)
{
O2GRequest request = null;
O2GRequestFactory requestFactory = session.getRequestFactory();
if (requestFactory == null)
{
throw new Exception("Cannot create request factory");
}
O2GValueMap valuemapMain = requestFactory.createValueMap();
valuemapMain.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOCO);
// ValueMap for upswing
O2GValueMap valuemapUp = requestFactory.createValueMap();
valuemapUp.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
valuemapUp.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry);
valuemapUp.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemapUp.setString(O2GRequestParamsEnum.OfferID, sOfferID);
valuemapUp.setString(O2GRequestParamsEnum.BuySell, Constants.Buy);
valuemapUp.setInt(O2GRequestParamsEnum.Amount, iAmount);
valuemapUp.setDouble(O2GRequestParamsEnum.Rate, dRateUp);
valuemapMain.appendChild(valuemapUp);
// ValueMap for downswing
O2GValueMap valuemapDown = requestFactory.createValueMap();
valuemapDown.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
valuemapDown.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.StopEntry);
valuemapDown.setString(O2GRequestParamsEnum.AccountID, sAccountID);
valuemapDown.setString(O2GRequestParamsEnum.OfferID, sOfferID);
valuemapDown.setString(O2GRequestParamsEnum.BuySell, Constants.Sell);
valuemapDown.setInt(O2GRequestParamsEnum.Amount, iAmount);
valuemapDown.setDouble(O2GRequestParamsEnum.Rate, dRateDown);
valuemapMain.appendChild(valuemapDown);
request = requestFactory.createOrderRequest(valuemapMain);
if (request == null)
{
Console.WriteLine(requestFactory.getLastError());
}
return request;
}