Exemplo n.º 1
0
 public Language(CurrencyName name, Iso639 iso639, TypeEnum type, Scope scope)
 {
     Name   = name;
     Iso639 = iso639;
     Type   = type;
     Scope  = scope;
 }
Exemplo n.º 2
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName inst, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            BitstampOrderResponse response = null;
            var symbol = inst.ToString().ToLower() + "usd";

            if (type == TradeOrderType.Limit)
            {
                response = Client.PlaceLimitOrder(side == OrderSide.BID ? "buy" : "sell", symbol, amount, price);
            }
            else
            {
                throw new ArgumentException("[Bitstamp] Invalid order type");
            }

            if (String.Compare(response.Status, "error", true) != 0)
            {
                return(new OrderResponse(response.Datetime, response.OrderId));
            }

            var str = new StringBuilder("[Bitstamp] PlaceOrder");

            foreach (var error in response.Reason.All)
            {
                str.AppendFormat(" {0}", error);
            }
            return(new OrderResponse()
            {
                ErrorReason = str.ToString()
            });
        }
Exemplo n.º 3
0
        public OrderBook GetOrderBook(CurrencyName instrument, CurrencyName currency)
        {
            var json     = GetQuery(String.Format("{0}order_book?book={1}_{2}", BaseUri, instrument.ToString().ToLower(), currency.ToString().ToLower()));
            var response = JsonConvert.DeserializeObject <QuadrigaOrderBook>(json);

            if (response.Error != null)
            {
                throw new System.Net.WebException(response.Error.Message);
            }

            var orderBook = new OrderBook {
                Currency = currency, Timestamp = response.Timestamp
            };

            orderBook.Asks = new Order[response.Asks.Length];
            orderBook.Bids = new Order[response.Bids.Length];

            for (int i = 0; i < orderBook.Asks.Length; i++)
            {
                orderBook.Asks[i] = new Order {
                    Price = response.Asks[i][0], Amount = response.Asks[i][1]
                }
            }
            ;

            for (int i = 0; i < orderBook.Bids.Length; i++)
            {
                orderBook.Bids[i] = new Order {
                    Price = response.Bids[i][0], Amount = response.Bids[i][1]
                }
            }
            ;

            return(orderBook);
        }
