本文整理汇总了C#中CIAPI.Rpc.Client类的典型用法代码示例。如果您正苦于以下问题:C# Client类的具体用法?C# Client怎么用?C# Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Client类属于CIAPI.Rpc命名空间,在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewsDetailAsync
public void GetNewsDetailAsync(int storyId, Action<NewsDetailDTO> onSuccess, Action<Exception> onError)
{
var client = new Client(RPC_URI);
client.BeginLogIn(USERNAME, PASSWORD,
ar =>
{
try
{
client.EndLogIn(ar);
client.BeginGetNewsDetail(storyId.ToString(),
ar2 =>
{
try
{
var resp = client.EndGetNewsDetail(ar2);
_client.BeginLogOut(ar3 => _client.EndLogOut(ar3), null);
onSuccess(resp.NewsDetail);
}
catch (Exception exc)
{
onError(exc);
}
}, null);
}
catch (Exception exc)
{
onError(exc);
}
}, null);
}
示例2: SetupFixture
public void SetupFixture()
{
_rpcClient = BuildRpcClient();
_streamingClient = _rpcClient.CreateStreamingClient();
_CFDmarketId = GetAvailableCFDMarkets(_rpcClient)[0].MarketId;
_accounts = _rpcClient.AccountInformation.GetClientAndTradingAccount();
}
示例3: DoPolling
private static void DoPolling()
{
var client = new Client(Const.RPC_URI, Const.STREAMING_URI, "Test.{B4E415A7-C453-4867-BDD1-C77ED345777B}");
try
{
client.AppKey = "Test";
client.StartMetrics();
client.LogIn(Const.USERNAME, Const.PASSWORD);
for (int i = 0; i < 10; i++)
{
var accountInfo = client.AccountInformation.GetClientAndTradingAccount();
client.TradesAndOrders.ListOpenPositions(accountInfo.CFDAccount.TradingAccountId);
Thread.Sleep(1000);
}
client.LogOut();
}
catch (Exception exc)
{
Trace.WriteLine(exc);
}
finally
{
client.Dispose();
}
}
示例4: Main
static void Main(string[] args)
{
try
{
var curProcess = Process.GetCurrentProcess();
var secondsOnStart = curProcess.TotalProcessorTime.TotalSeconds;
var totalWatch = Stopwatch.StartNew();
for (int i = 0; i < 20; i++)
{
var client = new Client(Const.RPC_URI, Const.STREAMING_URI, "");
var recorder = new Recorder(client);
recorder.Start();
var loginWatch = Stopwatch.StartNew();
client.LogIn(Const.USERNAME, Const.PASSWORD);
loginWatch.Stop();
var accountInfoWatch = Stopwatch.StartNew();
var accountInfo = client.AccountInformation.GetClientAndTradingAccount();
accountInfoWatch.Stop();
var listSpreadMarketsWatch = Stopwatch.StartNew();
var resp = client.SpreadMarkets.ListSpreadMarkets("", "",
accountInfo.ClientAccountId, 100, false);
listSpreadMarketsWatch.Stop();
var logoutWatch = Stopwatch.StartNew();
client.LogOut();
logoutWatch.Stop();
var purgeHandle = client.ShutDown();
if (!purgeHandle.WaitOne(60000))
throw new ApplicationException();
var requests = recorder.GetRequests();
if (requests.Count != 4)
throw new ApplicationException();
AddResult(loginWatch, requests[0], "Login");
AddResult(accountInfoWatch, requests[1], "GetClientAndTradingAccount");
AddResult(listSpreadMarketsWatch, requests[2], "ListSpreadMarkets");
AddResult(logoutWatch, requests[3], "Logout");
recorder.Stop();
recorder.Dispose();
client.Dispose();
}
totalWatch.Stop();
var secondsOnEnd = curProcess.TotalProcessorTime.TotalSeconds;
Console.WriteLine("CPU time used, seconds: {0} total time: {1}", secondsOnEnd - secondsOnStart, totalWatch.Elapsed.TotalSeconds);
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
Debugger.Break();
}
示例5: CanChangePassword
public void CanChangePassword()
{
const string NEWPASSWORD = "bingo72652";
var rpcClient = new Client(Settings.RpcUri,Settings.StreamingUri, AppKey);
//Login with existing credentials
rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);
//And change password
var changePasswordResponse = rpcClient.Authentication.ChangePassword(new ApiChangePasswordRequestDTO()
{
UserName = Settings.RpcUserName,
Password = Settings.RpcPassword,
NewPassword = NEWPASSWORD
});
Assert.IsTrue(changePasswordResponse.IsPasswordChanged);
rpcClient.LogOut();
//Make sure that login existing password fails
Assert.Throws<ReliableHttpException>(() => rpcClient.LogIn(Settings.RpcUserName, Settings.RpcUserName));
//Login with changed password and change back
rpcClient.LogIn(Settings.RpcUserName, NEWPASSWORD);
changePasswordResponse = rpcClient.Authentication.ChangePassword(new ApiChangePasswordRequestDTO()
{
UserName = Settings.RpcUserName,
Password = NEWPASSWORD,
NewPassword = Settings.RpcPassword
});
Assert.IsTrue(changePasswordResponse.IsPasswordChanged);
rpcClient.LogOut();
rpcClient.Dispose();
}
示例6: CanMockCiapiServerConversation
public void CanMockCiapiServerConversation()
{
Uri uri = new Uri(NormalizeUrl("/"));
var rpcClient = new Client(uri, uri, "foobardotnet");
rpcClient.LogIn("Foo", "Bar");
Assert.AreEqual("5f28983b-0e0a-4a57-92af-0d07c6fdbc38", rpcClient.Session);
// get some headlines
var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);
Assert.AreEqual(100, headlines.Headlines.Length);
// get a story id from one of the headlines
var storyId = headlines.Headlines[0].StoryId;
Assert.AreEqual(1416482, storyId);
var storyDetail = rpcClient.News.GetNewsDetail("dj", storyId.ToString());
Assert.IsTrue(storyDetail.NewsDetail.Story.Contains("By Anita Greil "));
rpcClient.LogOut();
rpcClient.Dispose();
}
示例7: RecordNewDataForCIAPI
public void RecordNewDataForCIAPI()
{
var rpcClient = new Client(new Uri("https://ciapi.cityindex.com/tradingapi"), new Uri("https://push.cityindex.com"), "foobardotnet");
// start recording requests
var stream = new MemoryStream();
var streamRecorder = new StreamRecorder(rpcClient, stream);
streamRecorder.Start();
rpcClient.LogIn("secret", "secret");
var accountInfo = rpcClient.AccountInformation.GetClientAndTradingAccount();
rpcClient.SpreadMarkets.ListSpreadMarkets("", "", accountInfo.ClientAccountId, 100, false);
rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 10);
rpcClient.Market.GetMarketInformation(MarketId.ToString());
rpcClient.PriceHistory.GetPriceBars(MarketId.ToString(), "MINUTE", 1, "20");
rpcClient.TradesAndOrders.ListOpenPositions(accountInfo.SpreadBettingAccount.TradingAccountId);
rpcClient.LogOut();
streamRecorder.Stop();
stream.Position = 0;
using (var fileStream = File.Create("recorded_requests.txt"))
{
stream.WriteTo(fileStream);
}
}
示例8: Client
public Client(Uri rpcUri, Uri streamingUri, string appKey,IJsonSerializer serializer, IRequestFactory factory)
: base(serializer, factory)
{
#if SILVERLIGHT
#if WINDOWS_PHONE
UserAgent = "CIAPI.PHONE7."+ GetVersionNumber();
#else
UserAgent = "CIAPI.SILVERLIGHT."+ GetVersionNumber();
#endif
#else
UserAgent = "CIAPI.CS." + GetVersionNumber();
#endif
AppKey=appKey;
_client=this;
_rootUri = rpcUri;
_streamingUri = streamingUri;
this. Authentication = new _Authentication(this);
this. PriceHistory = new _PriceHistory(this);
this. News = new _News(this);
this. CFDMarkets = new _CFDMarkets(this);
this. SpreadMarkets = new _SpreadMarkets(this);
this. Market = new _Market(this);
this. Preference = new _Preference(this);
this. TradesAndOrders = new _TradesAndOrders(this);
this. AccountInformation = new _AccountInformation(this);
this. Messaging = new _Messaging(this);
this. Watchlist = new _Watchlist(this);
this. ClientApplication = new _ClientApplication(this);
this. ExceptionHandling = new _ExceptionHandling(this);
Log.Debug("Rpc.Client created for " + _rootUri.AbsoluteUri);
}
示例9: CanSendMetrics
public void CanSendMetrics()
{
// set up a listener
var log = new StringBuilder();
var writer = new StringWriter(log);
var listener = new TextWriterTraceListener(writer);
Trace.Listeners.Add(listener);
var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, "my-test-appkey");
var metricsRecorder = new MetricsRecorder(rpcClient, new Uri("http://metrics.labs.cityindex.com/LogEvent.ashx"));
metricsRecorder.Start();
rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);
var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);
foreach (var item in headlines.Headlines)
{
rpcClient.News.GetNewsDetail("dj", item.StoryId.ToString());
}
new AutoResetEvent(false).WaitOne(10000);
rpcClient.LogOut();
metricsRecorder.Stop();
rpcClient.Dispose();
Trace.Listeners.Remove(listener);
var logText = log.ToString();
Assert.IsTrue(logText.Contains("Latency message complete"), "did not find evidence of metrics being posted");
}
示例10: Client
public Client(Uri rpcUri, Uri streamingUri, string appKey, int backgroundInterval)
: base(new Serializer(),backgroundInterval)
{
#if SILVERLIGHT
#if WINDOWS_PHONE
UserAgent = "CIAPI.PHONE7."+ GetVersionNumber();
#else
UserAgent = "CIAPI.SILVERLIGHT."+ GetVersionNumber();
#endif
#else
UserAgent = "CIAPI.CS." + GetVersionNumber();
#endif
_streamingFactory=new LightStreamerStreamingClientFactory();
AppKey=appKey;
_client=this;
_rootUri = rpcUri;
_streamingUri = streamingUri;
this. Authentication = new _Authentication(this);
this. PriceHistory = new _PriceHistory(this);
this. News = new _News(this);
this. CFDMarkets = new _CFDMarkets(this);
this. SpreadMarkets = new _SpreadMarkets(this);
this. Market = new _Market(this);
this. Preference = new _Preference(this);
this. TradesAndOrders = new _TradesAndOrders(this);
this. AccountInformation = new _AccountInformation(this);
this. Messaging = new _Messaging(this);
this. Watchlist = new _Watchlist(this);
this. ClientApplication = new _ClientApplication(this);
Log.Debug("Rpc.Client created for " + _rootUri.AbsoluteUri);
}
示例11: BuildRpcClient
public Client BuildRpcClient()
{
//Thread.Sleep(2000); // to let throttle settle down
var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, AppKey);
rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);
return rpcClient;
}
示例12: Issue42
public void Issue42()
{
var rpcClient = new Client(Settings.RpcUri);
rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);
var param = new NewStopLimitOrderRequestDTO
{
OrderId = 0,
MarketId = 99498,
Currency = null,
AutoRollover = false,
Direction = "buy",
Quantity = 10m,
BidPrice = 12094m,
OfferPrice = 12098m,
AuditId = "20110629-G2PREPROD3-0102794",
TradingAccountId = 400002249,
IfDone = null,
OcoOrder = null,
Applicability = null,
ExpiryDateTimeUTC = null,
Guaranteed = false,
TriggerPrice = 0m
};
var response = rpcClient.TradesAndOrders.Order(param);
rpcClient.LogOut();
}
示例13: BuildUnauthenticatedRpcClient
protected Client BuildUnauthenticatedRpcClient()
{
// WARNING: do not nest or otherwise refactor this method
// buildUri is looking back 2 stack frames to get the method that called this
var rpcClient = new Client(BuildUri(), new Uri(_streamingUrl), _apiKey);
return rpcClient;
}
示例14: AutoLogin
private void AutoLogin()
{
if (_ctx == null)
{
_ctx = new CIAPI.Rpc.Client(RPC_URI);
_ctx.LogIn(USERNAME, PASSWORD);
}
}
示例15: GetTradingAccountId
private static int GetTradingAccountId(Client client, int marketId, AccountInformationResponseDTO accountInfo)
{
GetMarketInformationResponseDTO marketInfo = client.Market.GetMarketInformation(marketId.ToString());
bool isCfd = marketInfo.MarketInformation.Name.EndsWith("CFD");
ApiTradingAccountDTO tradingAccount = isCfd
? accountInfo.TradingAccounts[0]
: accountInfo.TradingAccounts[1];
return tradingAccount.TradingAccountId;
}