/// <summary> /// Copy an order book entry object which is an exact and deep copy of /// the original. /// </summary> /// <param name="copy">The MamdaOrderBookEntry to deep copy.</param> public void copy(MamdaOrderBookEntry copy) { mId = copy.mId; mSize = copy.mSize; mAction = copy.mAction; mTime = copy.mTime; }
/// <summary> /// Add a new order book entry to the price level. /// </summary> /// <param name="entry">The new entry to be added to the level.</param> public void addEntry(MamdaOrderBookEntry entry) { if (mStrictChecking) { checkNotExist(entry); } mEntries.Add(entry); }
void getEntryInfo( MamdaOrderBookEntry entry, MamaMsg entMsg, MamdaOrderBookPriceLevel level) { entry.setAction((MamdaOrderBookEntry.Actions)entMsg.getChar( MamdaOrderBookFields.ENTRY_ACTION, 'D')); entry.setId(entMsg.getString(MamdaOrderBookFields.ENTRY_ID)); entry.setSize((long)entMsg.getF64(MamdaOrderBookFields.ENTRY_SIZE, 0)); entry.setTime(entMsg.getDateTime(MamdaOrderBookFields.ENTRY_TIME, level.getTime())); }
/// <summary> /// If the provided order book entry exists in the price level a /// <code>MamdaOrderBookException</code> exception is thrown. Otherwise the /// method simply returns. /// </summary> /// <param name="entry">The entry whose presence in the level is being determined.</param> /// <exception cref="MamdaOrderBookException">Throws MamdaOrderBookException if the entry is found in the price</exception> public void checkNotExist(MamdaOrderBookEntry entry) { for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry existingEntry = (MamdaOrderBookEntry)mEntries[i]; if (existingEntry.equalId(entry.getId())) { throw new MamdaOrderBookException( "attempted to add am existent entry: " + entry.getId()); } } }
/// <summary> /// Mark everything in this price level as deleted, including /// entries. /// </summary> public void markAllDeleted() { setSizeChange(-getSize()); setSize(0); setNumEntries(0); setAction(Actions.Delete); for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry entry = (MamdaOrderBookEntry)mEntries[i]; entry.setSize(0); entry.setAction(MamdaOrderBookEntry.Actions.Delete); } }
/// <summary> /// Construct a price level object which is a shallow copy of /// the original. /// </summary> /// <param name="copy">The MamdaOrderBookPriceLevel to copy.</param> public MamdaOrderBookPriceLevel(MamdaOrderBookPriceLevel copy) { mPrice = copy.mPrice; mSize = copy.mSize; mSizeChange = copy.mSizeChange; mNumEntries = copy.mNumEntries; mSide = copy.mSide; mAction = copy.mAction; mTime = copy.mTime; for (int i = 0; i < copy.mEntries.Count; i++) { MamdaOrderBookEntry entry = new MamdaOrderBookEntry( (MamdaOrderBookEntry)copy.mEntries[i]); mEntries.Add(entry); } }
/// <summary> /// Copy a price level object which is an exact and deep copy of /// the original. /// </summary> /// <param name="copy">The MamdaOrderBookPriceLevel to copy.</param> public void copy(MamdaOrderBookPriceLevel copy) { setPrice(copy.mPrice); setSize(copy.mSize); setSizeChange(copy.mSizeChange); setNumEntries(copy.mNumEntries); setSide(copy.mSide); setAction(copy.mAction); setTime(copy.mTime); // always deep copied for (int i = 0; i < copy.mEntries.Count; i++) { MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); entry.copy((MamdaOrderBookEntry)copy.mEntries[i]); mEntries.Add(entry); } }
/// <summary> /// Remove an order book entry from the price level. /// <see cref="MamdaOrderBookEntry"/> /// </summary> /// <param name="entry">The entry which is to be removed from the price level.</param> public void removeEntry(MamdaOrderBookEntry entry) { for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry existingEntry = (MamdaOrderBookEntry)mEntries[i]; if (existingEntry.equalId(entry.getId())) { mEntries.RemoveAt(i); return; } } if (mStrictChecking) { throw new MamdaOrderBookException( "attempted to delete a non-existent entry: " + entry.getId()); } }
private int findEntryAfter( ArrayList entries, int start, string id) { int i; int size = entries.Count; for (i = start; i < size; i++) { MamdaOrderBookEntry entry = (MamdaOrderBookEntry)entries[i]; if (entry.equalId(id)) { return(i); } } return(i); }
/// <summary> /// Update the details of an existing entry in the level. /// </summary> /// <param name="entry">An instance of <code>MamdaOrderBookEntry</code> with the /// new details for the entry in the level.</param> public void updateEntry(MamdaOrderBookEntry entry) { for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry existingEntry = (MamdaOrderBookEntry)mEntries[i]; if (existingEntry.equalId(entry.getId())) { existingEntry.setDetails(entry); return; } } if (mStrictChecking) { throw new MamdaOrderBookException( "attempted to update a non-existent entry: " + entry.getId()); } }
/// <summary> /// Order book entry equality verification. A /// MamdaOrderBookException is thrown if the entries within a price /// level are not equal, along with the reason for the inequality. /// </summary> /// <param name="rhs"></param> /// <exception cref="MamdaOrderBookException">MamdaOrderBookException</exception> public void assertEqual(MamdaOrderBookEntry rhs) { if (mId != rhs.mId) { throw new MamdaOrderBookException("entry IDs not equal"); } if (mSize != rhs.mSize) { throw new MamdaOrderBookException("entry size not equal"); } if (mAction != rhs.mAction) { throw new MamdaOrderBookException("entry action not equal"); } if (mTime != rhs.mTime) { throw new MamdaOrderBookException("entry time not equal"); } }
/// <summary> /// Order book price level equality verification. A /// is thrown if the price levels are /// not equal, along with the reason for the inequality. /// </summary> /// <param name="rhs"></param> /// <exception cref="MamdaOrderBookException">MamdaOrderBookException is thrown if the price levels are</exception> public void assertEqual(MamdaOrderBookPriceLevel rhs) { if ((mPrice != null) != (rhs.mPrice != null)) { throwError("price not equal"); } if (!mPrice.equals(rhs.mPrice)) { throwError("price not equal"); } if (mSize != rhs.mSize) { throwError("size not equal"); } if (mNumEntries != rhs.mNumEntries) { throwError("number of entries not equal"); } if (mSide != rhs.mSide) { throwError("side not equal"); } if (mAction != rhs.mAction) { throwError("action not equal"); } if (mTime != rhs.mTime) { throwError("time not equal"); } if (mEntries.Count != rhs.mEntries.Count) { throwError("entries size mismatch (" + mEntries.Count + "!=" + rhs.mEntries.Count); } for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry lhsEntry = (MamdaOrderBookEntry)mEntries[i]; MamdaOrderBookEntry rhsEntry = (MamdaOrderBookEntry)rhs.mEntries[i]; lhsEntry.assertEqual(rhsEntry); } }
/// <summary> /// </summary> /// <param name="copy"></param> public void setDetails(MamdaOrderBookEntry copy) { mSize = copy.mSize; mTime = copy.mTime; }
/// <summary> /// Copy an order book entry object which is a deep copy of /// the original. /// </summary> /// <param name="copy">The MamdaOrderBookEntry to copy.</param> public MamdaOrderBookEntry(MamdaOrderBookEntry copy) { this.copy(copy); }
/// <summary> /// Order book entry equality verification. A /// MamdaOrderBookException is thrown if the entries within a price /// level are not equal, along with the reason for the inequality. /// </summary> /// <param name="rhs"></param> /// <exception cref="MamdaOrderBookException">MamdaOrderBookException</exception> public void assertEqual(MamdaOrderBookEntry rhs) { if (mId != rhs.mId) throw new MamdaOrderBookException("entry IDs not equal"); if (mSize != rhs.mSize) throw new MamdaOrderBookException("entry size not equal"); if (mAction != rhs.mAction) throw new MamdaOrderBookException("entry action not equal"); if (mTime != rhs.mTime) throw new MamdaOrderBookException("entry time not equal"); }
/// <summary> /// </summary> /// <param name="lhs"></param> /// <param name="rhs"></param> public void setAsDifference( MamdaOrderBookPriceLevel lhs, MamdaOrderBookPriceLevel rhs) { int lhsBookSize = lhs.mEntries.Count; int rhsBookSize = rhs.mEntries.Count; int lhsIndex = 0; int rhsIndex = 0; while ((lhsIndex < lhsBookSize) && (rhsIndex < rhsBookSize)) { string lhsId = null; string rhsId = null; long lhsSize = 0; long rhsSize = 0; MamdaOrderBookEntry lhsEntry = null; MamdaOrderBookEntry rhsEntry = null; if (lhsIndex < lhsBookSize) { lhsEntry = (MamdaOrderBookEntry)lhs.mEntries[lhsIndex]; lhsId = lhsEntry.getId(); lhsSize = lhsEntry.getSize(); } if (rhsIndex < rhsBookSize) { rhsEntry = (MamdaOrderBookEntry)rhs.mEntries[rhsIndex]; rhsId = rhsEntry.getId(); rhsSize = rhsEntry.getSize(); } if ((lhsId != null) && (rhsId != null)) { if (lhsId == rhsId) { // Same ID, maybe different size. if (lhsSize != rhsSize) { MamdaOrderBookEntry updateEntry = new MamdaOrderBookEntry(rhsEntry); updateEntry.setAction(MamdaOrderBookEntry.Actions.Update); addEntry(updateEntry); } lhsIndex++; rhsIndex++; continue; } else { // Different ID (either something exists on the LHS // and not on RHS or vice versa). int rhsFound = findEntryAfter(rhs.mEntries, rhsIndex, lhsId); if (rhsFound != rhsSize) { // The ID from the LHS was found on the RHS, so // there must have been additional entries on the // RHS, which we now need to add. do { addEntry((MamdaOrderBookEntry)rhs.mEntries[rhsIndex]); rhsIndex++; } while (rhsIndex < rhsFound); } else { // The ID from the LHS was not present on the RHS, // so add the LHS entry. Note: it would probably // be faster to iterate over the LHS side rather // than begin the loop again. addEntry((MamdaOrderBookEntry)lhs.mEntries[lhsIndex]); lhsIndex++; } } } } if (mPrice != null && rhs.getPrice() != null) { mPrice.destroy(); } mPrice = rhs.getPrice(); setSizeChange(rhs.getSize() - lhs.getSize()); setSize(rhs.getSize()); setNumEntries(rhs.getNumEntries()); setAction(Actions.Update); mTime = rhs.getTime(); setSide(rhs.getSide()); }
/// <summary> /// Remove an order book entry from the price level. /// <see cref="MamdaOrderBookEntry"/> /// </summary> /// <param name="entry">The entry which is to be removed from the price level.</param> public void removeEntry(MamdaOrderBookEntry entry) { for (int i = 0; i < mEntries.Count; i++) { MamdaOrderBookEntry existingEntry = (MamdaOrderBookEntry)mEntries[i]; if (existingEntry.equalId(entry.getId())) { mEntries.RemoveAt(i); return; } } if (mStrictChecking) { throw new MamdaOrderBookException ( "attempted to delete a non-existent entry: " + entry.getId()); } }
private void getEntries( MamdaOrderBookPriceLevel level, MamaMsg plMsg) { /* Entries may or may not exist in the message. If they do exist, * they exist as a vector of submessages, separate submessages, or * (if there is only one entry in the message) in the price level * message itself. */ /* Optional order book fields: */ MamaMsg[] msgEntries = null; /*We won't have PL_ENTRIES if FieldAttrsOrderBookWombatMsg is not specified in the data dictionary*/ if (MamdaOrderBookFields.PL_ENTRIES != null) { /* null is passed as default value otherwise getVectorMsg throws an exception if not found*/ msgEntries = plMsg.getVectorMsg(MamdaOrderBookFields.PL_ENTRIES, null); } if (msgEntries != null) { MamdaOrderBookEntry[] entries = new MamdaOrderBookEntry[msgEntries.Length]; for (int j = 0; j < msgEntries.Length; j++) { MamaMsg entMsg = msgEntries[j]; if (entMsg != null) { MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, entMsg, level); level.addEntry(entry); } } return; } /* Second, try the list of entries. */ int maxEntryFields = MamdaOrderBookFields.PL_ENTRY.Length; // Get the number of attached sub messages int numEntryAttached = plMsg.getI32(MamdaOrderBookFields.PL_NUM_ATTACH, 0); // If there are no sub messages attempt to get the entry Id from this price level message if (0 == numEntryAttached) { string entID = null; // Check for the entry Id if (plMsg.tryString(MamdaOrderBookFields.ENTRY_ID, ref entID)) { // Add a new entry to the level MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, plMsg, level); level.addEntry(entry); } } else { // Ensure we dont' enumerate beyond the maximum number of entries if (numEntryAttached < maxEntryFields) { maxEntryFields = numEntryAttached; } // Enumerate all the entries for (int j = 1; j <= maxEntryFields; j++) { // Get the sub message MamaMsg entMsg = plMsg.getMsg(MamdaOrderBookFields.PL_ENTRY[j], null); if (entMsg != null) { // Add an entry for this level MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, entMsg, level); level.addEntry(entry); } } } }
/// <summary> /// Enforce strict checking of order book modifications (at the /// expense of some performance). This setting is passed on to the /// MamdaOrderBookPriceLevel and MamdaOrderBookEntry classes. /// </summary> /// <param name="strict"></param> public static void setStrictChecking(bool strict) { MamdaOrderBookPriceLevel.setStrictChecking(strict); MamdaOrderBookEntry.setStrictChecking(strict); }
/// <summary> /// </summary> /// <param name="lhs"></param> /// <param name="rhs"></param> public void setAsDifference( MamdaOrderBookPriceLevel lhs, MamdaOrderBookPriceLevel rhs) { int lhsBookSize = lhs.mEntries.Count; int rhsBookSize = rhs.mEntries.Count; int lhsIndex = 0; int rhsIndex = 0; while ((lhsIndex < lhsBookSize) && (rhsIndex < rhsBookSize)) { string lhsId = null; string rhsId = null; long lhsSize = 0; long rhsSize = 0; MamdaOrderBookEntry lhsEntry = null; MamdaOrderBookEntry rhsEntry = null; if (lhsIndex < lhsBookSize) { lhsEntry = (MamdaOrderBookEntry)lhs.mEntries[lhsIndex]; lhsId = lhsEntry.getId(); lhsSize = lhsEntry.getSize(); } if (rhsIndex < rhsBookSize) { rhsEntry = (MamdaOrderBookEntry)rhs.mEntries[rhsIndex]; rhsId = rhsEntry.getId(); rhsSize = rhsEntry.getSize(); } if ((lhsId != null) && (rhsId != null)) { if (lhsId == rhsId) { // Same ID, maybe different size. if (lhsSize != rhsSize) { MamdaOrderBookEntry updateEntry = new MamdaOrderBookEntry(rhsEntry); updateEntry.setAction(MamdaOrderBookEntry.Actions.Update); addEntry(updateEntry); } lhsIndex++; rhsIndex++; continue; } else { // Different ID (either something exists on the LHS // and not on RHS or vice versa). int rhsFound = findEntryAfter(rhs.mEntries, rhsIndex, lhsId); if (rhsFound != rhsSize) { // The ID from the LHS was found on the RHS, so // there must have been additional entries on the // RHS, which we now need to add. do { addEntry((MamdaOrderBookEntry)rhs.mEntries[rhsIndex]); rhsIndex++; }while (rhsIndex < rhsFound); } else { // The ID from the LHS was not present on the RHS, // so add the LHS entry. Note: it would probably // be faster to iterate over the LHS side rather // than begin the loop again. addEntry((MamdaOrderBookEntry)lhs.mEntries[lhsIndex]); lhsIndex++; } } } } if (mPrice != null && rhs.getPrice() != null) { mPrice.destroy(); } mPrice = rhs.getPrice(); setSizeChange(rhs.getSize() - lhs.getSize()); setSize(rhs.getSize()); setNumEntries(rhs.getNumEntries()); setAction(Actions.Update); mTime = rhs.getTime(); setSide(rhs.getSide()); }
private void getEntries( MamdaOrderBookPriceLevel level, MamaMsg plMsg) { /* Entries may or may not exist in the message. If they do exist, * they exist as a vector of submessages, separate submessages, or * (if there is only one entry in the message) in the price level * message itself. */ /* Optional order book fields: */ MamaMsg[] msgEntries = null; /*We won't have PL_ENTRIES if FieldAttrsOrderBookWombatMsg * is not specified in the data dictionary*/ if (MamdaOrderBookFields.PL_ENTRIES != null) { /* null is passed as default value otherwise * getVectorMsg throws an exception if not found*/ msgEntries = plMsg.getVectorMsg(MamdaOrderBookFields.PL_ENTRIES, null); } if (msgEntries != null) { MamdaOrderBookEntry[] entries = new MamdaOrderBookEntry[msgEntries.Length]; for (int j = 0; j < msgEntries.Length; j++) { MamaMsg entMsg = msgEntries[j]; if (entMsg != null) { MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, entMsg, level); level.addEntry(entry); } } return; } /* Second, try the list of entries. */ int maxEntryFields = MamdaOrderBookFields.PL_ENTRY.Length; // Get the number of attached sub messages int numEntryAttached = plMsg.getI32(MamdaOrderBookFields.PL_NUM_ATTACH, 0); // If there are no sub messages attempt to get the entry Id from this price level message if (0 == numEntryAttached) { string entID = null; // Check for the entry Id if (plMsg.tryString(MamdaOrderBookFields.ENTRY_ID, ref entID)) { // Add a new entry to the level MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, plMsg, level); level.addEntry(entry); } } else { // Ensure we dont' enumerate beyond the maximum number of entries if (numEntryAttached < maxEntryFields) { maxEntryFields = numEntryAttached; } // Enumerate all the entries for (int j = 1; j <= maxEntryFields; j++) { // Get the sub message MamaMsg entMsg = plMsg.getMsg(MamdaOrderBookFields.PL_ENTRY[j], null); if (entMsg != null) { // Add an entry for this level MamdaOrderBookEntry entry = new MamdaOrderBookEntry(); getEntryInfo(entry, entMsg, level); level.addEntry(entry); } } } }