Exemplo n.º 4
0
        public OrderBook GetOrderBook(CurrencyName instrument, CurrencyName currency)
        {
            var str      = String.Format("{0}book/{1}{2}?limit_bids={3}&limit_asks={3}", BaseUri, instrument.ToString().ToLower(), currency.ToString().ToLower(), OrderBookLimit);
            var json     = GetQuery(str);
            var response = JsonConvert.DeserializeObject <BitfinexOrderBook>(json);

            var asks = new Order[response.Asks.Length];
            var bids = new Order[response.Bids.Length];

            for (int i = 0; i < asks.Length; i++)
            {
                asks[i] = new Order {
                    Price = response.Asks[i].Price, Amount = response.Asks[i].Amount
                }
            }
            ;

            for (int i = 0; i < bids.Length; i++)
            {
                bids[i] = new Order {
                    Price = response.Bids[i].Price, Amount = response.Bids[i].Amount
                }
            }
            ;

            return(new OrderBook {
                Asks = asks, Bids = bids, Currency = currency
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Function called to search the model
        /// for availability of the specified string.
        /// </summary>
        /// <param name="str">The search string</param>
        /// <returns>True, if the string is contained in the model, else false</returns>
        public override bool Contains(string str)
        {
            String status = IsActive ? "Active" : "Inactive";

            return((CurrencyName != null && CurrencyName.StartsWith(str, StringComparison.CurrentCultureIgnoreCase)) ||
                   (Description != null && Description.StartsWith(str, StringComparison.CurrentCultureIgnoreCase)));
        }
Exemplo n.º 6
0
        public double GetMinTradeValue(CurrencyName currency, double value = 0)
        {
            if (currency == CurrencyName.USD)
            {
                return(BTCUSDMinValue);
            }

            switch (currency)
            {
            case CurrencyName.BTC: return(BTCUSDMinValue / value);

            case CurrencyName.BCH: return(BCHUSDMinValue / value);

            case CurrencyName.LTC: return(LTCUSDMinValue / value);

            case CurrencyName.ETH: return(ETHUSDMinValue / value);

            case CurrencyName.XRP: return(XRPUSDMinValue / value);

            case CurrencyName.DSH: return(DASHUSDMinValue / value);

            case CurrencyName.IOTA: return(IOTAUSDMinValue / value);

            default: throw new InvalidOperationException("GetMinTradeValue(). Invalid currency.");
            }
        }
Exemplo n.º 7
0
        private void UnsubscribeTrade(CurrencyName instrument1, EventHandler <TradeEventArgs> handler, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (instrument1 == CurrencyName.BTC)
            {
                _btcTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.BCH)
            {
                _bchTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.LTC)
            {
                _ltcTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.ETH)
            {
                _ethTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.XRP)
            {
                _xrpTradeHandler -= handler;
            }

            var channelName = String.Format(TradeChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'removeChannel'," + channelName + "}"));
        }
Exemplo n.º 8
0
        public void SubscribeOrderBook(CurrencyName instrument1, EventHandler <OrderBookEventArgs> handler = null, CurrencyName instrument2 = CurrencyName.USDT)
        {
            string channelName = null;

            if (handler != null)
            {
                if (instrument1 == CurrencyName.BTC)
                {
                    _btcOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.BCH)
                {
                    _bchOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.LTC)
                {
                    _ltcOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.ETH)
                {
                    _ethOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.IOTA)
                {
                    _iotaOrderBookHandler += handler;
                }
            }

            channelName = String.Format(OrderBookChannel, instrument1.ToString(), instrument2.ToString()).ToLower();
            SendMessage(c => c.Send("{'event':'addChannel'," + channelName + "}"));
        }
Exemplo n.º 9
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, DataType.OrderSide orderSide, TradeOrderType type = TradeOrderType.Limit)
        {
            if (!(currency == CurrencyName.BTC || currency == CurrencyName.BCH ||
                  currency == CurrencyName.ETH || currency == CurrencyName.LTC))
            {
                return(new OrderResponse {
                    ErrorReason = "Invalid instrument"
                });
            }
            var currencyName = currency.ToString();

            if (currency == CurrencyName.BCH)
            {
                currencyName = "BCC";
            }

            var symbol = currencyName + "USDT";
            var side   = orderSide == DataType.OrderSide.BID ? Binance.Net.Objects.OrderSide.Buy : Binance.Net.Objects.OrderSide.Sell;

            //"LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"

            var result = _client.PlaceOrder(symbol, side, OrderType.Limit, TimeInForce.GoodTillCancel, amount, price);

            return(result.Success
                ? new OrderResponse(result.Data.TransactTime, result.Data.OrderId.ToString())
                : new OrderResponse {
                ErrorReason = result.Error.Message, ErrorCode = result.Error.Code
            });
        }
Exemplo n.º 10
0
        public void UnsubscribeOrderBook(CurrencyName instrument1, EventHandler <OrderBookEventArgs> handler, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (instrument1 == CurrencyName.BTC)
            {
                _btcOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.BCH)
            {
                _bchOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.LTC)
            {
                _ltcOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.ETH)
            {
                _ethOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.IOTA)
            {
                _iotaOrderBookHandler -= handler;
            }

            var channelName = String.Format(OrderBookChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'removeChannel'," + channelName + "}"));
        }
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.currencyCode)
            {
                hashcode = (hashcode * 397) + CurrencyCode.GetHashCode();
            }
            if (__isset.currencyName)
            {
                hashcode = (hashcode * 397) + CurrencyName.GetHashCode();
            }
            if (__isset.currencySign)
            {
                hashcode = (hashcode * 397) + CurrencySign.GetHashCode();
            }
            if (__isset.preferred)
            {
                hashcode = (hashcode * 397) + Preferred.GetHashCode();
            }
            if (__isset.coinRate)
            {
                hashcode = (hashcode * 397) + CoinRate.GetHashCode();
            }
            if (__isset.creditRate)
            {
                hashcode = (hashcode * 397) + CreditRate.GetHashCode();
            }
        }
        return(hashcode);
    }
Exemplo n.º 12
0
 public BudgetInfo(DateTime period, double amount, CurrencyName currency, double percentage)
 {
     Period     = string.Format("{0:MM/yyyy}", period);
     Amount     = Math.Round(amount, 2);
     Currency   = currency.ToString();
     Percentage = Math.Round(percentage, 2);
 }
