static void Main() { // Only have one instance running. var mutex = new Mutex(true, APPLICATION_PROCESS_GUID, out bool instanceResult); if (!instanceResult) { return; } GC.KeepAlive(mutex); Logger.Log("Starting Sidekick."); // System tray icon. TrayIcon.Initialize(); // Load POE Trade information. _ = TradeClient.Initialize(); // Keyboard hooks. EventsHandler.Initialize(); // Overlay. OverlayController.Initialize(); // Run window. Application.ApplicationExit += OnApplicationExit; Application.Run(); }
private static async void TriggerItemFetch() { Logger.Log("Hotkey pressed."); // Trigger copy action. SendKeys.SendWait("^{c}"); // Retrieve clipboard. var itemText = ClipboardHelper.GetText(); // Parse item. var item = ItemParser.ParseItem(itemText); if (item != null) { OverlayController.SetPosition(Cursor.Position.X, Cursor.Position.Y); OverlayController.Show(); var queryResult = await TradeClient.GetListings(item); if (queryResult != null) { OverlayController.SetQueryResult(queryResult); return; } } OverlayController.Hide(); }
private static void OnApplicationExit(object sender, EventArgs e) { TrayIcon.Dispose(); TradeClient.Dispose(); EventsHandler.Dispose(); OverlayController.Dispose(); }
public void Should_Successfully_Send_BuyOrder() { var tradeClient = new TradeClient(_logger); var buyOrder = new FixOrder { Account = "12345678", SecurityId = "SampleID4567", Price = 64500 }; bool result = tradeClient.Send(buyOrder); Assert.True(result); }
private static void ChangeLanguage(Language lang) // Maybe async? { if (_providerDictionary.ContainsKey(lang)) { Provider = _providerDictionary[lang]; CurrentLanguage = lang; TradeClient.FetchAPIData().Wait(); } else { throw new Exception("Language not implemented yet"); } }
public void Should_Successfully_Send_SellOrder() { var tradeClient = new TradeClient(_logger); var sellOrder = new FixOrder { Account = "87654321", SecurityId = "SID4567", Price = 11300 }; bool result = tradeClient.Send(sellOrder); Assert.True(result); }
/// <summary> /// 获取最后一根柱子的信息 /// </summary> /// <param name="pcode">商品行情编码</param> /// <param name="dtype">周期类型</param> /// <returns>获取最后一根柱子的信息(逗号隔开的行情数据)</returns> public string GetLastPillar(string pcode, datatype dtype) { string strtmp = String.Empty; TradeClient tc = new TradeClient(); try { switch (dtype) { case datatype.M1: strtmp = "M1"; break; case datatype.M5: strtmp = "M5"; break; case datatype.M15: strtmp = "M15"; break; case datatype.M30: strtmp = "M30"; break; case datatype.H1: strtmp = "H1"; break; case datatype.H4: strtmp = "H4"; break; case datatype.D1: strtmp = "D1"; break; case datatype.W1: strtmp = "W1"; break; case datatype.MN: strtmp = "MN"; break; default: break; } strtmp = tc.GetLastPillarData(strtmp, pcode); tc.Close(); } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return(strtmp); }
private void ChangeCurrent(TradeClient client) { if (Current != null) { Current.CapitalReceived -= Show; } client.CapitalReceived += Show; Thread thread = new Thread(new ThreadStart(() => { client.QueryCapital(); })); thread.Start(); Current = client; ClientChanged?.Invoke(client); }
// Constructor for Fabricated Goods Trade Order: public TradeOrder(TradeClient client, string name, int comp, Item fabGoods, int ammnt, int days) { tradeClient = client; orderName = name; compensation = comp; tradeResource = new TradeResource(fabGoods); tradeQuota = ammnt; timeLimit = days; tradeOrderStatus = TradeOrderStatus.Pending; }
// Constructor for Raw Resources Trade Order: public TradeOrder(TradeClient client, string name, int comp, TileData.Types rawResource, int ammnt, int days) { tradeClient = client; orderName = name; compensation = comp; tradeResource = new TradeResource(rawResource); tradeQuota = ammnt; timeLimit = days; tradeOrderStatus = TradeOrderStatus.Pending; }
private void InitializeTradeClients() { optLastTrdClient = new TradeClient(); optLastTrdClient.RegisterSessHndlrs(optLastTrdClient_HandleErr, optLastTrdClient_HandleConnectionFailed, optLastTrdClient_HandleConnected, optLastTrdClient_HandleDisconnected); eqLastTrdClient = new TradeClient(); eqLastTrdClient.RegisterSessHndlrs(eqLastTrdClient_HandleErr, eqLastTrdClient_HandleConnectionFailed, eqLastTrdClient_HandleConnected, eqLastTrdClient_HandleDisconnected); sprdLastTrdClient = new TradeClient(); sprdLastTrdClient.RegisterSessHndlrs(sprdLastTrdClient_HandleErr, sprdLastTrdClient_HandleConnectionFailed, sprdLastTrdClient_HandleConnected, sprdLastTrdClient_HandleDisconnected); }
/// <summary> /// 获取实时价 /// </summary> /// <param name="pcode">商品行情编码</param> /// <returns>获取实际价格</returns> public double GetRealPrice(string pcode) { TradeClient tc = new TradeClient(); double price = 0; try { price = tc.GetRealprice(pcode); } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return(price); }
public static async void GetBaseListing() { if (currentItem.GetType() == typeof(EquippableItem)) { var item = (EquippableItem)currentItem; item.Rarity = StringConstants.RarityAnyNonUnique; var queryResult = await TradeClient.GetListings(item); if (queryResult != null) { OverlayController.SetQueryResult(queryResult); return; } } }
private static async void TriggerItemFetch() { Logger.Log("Hotkey for pricing item triggered."); Item item = await TriggerCopyAction(); if (item != null) { OverlayController.Open(); var queryResult = await TradeClient.GetListings(item); if (queryResult != null) { OverlayController.SetQueryResult(queryResult); return; } } OverlayController.Hide(); }
public void Subscribe() { var symbol1 = Symbol.BTC_USDT; var symbol2 = Symbol.LTC_BTC; Assert.Empty(_client.SubscribedStreams); // Subscribe to symbol. _client.Subscribe(symbol1); Assert.Equal(TradeClient.GetStreamName(symbol1), _client.SubscribedStreams.Single()); // Re-Subscribe to same symbol doesn't fail. _client.Subscribe(symbol1); Assert.Equal(TradeClient.GetStreamName(symbol1), _client.SubscribedStreams.Single()); // Subscribe to a different symbol. _client.Subscribe(symbol2); Assert.True(_client.SubscribedStreams.Count() == 2); Assert.Contains(TradeClient.GetStreamName(symbol1), _client.SubscribedStreams); Assert.Contains(TradeClient.GetStreamName(symbol2), _client.SubscribedStreams); }
/// <summary> /// Every item should start with Rarity in the first line. /// This will force the TradeClient to refetch the Public API's data if needed. /// </summary> public static async Task <bool> FindAndSetLanguageProvider(string itemDescription) { foreach (var item in RarityToLanguageDictionary) { if (itemDescription.Contains(item.Key)) { if (CurrentLanguage != item.Value) { Logger.Log($"Changed language support to {item.Value}."); CurrentLanguage = item.Value; Provider = GetLanguageProvider(item.Value); TradeClient.Dispose(); return(await TradeClient.Initialize()); } return(true); } } Logger.Log("This Path of Exile language is not yet supported."); return(false); }
/// <summary> /// 获取最后一根柱子的信息 /// </summary> /// <param name="pcode">商品行情编码</param> /// <param name="dtype">周期类型</param> /// <returns>获取最后一根柱子的信息(逗号隔开的行情数据)</returns> public string GetLastPillar(string pcode, datatype dtype) { string strtmp = String.Empty; TradeClient tc = new TradeClient(); try { switch (dtype) { case datatype.M1: strtmp = "M1"; break; case datatype.M5: strtmp = "M5"; break; case datatype.M15: strtmp = "M15"; break; case datatype.M30: strtmp = "M30"; break; case datatype.H1: strtmp = "H1"; break; case datatype.H4: strtmp = "H4"; break; case datatype.D1: strtmp = "D1"; break; case datatype.W1: strtmp = "W1"; break; case datatype.MN: strtmp = "MN"; break; default: break; } strtmp = tc.GetLastPillarData(strtmp, pcode); tc.Close(); } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return strtmp; }
private bool DoLogin() { Config config = CurrentConfig(); string account = CurrentAccount(); if (config == null) { MessageBox.Show("请选择服务配置"); return(false); } if (String.IsNullOrEmpty(account)) { MessageBox.Show("请输入账号"); return(false); } try { SaveConfig(); TradeClient adapter = TradeFacade.Create( account, txtPassword.Text, config.TradeHost, config.TradeQueryPort, config.TradeOrderPort, config.TradeReportPort ); StockFacade.ConnectL1(config.ReferenceAddress); StockFacade.ConnectL2(config.Level2Address); StockFacade.UpdateStockAsync(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// 获取实时卖价和买价 /// </summary> /// <returns>获取实际价格(黄金,白银,铂金,钯金)</returns> public ProductRealPrice GetProductRealPrice() { TradeClient tc = new TradeClient(); ProductRealPrice PRealPrice = new ProductRealPrice(); try { PRealPrice = ComFunction.GetProductRealPrice(); PRealPrice.au_realprice = tc.GetRealprice("XAUUSD"); PRealPrice.ag_realprice = tc.GetRealprice("XAGUSD"); PRealPrice.pt_realprice = tc.GetRealprice("XPTUSD"); PRealPrice.pd_realprice = tc.GetRealprice("XPDUSD"); PRealPrice.agb_price = PRealPrice.ag_realprice - PRealPrice.agb_price; PRealPrice.aub_price = PRealPrice.au_realprice - PRealPrice.aub_price; PRealPrice.ptb_price = PRealPrice.pt_realprice - PRealPrice.ptb_price; PRealPrice.pdb_price = PRealPrice.pd_realprice - PRealPrice.pdb_price; } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return(PRealPrice); }
public void LinkToClient() { var api = new Mock <IBinanceApi>().Object; var client1 = new Mock <ITradeClient>().Object; var client2 = new TradeClient(); var symbol1 = Symbol.BTC_USDT; var symbol2 = Symbol.LTC_BTC; client2.Subscribe(symbol1); var clientSubscribeStreams = client2.SubscribedStreams.ToArray(); Assert.Equal(TradeClient.GetStreamName(symbol1), clientSubscribeStreams.Single()); var cache = new TradeCache(api, client1) { Client = client2 // link client. }; // Client subscribed streams are unchanged after link to unsubscribed cache. Assert.Equal(clientSubscribeStreams, client2.SubscribedStreams); cache.Client = client1; // unlink client. // Subscribe cache to symbol. cache.Subscribe(symbol2); // Cache is subscribed to symbol. Assert.Equal(TradeClient.GetStreamName(symbol2), cache.SubscribedStreams.Single()); cache.Client = client2; // link to client. // Client has second subscribed stream from cache. Assert.True(client2.SubscribedStreams.Count() == 2); Assert.Contains(TradeClient.GetStreamName(symbol2), client2.SubscribedStreams); }
private void BindTradeClient(TradeClient obj) { obj.PlaceReportReceived += On_Trade_Place; obj.FillReportReceived += On_Trade_Fill; obj.CancelReportReceived += On_Trade_Cancel; }
/// <summary> /// 获取实时卖价和买价 /// </summary> /// <returns>获取实际价格(黄金,白银,铂金,钯金)</returns> public ProductRealPrice GetProductRealPrice() { TradeClient tc = new TradeClient(); ProductRealPrice PRealPrice = new ProductRealPrice(); try { PRealPrice = ComFunction.GetProductRealPrice(); PRealPrice.au_realprice = tc.GetRealprice("XAUUSD"); PRealPrice.ag_realprice = tc.GetRealprice("XAGUSD"); PRealPrice.pt_realprice = tc.GetRealprice("XPTUSD"); PRealPrice.pd_realprice = tc.GetRealprice("XPDUSD"); PRealPrice.agb_price = PRealPrice.ag_realprice - PRealPrice.agb_price; PRealPrice.aub_price = PRealPrice.au_realprice - PRealPrice.aub_price; PRealPrice.ptb_price = PRealPrice.pt_realprice - PRealPrice.ptb_price; PRealPrice.pdb_price = PRealPrice.pd_realprice - PRealPrice.pdb_price; } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return PRealPrice; }
/// <summary> /// 获取实时价 /// </summary> /// <param name="pcode">商品行情编码</param> /// <returns>获取实际价格</returns> public double GetRealPrice(string pcode) { TradeClient tc = new TradeClient(); double price = 0; try { price = tc.GetRealprice(pcode); } catch (Exception ex) { tc.Abort(); ComFunction.WriteErr(ex); } return price; }
/// <summary> /// /// </summary> /// <param name="TdRate"></param> /// <returns></returns> public static int ModifyWaterAndRate(WcfInterface.model.TradeRate TdRate) { TradeClient tc = new TradeClient(); int result = 0; try { result = tc.SetRateAndWater(TdRate.PriceCode, TdRate.Rate, TdRate.Water); tc.Close(); } catch (Exception ex) { tc.Abort(); throw new Exception(ex.Message, ex); } return result; }
/// <summary> /// 删除节假日 /// </summary> /// <param name="ID"></param> public static void DelHoliday(string ID) { TradeClient tc = new TradeClient(); try { tc.DelHoliday(ID); tc.Close(); } catch (Exception) { tc.Abort(); } }
/// <summary> /// 修改交易日 /// </summary> /// <param name="DtSet"></param> public static void ModifyDateSetEx(WcfInterface.model.DateSet DtSet) { TradeClient tc = new TradeClient(); try { WcfInterface.ServiceReference1.DateSet ds = new ServiceReference1.DateSet(); ds.Desc = DtSet.Desc; ds.Endtime = DtSet.Endtime; ds.Starttime = DtSet.Starttime; ds.Istrade = !DtSet.Istrade; ds.Weekday = DtSet.Weekday; ds.PriceCode = DtSet.PriceCode; tc.ModifyDateSet(ds); tc.Close(); } catch (Exception) { tc.Abort(); } }
/// <summary> /// 修改节假日 /// </summary> /// <param name="Hliday"></param> public static void ModifyHoliday(WcfInterface.model.DateHoliday Hliday) { TradeClient tc = new TradeClient(); try { WcfInterface.ServiceReference1.DateHoliday dh = new ServiceReference1.DateHoliday(); dh.Desc = Hliday.Desc; dh.Endtime = Hliday.Endtime; dh.Starttime = Hliday.Starttime; dh.ID = Hliday.ID; dh.HoliName = Hliday.HoliName; dh.PriceCode = Hliday.PriceCode; tc.ModifyHoliday(dh); tc.Close(); } catch (Exception) { tc.Abort(); } }
/// <summary> /// 根据用户ID获取用户的盈亏 /// </summary> /// <param name="userid"></param> /// <returns></returns> public static double GetUserYingKui(string userid) { System.Data.Common.DbDataReader dbreader = null; double yingkui = 0; TradeClient tc = new TradeClient(); try { string data = string.Empty; Dictionary<string, ProPrice> prodic = tc.GetProPrice(); foreach (var item in prodic) { data += string.Format("{0},{1}|", item.Key, item.Value.realprice); } if (data.Length > 1) { data = data.Substring(0, data.Length - 1); } else { return 0; } //@data 参数格式[行情编码,价格|行情编码,价格|行情编码,价格|行情编码,价格|行情编码,价格] //存储过程proc_GetUserYingKui计算一个用户所有订单的盈亏之和 dbreader = DbHelper.RunProcedureGetDataReader("proc_GetUserYingKui", new System.Data.Common.DbParameter[] { DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type, "@userid", DbParameterType.String, userid, ParameterDirection.Input), DbHelper.CreateDbParameter(JinTong.Jyrj.Data.DataBase.Type, "@data", DbParameterType.String, data, ParameterDirection.Input) }); if (dbreader.Read()) { yingkui = System.DBNull.Value != dbreader["yingkui"] ? Convert.ToDouble(dbreader["yingkui"]) : 0; } tc.Close(); } catch (Exception ex) { tc.Abort(); throw new Exception(ex.Message, ex); } finally { if (dbreader != null) { dbreader.Close(); dbreader.Dispose(); } } return yingkui; }
/// <summary> /// 根据行情编码 获取实时价格 /// </summary> /// <param name="pcode">行情编码</param> /// <returns>实时价格</returns> public static double GetRealPrice(string pcode) { double realprice = 0; TradeClient tc = new TradeClient(); try { //WSHttpBinding binding = new WSHttpBinding(SecurityMode.None); //EndpointAddress address = new EndpointAddress(ConfigurationManager.AppSettings["wcfaddr1"]); //ChannelFactory<WcfInterface.ServiceReference1.ITrade> ttgService = new ChannelFactory<WcfInterface.ServiceReference1.ITrade>(binding, address); //realprice = ttgService.CreateChannel().GetRealprice(pcode); realprice = tc.GetRealprice(pcode); tc.Close(); } catch (Exception ex) { tc.Abort(); throw new Exception(ex.Message, ex); } return realprice; }
/// <summary> /// 获取商品时间和最新价格 /// </summary> /// <returns></returns> public static Dictionary<string, ProPrice> GetProPrice() { Dictionary<string, ProPrice> prodic = new Dictionary<string, ProPrice>(); TradeClient tc = new TradeClient(); try { prodic = tc.GetProPrice(); tc.Close(); } catch (Exception ex) { tc.Abort(); throw new Exception(ex.Message, ex); } return prodic; }
/// <summary> /// 根据周期获取最后一根柱子的信息 /// </summary> /// <param name="weekflg"></param> /// <returns></returns> public static Dictionary<string, string> GetAllLastPillar(string weekflg) { Dictionary<string, string> dic = new Dictionary<string, string>(); TradeClient tc = new TradeClient(); try { dic = tc.GetAllLastPillar(weekflg); tc.Close(); } catch (Exception ex) { tc.Abort(); throw new Exception(ex.Message, ex); } return dic; }
public void Initial(Action <string> progress, Action <long> complete) { FProgress = progress; FComplete = complete; IsReady = false; DataPipe pipe1 = null; DataPipe pipe2 = null; managers.Clear(); workers.Clear(); // 1. Create Managers var SocketTask = new SocketClient(Progress); var CollectTask = new CollectClient(Progress); var TradeTask = new TradeClient(Progress); var GenerateTask = new GenerateClient(Progress); GenerateTask.AddGetPlugAction(SocketClient.ID, SocketTask.AddGetPlug); GenerateTask.AddPutPlugAction(SocketClient.ID, SocketTask.AddPutPlug); GenerateTask.AddGetPlugAction(CollectClient.ID, CollectTask.AddGetPlug); GenerateTask.AddPutPlugAction(CollectClient.ID, CollectTask.AddPutPlug); GenerateTask.AddGetPlugAction(TradeClient.ID, TradeTask.AddGetPlug); GenerateTask.AddPutPlugAction(TradeClient.ID, TradeTask.AddPutPlug); pipe1 = new DataPipe(); pipe2 = new DataPipe(); SocketTask.AddPutPlug(CollectClient.ID, pipe1); CollectTask.AddGetPlug(SocketClient.ID, pipe1); SocketTask.AddGetPlug(CollectClient.ID, pipe2); CollectTask.AddPutPlug(SocketClient.ID, pipe2); pipe1 = new DataPipe(); pipe2 = new DataPipe(); SocketTask.AddPutPlug(TradeClient.ID, pipe1); TradeTask.AddGetPlug(SocketClient.ID, pipe1); SocketTask.AddGetPlug(TradeClient.ID, pipe2); TradeTask.AddPutPlug(SocketClient.ID, pipe2); managers.Add(new Worker(GenerateClient.ID, GenerateTask)); managers.Add(new Worker(SocketClient.ID, SocketTask)); managers.Add(new Worker(CollectClient.ID, CollectTask)); managers.Add(new Worker(TradeClient.ID, TradeTask)); //// 2. Create Workers //if (stocks != null && stocks.Count > 0) //{ // foreach (string id in stocks) // { // if(string.IsNullOrWhiteSpace(id) || workers.Any(w=>w.id.Equals(id.Trim().ToUpper())))continue; // var StockTask = new StockClient(id.Trim().ToUpper(), Progress); // pipe1 = new DataPipe(); // pipe2 = new DataPipe(); // SocketTask.AddPutPlug(StockTask.id, pipe1); // StockTask.AddGetPlug(SocketClient.ID, pipe1); // SocketTask.AddGetPlug(StockTask.id, pipe2); // StockTask.AddPutPlug(SocketClient.ID, pipe2); // pipe1 = new DataPipe(); // pipe2 = new DataPipe(); // StockTask.AddPutPlug(TradeClient.ID, pipe1); // TradeTask.AddGetPlug(StockTask.id, pipe1); // StockTask.AddGetPlug(TradeClient.ID, pipe2); // TradeTask.AddPutPlug(StockTask.id, pipe2); // pipe1 = new DataPipe(); // pipe2 = new DataPipe(); // DatabaseTask.AddPutPlug(StockTask.id, pipe1); // StockTask.AddGetPlug(DatabaseClient.ID, pipe1); // DatabaseTask.AddGetPlug(StockTask.id, pipe2); // StockTask.AddPutPlug(DatabaseClient.ID, pipe2); // workers.Add(new Worker(StockTask.id, StockTask, 1000)); // } //} IsReady = true; }