public static string ToTopic(string tickerSymbol, TradeEventType tradeEventType)
        {
            string ToStr(TradeEventType e)
            {
                switch (e)
                {
                case TradeEventType.Ask:
                    return("Ask");

                case TradeEventType.Bid:
                    return("Bid");

                case TradeEventType.Fill:
                    return("Fill");

                case TradeEventType.Match:
                    return("Match");

                default:
                    throw new ArgumentOutOfRangeException(nameof(e));
                }
            }

            return($"{tickerSymbol}-{ToStr(tradeEventType)}");
        }
 private void EnsureSub(TradeEventType e)
 {
     if (!_subscribers.ContainsKey(e))
     {
         _subscribers[e] = new HashSet <IActorRef>();
     }
 }
Beispiel #3
0
 private void HuobiExchange_TradeInfoEvent(TradingInfo ti, TradeEventType tt)
 {
     if (TickerEvent != null && tt == TradeEventType.TRADE)
     {
         TickerEvent(this, ti.t, (CommonLab.EventTypes)ti.type, ti.tp);
     }
     if (DepthEvent != null && tt == TradeEventType.ORDERS)
     {
         DepthEvent(this, ti.d, (CommonLab.EventTypes)ti.type, ti.tp);
     }
 }
Beispiel #4
0
 public TradeDetailsMessageData(
     TradeEventType eventType,
     string symbol,
     long orderId,
     decimal tradePrice,
     decimal tradeVolume,
     OrderSide orderSide,
     OrderType orderType,
     bool aggressor,
     long tradeId,
     DateTimeOffset tradeTime,
     decimal transactionFee,
     string feeCurrency,
     decimal feeDeduct,
     string feeDeductType,
     long accountId,
     string source,
     decimal orderPrice,
     decimal orderSize,
     decimal orderValue,
     string clientOrderId,
     decimal stopPrice,
     string @operator,
     DateTimeOffset orderCreateTime,
     OrderStatus orderStatus)
 {
     EventType       = eventType;
     Symbol          = symbol;
     OrderId         = orderId;
     TradePrice      = tradePrice;
     TradeVolume     = tradeVolume;
     OrderSide       = orderSide;
     OrderType       = orderType;
     Aggressor       = aggressor;
     TradeId         = tradeId;
     TradeTime       = tradeTime;
     TransactionFee  = transactionFee;
     FeeCurrency     = feeCurrency;
     FeeDeduct       = feeDeduct;
     FeeDeductType   = feeDeductType;
     AccountId       = accountId;
     Source          = source;
     OrderPrice      = orderPrice;
     OrderSize       = orderSize;
     OrderValue      = orderValue;
     ClientOrderId   = clientOrderId;
     StopPrice       = stopPrice;
     Operator        = @operator;
     OrderCreateTime = orderCreateTime;
     OrderStatus     = orderStatus;
 }
 public void ShouldFormatDistributedPubSubTopic(string ticker, TradeEventType tradeEvent, string expectedTopic)
 {
     ToTopic(ticker, tradeEvent).Should().Be(expectedTopic);
 }
Beispiel #6
0
 public Task <TradeUnsubscribeAck> Unsubscribe(string tickerSymbol, TradeEventType @event, IActorRef subscriber)
 {
     return(Unsubscribe(tickerSymbol, new[] { @event }, subscriber));
 }
Beispiel #7
0
 public void ShouldMatchEventWithTradeType(ITradeEvent tradeEvent, TradeEventType expectedType)
 {
     tradeEvent.ToTradeEventType().Should().Be(expectedType);
 }
Beispiel #8
0
        /// <summary>
        /// This updates the trade.  This is called at an interval of a
        /// default of 800ms, not including the execution time of the
        /// method itself.
        /// </summary>
        /// <returns><c>true</c> if the other trade partner performed an action; otherwise <c>false</c>.</returns>
        public bool Poll()
        {
            bool otherDidSomething = false;

            if (!TradeStarted)
            {
                tradeStarted = true;

                // since there is no feedback to let us know that the trade
                // is fully initialized we assume that it is when we start polling.
                if (OnAfterInit != null)
                {
                    OnAfterInit();
                }
            }

            TradeStatus status = session.GetStatus();

            if (status == null)
            {
                throw new TradeException("The web command to get the trade status failed.");
            }

            switch (status.trade_status)
            {
            // Nothing happened. i.e. trade hasn't closed yet.
            case 0:
                break;

            // Successful trade
            case 1:
                HasTradeCompletedOk = true;
                return(otherDidSomething);

            // All other known values (3, 4) correspond to trades closing.
            default:
                if (OnError != null)
                {
                    OnError("Trade was closed by other user. Trade status: " + status.trade_status);
                }
                OtherUserCancelled = true;
                return(otherDidSomething);
            }

            if (status.newversion)
            {
                // handle item adding and removing
                session.Version = status.version;

                TradeEvent     trdEvent   = status.GetLastEvent();
                TradeEventType actionType = (TradeEventType)trdEvent.action;
                HandleTradeVersionChange(status);
                return(true);
            }
            else if (status.version > session.Version)
            {
                // oh crap! we missed a version update abort so we don't get
                // scammed. if we could get what steam thinks what's in the
                // trade then this wouldn't be an issue. but we can only get
                // that when we see newversion == true
                throw new TradeException("The trade version does not match. Aborting.");
            }

            var events = status.GetAllEvents();

            foreach (var tradeEvent in events)
            {
                if (eventList.Contains(tradeEvent))
                {
                    continue;
                }

                //add event to processed list, as we are taking care of this event now
                eventList.Add(tradeEvent);

                bool isBot = tradeEvent.steamid == MySteamId.ConvertToUInt64().ToString();

                // dont process if this is something the bot did
                if (isBot)
                {
                    continue;
                }

                otherDidSomething = true;

                /* Trade Action ID's
                 * 0 = Add item (itemid = "assetid")
                 * 1 = remove item (itemid = "assetid")
                 * 2 = Toggle ready
                 * 3 = Toggle not ready
                 * 4 = ?
                 * 5 = ? - maybe some sort of cancel
                 * 6 = ?
                 * 7 = Chat (message = "text")        */
                switch ((TradeEventType)tradeEvent.action)
                {
                case TradeEventType.ItemAdded:
                    FireOnUserAddItem(tradeEvent);
                    break;

                case TradeEventType.ItemRemoved:
                    FireOnUserRemoveItem(tradeEvent);
                    break;

                case TradeEventType.UserSetReady:
                    otherIsReady = true;
                    OnUserSetReady(true);
                    break;

                case TradeEventType.UserSetUnReady:
                    otherIsReady = false;
                    OnUserSetReady(false);
                    break;

                case TradeEventType.UserAccept:
                    OnUserAccept();
                    break;

                case TradeEventType.UserChat:
                    OnMessage(tradeEvent.text);
                    break;

                default:
                    // Todo: add an OnWarning or similar event
                    if (OnError != null)
                    {
                        OnError("Unknown Event ID: " + tradeEvent.action);
                    }
                    break;
                }
            }

            // Update Local Variables
            if (status.them != null)
            {
                otherIsReady = status.them.ready == 1;
                meIsReady    = status.me.ready == 1;
            }

            if (status.logpos != 0)
            {
                session.LogPos = status.logpos;
            }

            return(otherDidSomething);
        }