Exemplo n.º 13
0
        private void SetAveragePrice(CurrencyName instrument, string pairName, Action wait = null)
        {
            var exist1 = _restInstruments.ContainsKey(instrument);

            //var exist2 = _wsInstruments.ContainsKey(instrument);

            if (!exist1 /*&& !exist2*/)
            {
                return;
            }

            if (wait != null)
            {
                wait();
            }

            var vwap = _bitfinex.GetTicker(pairName).Mid;

            if (_restInstruments.ContainsKey(instrument))
            {
                _restInstruments[instrument].SetAveragePrice(vwap);
            }

            //if (_wsInstruments.ContainsKey(instrument))
            //    _wsInstruments[instrument].SetAveragePrice(vwap);
        }
Exemplo n.º 14
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            QuadrigaOrderResponse response = null;
            string path = side == OrderSide.BID ? "buy" : "sell";
            string book = currency.ToString().ToLower() + "_cad";

            if (type == TradeOrderType.Limit)
            {
                response = _client.PlaceLimitOrder(path, amount, book, price);
            }
            else if (type == TradeOrderType.Market)
            {
                response = _client.PlaceMarketOrder(path, amount, book, price);
            }
            else
            {
                throw new ArgumentException("Invalid order type");
            }

            return(response.Error == null
                ? new OrderResponse(response.Datetime, response.OrderId)
                : new OrderResponse()
            {
                ErrorReason = response.Error.Message
            });
        }
Exemplo n.º 15
0
        public void SubscribeTrade(CurrencyName instrument1, EventHandler <TradeEventArgs> handler = null, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (handler != null)
            {
                if (instrument1 == CurrencyName.BTC)
                {
                    _btcTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.BCH)
                {
                    _bchTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.LTC)
                {
                    _ltcTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.ETH)
                {
                    _ethTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.XRP)
                {
                    _xrpTradeHandler += handler;
                }
            }

            var channelName = String.Format(TradeChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'addChannel'," + channelName + "}"));
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (BaseCurrencyName.Length != 0)
            {
                hash ^= BaseCurrencyName.GetHashCode();
            }
            if (CurrencyName.Length != 0)
            {
                hash ^= CurrencyName.GetHashCode();
            }
            if (BuyRate != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(BuyRate);
            }
            if (SellRate != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(SellRate);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 17
0
 private void RestRequestHandler(object sender, CurrencyName currency)
 {
     foreach (BaseRestExchange ex in _restExchanges.Values)
     {
         Task.Run(() => ex.RestRequestHandler(currency));
     }
 }
Exemplo n.º 18
0
        protected void lnkSave_Click(object sender, EventArgs e)
        {
            if (Action == string.Empty || Action == Constants.ViewAction)
            {
                Action = Constants.InsertAction;
            }
            if (Action == Constants.InsertAction)
            {
                QueryArgument queryArgument = new QueryArgument(UserContext.DataBaseInfo)
                {
                    FilterKey = CountryId,
                    filter1   = Constants.CountryType,
                    QueryType = Constants.TableMCatHeader
                };
                if (_transactionManager.ValidateKey(queryArgument))
                {
                    CustomMessageControl.MessageBodyText = "Country Code already exist";
                    CustomMessageControl.MessageType     = MessageTypes.Error;
                    CustomMessageControl.ShowMessage();
                    txtId.Focus();
                    return;
                }
            }
            var country = new Country
            {
                CountryId      = CountryId,
                CountryName    = CountryName,
                CurrencyCode   = CurrencyCode,
                CurrencyName   = CurrencyName.ToTrimString(),
                CurrencySymbol = CurrencySymbol,
                Denomination   = Denomination,
                Action         = Action,
                DataBaseInfo   = UserContext.DataBaseInfo
            };
            var countries = new Countries {
                country
            };

            if (_controlPanel.SetCountry(countries))
            {
                CustomMessageControl.MessageBodyText = GlobalCustomResource.CountrySaved;
                CustomMessageControl.MessageType     = MessageTypes.Success;
                AuditLog.LogEvent(SysEventType.INFO, "Country Saved",
                                  GlobalCustomResource.CountrySaved);
                ClearForm();
                BindData(BindType.List);
                IsVisibleSave = false;
                txtId.Enabled = true;
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "openTabFunctionCall", "openTab(1)", true);
            }
            else
            {
                CustomMessageControl.MessageBodyText = GlobalCustomResource.CountryFailed;
                CustomMessageControl.MessageType     = MessageTypes.Error;
                AuditLog.LogEvent(SysEventType.INFO, "Country update failed",
                                  GlobalCustomResource.CountryFailed);
            }
            CustomMessageControl.ShowMessage();
        }
Exemplo n.º 19
0
 public MatchingEventArgs(ExchangeName exchange, CurrencyName instrument2, double bidPrice, double askPrice, double fee)
 {
     Instrument2 = instrument2;
     Exchange    = exchange;
     BidPrice    = bidPrice;
     AskPrice    = askPrice;
     TradingFee  = fee;
 }
Exemplo n.º 20
0
 public double GetCurrencyRate(CurrencyName currency)
 {
     using (var db = DbConnection)
     {
         var res = db.Query <DbCurrencyRate>(DbQueryStr.GetCurrencyRates, new { CurrencyId = (int)currency }).Single();
         return(res.Rate);
     }
 }
Exemplo n.º 21
0
        public OrderBook GetOrderBook(CurrencyName instrument, CurrencyName currency)
        {
            var json     = GetQuery(String.Format("{0}depth.do?symbol={1}_{2}", BaseUri, instrument.ToString().ToLower(), currency.ToString().ToLower()));
            var response = JsonConvert.DeserializeObject <OrderBook>(json);

            SortAsks(response);

            return(response);
        }
 public void Add(CurrencyName currencyName, int amount)
 {
     if (currencyName == CurrencyName.Expirience)
     {
         AddExp(amount);
         return;
     }
     Spend(currencyName, -amount);
 }
Exemplo n.º 23
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName instrument, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            var result = _client.PlaceOrder(side == OrderSide.BID ? "buy" : "sell", instrument, amount, CurrencyName.PLN, price);

            return(result.Success ? new OrderResponse(result.OrderId) : new OrderResponse()
            {
                ErrorReason = "Error"
            });
        }
