/// <summary> /// 建構子 /// </summary> /// <param name="tradeOrder">訂單資訊</param> /// <param name="symbolId">商品代號</param> /// <param name="type">回報類型</param> /// <param name="openTrades">開倉交易單列表</param> /// <param name="closeTrades">已平倉交易單列表</param> public ResponseEvent(ITradeOrder tradeOrder, string symbolId, ResponseType type, TradeList<ITrade> openTrades, List<ITrade> closeTrades) { __cTradeOrder = tradeOrder; __sSymbolId = symbolId; __cType = type; __cOpenTrades = openTrades; __cCloseTrades = closeTrades; }
void cmdShowlist(BasePlayer player, string cmd, string[] args) { if (!IsMoethorized(player)) { player.ChatMessage("Unknown command 'showlist'!"); return; } // Make sure we have a listname as param otherwise show usage if (args.Length != 1) { player.ChatMessage(FormatError("Usage: <color=yellow>/mlist</color> <color=lime>listname</color>")); return; } // Get the list and show msg if it does not exist TradeList list = GetList(args[0]); if (list == null) { player.ChatMessage(FormatError($"Trade list <color=yellow>" + args[0] + "</color> not found (it's case sensitive!)")); return; } // Generate and show the list contents var sb = new StringBuilder(); sb.Append($"Displaying trade list <color=lime>\"{list.Listname}\"</color>:"); sb.Append(list); player.ChatMessage(sb.ToString()); }
// EDIT TRADE LIST // public TradeList UpdateTradeList(TradeList updatedTradeList) { using (var db = new SqlConnection(ConnectionString)) { var editTradeListQuery = @" UPDATE [Tradelist] SET [UserId] = @userId, [CartId] = @cartId, [Name] = @name, [Genre] = @genre, [ReleaseDate] = @releaseDate, [ImageUrl] = @imageUrl WHERE id = @id"; var rowsAffected = db.Execute(editTradeListQuery, updatedTradeList); if (rowsAffected == 1) { return(updatedTradeList); } throw new Exception("Could Not Update NESVault Trade List"); } }
public void OnTrade(Trade trade) { if (_trades == null) { _trades = new TradeList(trade.CurrencyPair); } _trades.Add(trade); OutputDisruptor.Publish(trade); Log.Debug("Trade received: " + trade.ToString()); }
public ActionResult UpdateTradeList(int id, TradeList tradeListToUpdate) { if (id != tradeListToUpdate.Id) { return(BadRequest(new { Error = "NESVault Needs A Bit More Product Information." })); } var updatedMyTradeList = _tradeListRepository.UpdateTradeList(tradeListToUpdate); return(Ok(updatedMyTradeList)); }
/// <summary> /// 建構子 /// </summary> /// <param name="tradeOrder">訂單資訊</param> /// <param name="symbolId">商品代號</param> /// <param name="type">回報類型</param> /// <param name="openTrades">開倉交易單列表</param> /// <param name="closeTrades">已平倉交易單列表</param> /// <param name="latestHistoryCount">最近新增的歷史交易紀錄個數</param> public ResponseEvent(ITradeOrder tradeOrder, string symbolId, ResponseType type, TradeList <ITrade> openTrades, List <ITrade> closeTrades, int latestHistoryCount) { __cTradeOrder = tradeOrder; __sSymbolId = symbolId; __cType = type; __cOpenTrades = openTrades; __cCloseTrades = closeTrades; __iLatestHistoryCount = latestHistoryCount; __iLatestHistoryIndex = (__iLatestHistoryCount == 0) ? -1 : closeTrades.Count - latestHistoryCount; }
/// <summary> /// 建構子 /// </summary> public SimulateOrderService() { __cReserves = new Queue<string>(16); __cDeals = new Queue<TradeOrder>(16); __cEntrusts = new TradeList<TradeOrder>(64); __cNextBarRequires = new HashSet<string>(); __cPNextBarRequires = new HashSet<string>(); __cCurrentPosition = new MarketPosition(16); //建立目前留倉部位 __cPositions = new PositionSeries(); //建立留倉部位陣列 __cPositions.Value = __cCurrentPosition; }
public void TestDecreasingUnitPrice() { Assert.AreEqual(1, TradeList.DecreasingUnitPrice(cheap, expensive)); Assert.AreEqual(0, TradeList.DecreasingUnitPrice(cheap, cheap)); Assert.AreEqual(-1, TradeList.DecreasingUnitPrice(expensive, cheap)); Assert.AreEqual(1, TradeList.DecreasingUnitPrice(zero, cheap)); Assert.AreEqual(0, TradeList.DecreasingUnitPrice(zero, zero)); Assert.AreEqual(-1, TradeList.DecreasingUnitPrice(expensive, zero)); Assert.AreEqual(1, TradeList.DecreasingUnitPrice(cheap, oneExpensive)); Assert.AreEqual(0, TradeList.DecreasingUnitPrice(oneExpensive, expensive)); Assert.AreEqual(-1, TradeList.DecreasingUnitPrice(expensive, oneCheap)); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void test_portfolios() throws Exception public virtual void test_portfolios() { File baseDir = new File("src/main/resources/example-portfolios"); assertTrue(baseDir.exists()); foreach (File file in baseDir.listFiles(f => f.Name.EndsWith(".xml"))) { using (FileStream @in = new FileStream(file, FileMode.Open, FileAccess.Read)) { TradeList tradeList = JodaBeanSer.COMPACT.xmlReader().read(@in, typeof(TradeList)); assertTrue(tradeList.Trades.size() > 0); } } }
public override Task <TradeList> GetOpenTrades(Empty e, ServerCallContext context) { TradeList tl = new TradeList(); var q = from t in db.Trades .Include(l => l.TradeItemList) .ThenInclude(y => y.TradeItemDetails) .ThenInclude(z => z.Item) select t; foreach (var trade in q) { tl.Trades.Add(trade); } return(Task.FromResult(tl)); }
/// <summary> /// 建構子 /// </summary> public RealOrderService() { this.ApiNumber = 1; //預設通道編號 this.PipeNumber = 1; //預設通道編號 __cDeals = new Queue<TradeOrder>(16); __cReserves = new Queue<string>(16); __cEntrusts = new TradeList<TradeOrder>(64); __cNextBarRequires = new HashSet<string>(); __cPNextBarRequires = new HashSet<string>(); __cCurrentPosition = new MarketPosition(16); //建立目前留倉部位 __cPositions = new PositionSeries(); //建立留倉部位陣列 __cPositions.Value = __cCurrentPosition; __cResetEvent = new AutoResetEvent(false); }
void CreateExampleSalesLists() { var exampleList = new TradeList("list1"); exampleList.Offers.Add(new TradeOffer(new Product("Wood", 1000), new[] { new Product("Salvaged Axe", 1) })); exampleList.Offers.Add(new TradeOffer(new Product("Metal Ore", 1000), new[] { new Product("Pick Axe", 1) })); g_config.TradeLists.Add(exampleList.Listname, exampleList); exampleList = new TradeList("list2"); exampleList.Offers.Add(new TradeOffer(new Product("Cloth", 500), new[] { new Product("Animal Fat", 250) })); exampleList.Offers.Add(new TradeOffer(new Product("Animal Fat", 250), new[] { new Product("Cloth", 500) })); g_config.TradeLists.Add(exampleList.Listname, exampleList); exampleList = new TradeList("list3"); exampleList.Offers.Add(new TradeOffer(new Product("Metal Fragments", 2500), new[] { new Product("Assault Rifle", 1), new Product("5.56 Rifle Ammo", 100) })); g_config.TradeLists.Add(exampleList.Listname, exampleList); }
public void ExecuteTrade(Order order, List <Order> matchingOrders) { Trade trade = new Trade(order.Symbol, order.Exchange); long quantityRequired = order.Quantity; //if (order.Transaction == TransactionType.Buy) { foreach (var sOrder in matchingOrders) { //Single seller has sufficient Quantity if (quantityRequired <= sOrder.Quantity) { trade.UpdateTrade(sOrder.Price, quantityRequired); } else { trade.UpdateTrade(sOrder.Price, sOrder.Quantity); } if (quantityRequired == trade.Quantity || sOrder.Quantity == trade.Quantity) { //Trade Finished TradeCompleted?.Invoke(this, new TradeCompletedEventArgs(trade)); if (order.Quantity == trade.Quantity) { sOrder.Quantity -= trade.Quantity; order.Status = OrderStatus.Completed; order.OrderSubmitted(OrderStatus.Completed); if (sOrder.Quantity == 0) { sOrder.Status = OrderStatus.Completed; } } else { order.Quantity -= trade.Quantity; sOrder.Status = OrderStatus.Completed; sOrder.OrderSubmitted(OrderStatus.Completed); } break; } } TradeList.Add(trade); } }
public override Task <TradeList> GetUserTrades(User u, ServerCallContext context) { TradeList tl = new TradeList(); var q = from t in db.Trades .Include(l => l.TradeItemList) .ThenInclude(y => y.TradeItemDetails) .ThenInclude(z => z.Item) join x in db.TradeUsers on u.Id equals x.UserId where t.Id == x.TradeId && x.State.Description == _States._TradeUser.JOINED select t; foreach (var trade in q) { tl.Trades.Add(trade); } return(Task.FromResult(tl)); }
/// <summary> /// Initializes a new instance of the <see cref="EntityRegistry"/>. /// </summary> /// <param name="storage">The special interface for direct access to the storage.</param> public EntityRegistry(IStorage storage) { if (storage == null) throw new ArgumentNullException(nameof(storage)); Storage = storage; ConfigManager.TryRegisterService(storage); Exchanges = new ExchangeList(storage) { BulkLoad = true }; ExchangeBoards = new ExchangeBoardList(storage) { BulkLoad = true }; Securities = new SecurityList(this); Trades = new TradeList(storage); MyTrades = new MyTradeList(storage); Orders = new OrderList(storage); OrderFails = new OrderFailList(storage); Portfolios = new PortfolioList(storage); Positions = new PositionList(storage); News = new NewsList(storage); }
internal bool AddTrades(TradeList <ITrade> openTrades, List <ITrade> historyTrades) { bool bRet = false; if (openTrades == null) { int iCount = historyTrades.Count; for (int i = 0; i < iCount; i++) { ITrade cTrade = historyTrades[i]; AddTradeFromRange(__cHistoryTrades, cTrade.EntryOrder.BarNumber, cTrade.ExitOrder.BarNumber, cTrade); } __cLastOpenTrade = null; __cOpenTrades.Clear(); bRet = true; } else { int iHistoruCount = historyTrades.Count; if (iHistoruCount > __iPrevHistorys) { __iPrevHistorys = iHistoruCount; bRet = true; } int iIndex = openTrades.Count - 1; if (iIndex > -1) { ITrade cTrade = openTrades[iIndex]; if (__cLastOpenTrade != cTrade) { AddTradeFromRange(__cOpenTrades, cTrade.EntryOrder.BarNumber, 0, cTrade); __cLastOpenTrade = cTrade; bRet = true; } } } return(bRet); }
void cmdLinkBox(BasePlayer player, string cmd, string[] args) { if (!IsMoethorized(player)) { player.ChatMessage("Unknown command 'linkbox'!"); return; } var sb = new StringBuilder(); var currentCommand = GetActiveCommand(player); if (currentCommand != null) { ClearActiveCommand(player); sb.Append($"<color=yellow>{currentCommand}</color> mode is now <color=red>OFF</color>\n"); } if (args.Length != 1) { sb.Append(FormatError("Usage: <color=yellow>/mlink</color> <color=lime>listname</color>")); player.ChatMessage(sb.ToString()); return; } TradeList list = GetList(args[0]); if (list == null) { sb.Append(FormatError("Trade list <color=yellow>" + args[0] + "</color> not found (check case)")); player.ChatMessage(sb.ToString()); return; } SetActiveCommand(player, $"linkbox {args[0]}"); sb.Append($"<color=yellow>linkbox</color> mode is now <color=lime>ON</color>\nOpen the container you wish to associate with <color=yellow>{args[0]}</color>"); player.ChatMessage(sb.ToString()); }
/// <summary> /// 發送回報事件 /// </summary> /// <param name="order">下單資訊</param> /// <param name="symbolId">商品代號</param> /// <param name="type">回報類型</param> /// <param name="openTrades">開倉交易單列表</param> /// <param name="closeTrades">已平倉交易單列表</param> /// <param name="latestHistoryCount">最近新增的歷史交易紀錄個數</param> protected void OnResponse(ITradeOrder order, string symbolId, ResponseType type, TradeList<ITrade> openTrades = null, List<ITrade> closeTrades = null, int latestHistoryCount = 0) { if (onResponse != null) { onResponse(this, new ResponseEvent(order, symbolId, type, openTrades, closeTrades, latestHistoryCount)); } }
private void TradeTimer_onElapsed(object sender, ElapsedEventArgs e) { bool bBusy = false; lock (__oLock) { bBusy = __bTradeBusy; if (!bBusy) { __bTradeBusy = true; } } if (!bBusy) { bool bUpdate = __cQueue.Count > 0; while (__cQueue.Count > 0) { ResponseEvent cResponse = null; lock (__cQueue) { cResponse = __cQueue.Dequeue(); } ResponseType cType = cResponse.ResponseType; if (cType == ResponseType.Update) { continue; } string sSymbolId = cResponse.SymbolId; ITradeOrder cOrder = cResponse.TradeOrder; string sTicket = cOrder.Ticket; switch (cType) { case ResponseType.Cancel: //取消委託 case ResponseType.Trust: //委託回報 if (cType == ResponseType.Cancel) { __cTrusts.Remove(sTicket); } else { if (cOrder.Contracts == 0) { __cTrusts.Remove(sTicket); } else { __cTrusts.Add(new _TradeInfo(cOrder, sSymbolId)); } } break; case ResponseType.Deal: //成交回報 EOrderAction cAction = cOrder.Action; if (cAction == EOrderAction.Buy || cAction == EOrderAction.SellShort) { TradeList <ITrade> cOpenTrades = cResponse.OpenTrades; if (cOpenTrades != null && cOpenTrades.Count > 0) { ITrade cTrade = cOpenTrades.GetTrade(sTicket); if (cTrade != null) { __cOpens.Add(new _TradeInfo(cTrade, sSymbolId)); } } } else { List <ITrade> cCloseTrades = cResponse.CloseTrades; int iHistoryCount = cResponse.LatestHistoryCount; if (iHistoryCount > 0) { int iHistoryIndex = cResponse.LatestHistoryIndex; if (iHistoryIndex > -1) { for (int i = 0; i < iHistoryCount; i++) { ITrade cTrade = cCloseTrades[iHistoryIndex + i]; __cCloses.Add(new _TradeInfo(cTrade.EntryOrder, sSymbolId, 0)); __cCloses.Add(new _TradeInfo(cTrade.ExitOrder, sSymbolId, cTrade.Profit)); if (cTrade.IsTradeClosed) { __cOpens.Remove(cTrade.Ticket); } } } } } break; } } if (bUpdate) { __cUpdateTimer.Start(); onUpdate(this, EventArgs.Empty); } lock (__oLock) { __bTradeBusy = false; } } }
/// <summary> /// 發送回報事件 /// </summary> /// <param name="order">下單資訊</param> /// <param name="symbolId">商品代號</param> /// <param name="type">回報類型</param> /// <param name="openTrades">開倉交易單列表</param> /// <param name="closeTrades">已平倉交易單列表</param> protected void OnResponse(ITradeOrder order, string symbolId, ResponseType type, TradeList<ITrade> openTrades = null, List<ITrade> closeTrades = null) { if (onResponse != null) { onResponse(this, new ResponseEvent(order, symbolId, type, openTrades, closeTrades)); } }
void RunCommand(BasePlayer player, string command, BaseEntity box) { var currentTradeList = GetActiveList(box); //********************************************* // RECYCLEBOX //********************************************* if (command.StartsWith("recyclebox")) { // Make sure the box is not already associated with a list if (currentTradeList != null) { player.ChatMessage($"This box is already associated with <color=yellow>{currentTradeList}</color>!"); return; } else { // Check if we have the price and if so, remove if (!HasPrice(player)) { player.ChatMessage(FormatError(GetPriceString())); return; } foreach (var price in g_config.RecyclerPrice) { var removed = RemoveItemsFromInventory(player, price.Key, price.Value); if (removed != price.Value) { Puts($"Oh snap! Tried to remove {price.Value} X {price.Key} but only {removed} were found --- this should not happen, contact the author"); } } // Link the box g_config.BoxLinks.Add(box.MoegicId(), "recycling"); g_config.Save(); // Report success player.ChatMessage($"Box is now a <color=yellow>Moegic Recycling Box</color>!"); return; } } //********************************************* // LINKBOX //********************************************* if (command.StartsWith("linkbox")) { // Make sure the box is not already associated with a list if (currentTradeList != null) { player.ChatMessage(FormatError("This box is already associated with <color=lime>" + currentTradeList + "</color>, use <color=yellow>/unlinkbox</color> first")); return; } // Make sure the new list we're trying to assign actually exists var listName = command.Split(new[] { ' ' }).Last(); TradeList list = GetList(listName); if (list == null) { player.ChatMessage(FormatError("Trade list <color=yellow>" + listName + "</color> not found (check case)")); return; } // Link the box g_config.BoxLinks.Add(box.MoegicId(), listName); g_config.Save(); // Report success player.ChatMessage($"Box associated with <color=yellow>{listName}</color> successfully!"); return; } //********************************************* // UNLINKBOX //********************************************* if (command.StartsWith("unlinkbox")) { // Abort if no list is currently associated with the box if (currentTradeList == null) { player.ChatMessage(FormatError("This box is not linked with any list!")); return; } if (currentTradeList != "recycling" && !IsMoethorized(player)) { player.ChatMessage(FormatError("You do not have the required access to unlink this box")); return; } // Unlink the box g_config.BoxLinks.Remove(box.MoegicId()); g_config.Save(); // Report success player.ChatMessage($"Box successfully unlinked from <color=yellow>{currentTradeList}</color>"); return; } }