public static void GetTradeSession(TickTraderWebClient client) { // Account trade session TTTradeSession tradesession = client.GetTradeSession(); Console.WriteLine("Trade session status: {0}", tradesession.SessionStatus); }
public ClientView(CredsModel creds) { PublicTradeSessionCommand = new Command(async() => await GetPublicTradeSession()); PublicCurrenciesCommand = new Command(async() => await GetPublicCurrencies()); PublicSymbolsCommand = new Command(async() => await GetPublicSymbols()); PublicTicksCommand = new Command(async() => await GetPublicTicks()); PublicTicksL2Command = new Command(async() => await GetPublicTicksLevel2()); PublicTickersCommand = new Command(async() => await GetPublicTickers()); AccountInfoCommand = new Command(async() => await GetAccount()); TradeSessionCommand = new Command(async() => await GetTradeSession()); CurrenciesCommand = new Command(async() => await GetCurrencies()); SymbolsCommand = new Command(async() => await GetSymbols()); TicksCommand = new Command(async() => await GetTicks()); TicksL2Command = new Command(async() => await GetTicksLevel2()); AssetsCommand = new Command(async() => await GetAssets()); PositionsCommand = new Command(async() => await GetPositions()); TradesCommand = new Command(async() => await GetTrades()); if (creds.IsPublicOnly) { _client = new TickTraderWebClient(creds.WebApiAddress); IsPublicEnabled = true; IsPrivateEnabled = false; } else { _client = new TickTraderWebClient(creds.WebApiAddress, creds.WebApiId, creds.WebApiKey, creds.WebApiSecret); IsPublicEnabled = true; IsPrivateEnabled = true; AccountInfoCommand.Execute(null); } }
public static void LimitOrder(TickTraderWebClient client) { // Create, modify and cancel limit order TTAccount account = client.GetAccount(); if ((account.AccountingType == TTAccountingTypes.Gross) || (account.AccountingType == TTAccountingTypes.Net)) { // Create limit order var limit = client.CreateTrade(new TTTradeCreate { Type = TTOrderTypes.Limit, Side = TTOrderSides.Buy, Symbol = (account.AccountingType == TTAccountingTypes.Gross) ? "EURUSD" : "EUR/USD", Amount = 10000, Price = 1.0M, Comment = "Buy limit from Web API sample" }); // Modify limit order limit = client.ModifyTrade(new TTTradeModify { Id = limit.Id, Comment = "Modified limit from Web API sample" }); // Cancel limit order client.CancelTrade(limit.Id); } }
public static void GetAccount(TickTraderWebClient client) { // Account info TTAccount account = client.GetAccount(); Console.WriteLine("Account Id: {0}", account.Id); Console.WriteLine("Account name: {0}", account.Name); Console.WriteLine("Account group: {0}", account.Group); }
public static void GetPublicTradeSession(TickTraderWebClient client) { // Public trade session TTTradeSession publictradesession = client.GetPublicTradeSession(); Console.WriteLine("TickTrader name: {0}", publictradesession.PlatformName); Console.WriteLine("TickTrader company: {0}", publictradesession.PlatformCompany); Console.WriteLine("TickTrader address: {0}", publictradesession.PlatformAddress); Console.WriteLine("TickTrader timezone offset: {0}", publictradesession.PlatformTimezoneOffset); Console.WriteLine("TickTrader session status: {0}", publictradesession.SessionStatus); }
public static void GetPositions(TickTraderWebClient client) { // Account positions TTAccount account = client.GetAccount(); if (account.AccountingType == TTAccountingTypes.Net) { List <TTPosition> positions = client.GetAllPositions(); foreach (var p in positions) { Console.WriteLine("{0} position: {1} {2}", p.Symbol, p.LongAmount, p.ShortAmount); } } }
public static void GetAssets(TickTraderWebClient client) { // Account assets TTAccount account = client.GetAccount(); if (account.AccountingType == TTAccountingTypes.Cash) { List <TTAsset> assets = client.GetAllAssets(); foreach (var a in assets) { Console.WriteLine("{0} asset: {1}", a.Currency, a.Amount); } } }
public static void GetTrades(TickTraderWebClient client) { // Account trades List <TTTrade> trades = client.GetAllTrades(); foreach (var t in trades) { Console.WriteLine("{0} trade with type {1} by symbol {2}: {3}", t.Id, t.Type, t.Symbol, t.Amount); } if (trades.Count > 0) { TTTrade trade = client.GetTrade(trades[0].Id); Console.WriteLine("{0} trade with type {1} by symbol {2}: {3}", trade.Id, trade.Type, trade.Symbol, trade.Amount); } }
public static void GetPublicCurrencies(TickTraderWebClient client) { // Public currencies List <TTCurrency> publicCurrencies = client.GetPublicAllCurrencies(); foreach (var c in publicCurrencies) { Console.WriteLine("Currency: " + c.Name); } TTCurrency publicCurrency = client.GetPublicCurrency(publicCurrencies[0].Name).FirstOrDefault(); if (publicCurrency != null) { Console.WriteLine("{0} currency precision: {1}", publicCurrency.Name, publicCurrency.Precision); } }
public static void GetTicksLevel2(TickTraderWebClient client) { // Account feed ticks level2 List <TTFeedTickLevel2> ticksLevel2 = client.GetAllTicksLevel2(); foreach (var t in ticksLevel2) { Console.WriteLine("{0} level2 book depth: {1}", t.Symbol, Math.Max(t.Bids.Count, t.Asks.Count)); } TTFeedTickLevel2 tickLevel2 = client.GetTickLevel2(ticksLevel2[0].Symbol).FirstOrDefault(); if (tickLevel2 != null) { Console.WriteLine("{0} level2 book depth: {1}", tickLevel2.Symbol, Math.Max(tickLevel2.Bids.Count, tickLevel2.Asks.Count)); } }
public static void GetTicks(TickTraderWebClient client) { // Account feed ticks List <TTFeedTick> ticks = client.GetAllTicks(); foreach (var t in ticks) { Console.WriteLine("{0} tick: {1}, {2}", t.Symbol, t.BestBid.Price, t.BestAsk.Price); } TTFeedTick tick = client.GetTick(ticks[0].Symbol).FirstOrDefault(); if (tick != null) { Console.WriteLine("{0} tick timestamp: {1}", tick.Symbol, tick.Timestamp); } }
public static void GetPublicTickers(TickTraderWebClient client) { // Public symbol statistics List <TTTicker> publicTickers = client.GetPublicAllTickers(); foreach (var t in publicTickers) { Console.WriteLine("{0} last buy/sell prices : {1} / {2}", t.Symbol, t.LastBuyPrice, t.LastSellPrice); } TTTicker publicTicker = client.GetPublicTicker(publicTickers[0].Symbol).FirstOrDefault(); if (publicTicker != null) { Console.WriteLine("{0} best bid/ask: {1} / {2}", publicTicker.Symbol, publicTicker.BestBid, publicTicker.BestAsk); } }
public static void GetPublicSymbols(TickTraderWebClient client) { // Public symbols List <TTSymbol> publicSymbols = client.GetPublicAllSymbols(); foreach (var s in publicSymbols) { Console.WriteLine("Symbol: " + s.Symbol); } TTSymbol publicSymbol = client.GetPublicSymbol(publicSymbols[0].Symbol).FirstOrDefault(); if (publicSymbol != null) { Console.WriteLine("{0} symbol precision: {1}", publicSymbol.Symbol, publicSymbol.Precision); } }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: TTWebClientSample.exe WebApiAddress WebApiId WebApiKey WebApiSecret"); return; } string webApiAddress = args[0]; string webApiId = args[1]; string webApiKey = args[2]; string webApiSecret = args[3]; // Optional: Force to ignore server certificate TickTraderWebClient.IgnoreServerCertificate(); // Create instance of the TickTrader Web API client var client = new TickTraderWebClient(webApiAddress, webApiId, webApiKey, webApiSecret); Console.WriteLine("--- Public Web API methods ---"); GetPublicTradeSession(client); GetPublicCurrencies(client); GetPublicSymbols(client); GetPublicTicks(client); GetPublicTicksLevel2(client); Console.WriteLine("--- Web API client methods ---"); GetAccount(client); GetTradeSession(client); GetCurrencies(client); GetSymbols(client); GetTicks(client); GetTicksLevel2(client); GetAssets(client); GetPositions(client); GetTrades(client); GetTradeHistory(client); LimitOrder(client); }
public static void SetupSymbols(TickTraderWebClient client) { var symbols = client.GetQuoteHistorySymbols(); foreach (var symbol in symbols) { using (var repo = new SymbolRepository()) { try { repo.AddSymbol(new Symbol { Name = symbol }).GetAwaiter().GetResult(); } catch (SqlException e) { Console.WriteLine(e); } } } }
public static void SetupQuotes(TickTraderWebClient client) { using (var symbolRepository = new SymbolRepository()) using (var quoteRepository = new QuoteRepository()) { var symbols = symbolRepository.GetAll().ToList(); foreach (var symbol in symbols) { try { var periodicities = client.GetQuoteSymbolPeriodicities(symbol.Name); var barInfo = client.GetBarsInfo(symbol.Name, periodicities[0]); var bars = client.GetBars(symbol.Name, periodicities[0], barInfo.AvailableTo, BatchSize); foreach (var bar in bars.Bars) { quoteRepository.AddQuote(new Quote { SymbolId = symbol.Id, Timestamp = bar.Timestamp, Close = bar.Close, High = bar.High, Low = bar.Low, Open = bar.Open, Volume = bar.Open }); } } catch (HttpRequestException e) { Console.WriteLine(e.Message); } catch (SqlException e) { Console.WriteLine(e.Message); } } } }
private static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: TreadingView.Importer.exe WebApiAddress WebApiId WebApiKey WebApiSecret"); return; } var webApiAddress = args[0]; var webApiId = args[1]; var webApiKey = args[2]; var webApiSecret = args[3]; TickTraderWebClient.IgnoreServerCertificate(); var client = new TickTraderWebClient(webApiAddress, webApiId, webApiKey, webApiSecret); // Uncomment to get symbols from Tick Trader Web API, Should be called // before SetupQuotes method //SetupSymbols(client); // Uncomment to get last (BatchSize) bars from Web API for each symbol // SetupQuotes(client); }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: TTWebClientRobot.exe WebApiAddress WebApiId WebApiKey WebApiSecret"); return; } string webApiAddress = args[0]; string webApiId = args[1]; string webApiKey = args[2]; string webApiSecret = args[3]; // Optional: Force to ignore server certificate TickTraderWebClient.IgnoreServerCertificate(); // Create instance of the TickTrader Web API client var client = new TickTraderWebClient(webApiAddress, webApiId, webApiKey, webApiSecret); // Create and run WebRobot var robot = new WebRobot(client); robot.RunInConsole(); }
public static void GetTradeHistory(TickTraderWebClient client) { int iterations = 3; var request = new TTTradeHistoryRequest { TimestampTo = DateTime.UtcNow, RequestDirection = TTStreamingDirections.Backward, RequestPageSize = 10 }; // Try to get trade history from now to the past. Request is limited to 30 records! while (iterations-- > 0) { TTTradeHistoryReport report = client.GetTradeHistory(request); foreach (var record in report.Records) { Console.WriteLine("TradeHistory record: Id={0}, TransactionType={1}, TransactionReason={2}, Symbol={3}, TradeId={4}", record.Id, record.TransactionType, record.TransactionReason, record.Symbol, record.TradeId); request.RequestLastId = record.Id; } // Stop for last report if (report.IsLastReport) { break; } } }
public WebRobot(TickTraderWebClient client) { WebClient = client; }
static ClientView() { // Optional: Force to ignore server certificate TickTraderWebClient.IgnoreServerCertificate(); }