Exemplo n.º 24
0
 public void StopRestScheduler(CurrencyName instrument)
 {
     SendMessage <RestSchedulerCommand>(
         () => new RestSchedulerCommand {
         Instrument = instrument
     },
         () => RemoteCommandType.RunRestScheduler
         );
 }
Exemplo n.º 25
0
 public double GetCurrencyRate(CurrencyName currency)
 {
     return(SendReceiveMessage <CurrencyRateCommand, double>(
                () => new CurrencyRateCommand {
         Currency = currency
     },
                () => RemoteCommandType.CurrencyRate
                ));
 }
Exemplo n.º 26
0
        private void CreateConnection(CurrencyName instrument)
        {
            var config     = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
            var connection = config.FindConnectionElement("RestScheduler");
            var strAddr    = String.Format(connection.DomainName, instrument.ToString().ToLower());
            var ipAddr     = Dns.GetHostEntry(strAddr).AddressList.Where(a => a.AddressFamily == AddressFamily.InterNetwork).First();

            _log.WriteInfo(String.Format("{0} subscribed", instrument.ToString()));
            _connections.Add(new Tuple <CurrencyName, IPEndPoint>(instrument, new IPEndPoint(ipAddr, connection.Port)));
        }
Exemplo n.º 27
0
        public RestExchangeListener(DbGatewayService dbGateway, ServiceEventLogger log)
        {
            var config = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");

            _instrument = (CurrencyName)Enum.Parse(typeof(CurrencyName), config.RestExchanges.Instrument.Split(',')[0].Trim().ToUpper());

            _dbGateway = dbGateway;
            _tcp       = new TcpService();
            _log       = log;
        }
Exemplo n.º 28
0
        public KunaOrdersHistory[] GetOrdersHistory(CurrencyName inst)
        {
            var args = CreateSignHeaders("trades/my", "GET", new SortedDictionary <string, string>
            {
                { "market", inst.ToString().ToLower() + "uah" }
            });

            var response = UserQuery("trades/my", HttpMethod.Get, null, UrlEncode(args));

            return(JsonConvert.DeserializeObject <KunaOrdersHistory[]>(response.Content));
        }
Exemplo n.º 29
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            string market = currency.ToString().ToLower() + "uah";
            var    order  = _client.PlaceOrder(market, side == OrderSide.BID ? "buy" : "sell", amount, price);

            return(order.Error == null
                ? new OrderResponse(order.CreatedAt, order.Id)
                : new OrderResponse {
                ErrorReason = order.Error.Message
            });
        }
Exemplo n.º 30
0
        private CashInfo GetOperationInfo(IEnumerable <Operation> operations, CurrencyName currency)
        {
            var count  = operations.ByCurrency(currency).Count();
            var amount = operations.Sum(x => x.Amount);

            return(new CashInfo()
            {
                Iterations = count,
                Amount = amount,
                Currency = currency
            });
        }