コード例 #1
0
        /// <summary>
        /// Handles object messages sent by bitmex.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="streams">The streams.</param>
        /// <returns></returns>
        public static bool HandleObjectMessage(string msg, BitmexClientStreams streams)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return
                (TradeResponse.TryHandle(response, streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, streams.PositionSubject) ||
                 MarginResponse.TryHandle(response, streams.MarginSubject) ||
                 OrderResponse.TryHandle(response, streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, streams.WalletSubject) ||
                 InstrumentResponse.TryHandle(response, streams.InstrumentSubject) ||
                 ExecutionResponse.TryHandle(response, streams.ExecutionSubject) ||
                 FundingResponse.TryHandle(response, streams.FundingsSubject) ||


                 ErrorResponse.TryHandle(response, streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, streams.AuthenticationSubject));
        }
コード例 #2
0
        private bool HandleObjectMessage(string msg)
        {
            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (ErrorResponse.TryHandle(msg, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(msg, Streams.SubscribeSubject) ||

                 BookResponse.TryHandle(msg, Streams.BookSubject, "orderBookL2") ||
                 TradeResponse.TryHandle(msg, Streams.TradesSubject) ||
                 QuoteResponse.TryHandle(msg, Streams.QuoteSubject) ||
                 BookResponse.TryHandle(msg, Streams.Book25Subject, "orderBookL2_25") ||
                 LiquidationResponse.TryHandle(msg, Streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(msg, Streams.PositionSubject) ||
                 MarginResponse.TryHandle(msg, Streams.MarginSubject) ||
                 OrderResponse.TryHandle(msg, Streams.OrderSubject) ||
                 WalletResponse.TryHandle(msg, Streams.WalletSubject) ||
                 ExecutionResponse.TryHandle(msg, Streams.ExecutionSubject) ||
                 FundingResponse.TryHandle(msg, Streams.FundingsSubject) ||
                 InstrumentResponse.TryHandle(msg, Streams.InstrumentSubject) ||
                 TradeBinResponse.TryHandle(msg, Streams.TradeBinSubject) ||


                 InfoResponse.TryHandle(msg, Streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(msg, Streams.AuthenticationSubject));
        }
コード例 #3
0
        /// <summary>
        /// PLEASE NOTE! wallet account balances dont work as you would expect! => https://github.com/PIVX-Project/PIVX/wiki/Accounts-Explained
        /// </summary>
        public static async Task <ParsedWalletResponse <decimal?> > GetBalanceAsync(this WalletClient client,
                                                                                    string walletAccount    = null,
                                                                                    int miniumConfirmations = 1,
                                                                                    bool includeWatchonly   = false)
        {
            WalletResponse response = null;

            if (walletAccount != null)
            {
                response = await client.MakeRequestAsync("getbalance", walletAccount, miniumConfirmations, includeWatchonly);
            }
            else
            {
                response = await client.MakeRequestAsync("getbalance");
            }

            if (response.Error == null)
            {
                decimal?amount = null;
                //parsing the string fails because , or .
                var culture = System.Globalization.CultureInfo.InvariantCulture;
                var style   = System.Globalization.NumberStyles.Any;

                if (decimal.TryParse(response.Result, style, culture, out decimal d))
                {
                    amount = d;
                }
                return(ParsedWalletResponse <decimal?> .CreateContent(d));
            }
            else
            {
                return(ParsedWalletResponse <decimal?> .CreateError(response.Error));
            }
        }
コード例 #4
0
        private bool HandleObjectMessage(string msg)
        {
            var response = BitmexJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (TradeResponse.TryHandle(response, Streams.TradesSubject) ||
                 TradeBinResponse.TryHandle(response, Streams.TradeBinSubject) ||
                 BookResponse.TryHandle(response, Streams.BookSubject) ||
                 QuoteResponse.TryHandle(response, Streams.QuoteSubject) ||
                 LiquidationResponse.TryHandle(response, Streams.LiquidationSubject) ||
                 PositionResponse.TryHandle(response, Streams.PositionSubject) ||
                 OrderResponse.TryHandle(response, Streams.OrderSubject) ||
                 WalletResponse.TryHandle(response, Streams.WalletSubject) ||


                 ErrorResponse.TryHandle(response, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, Streams.SubscribeSubject) ||
                 InfoResponse.TryHandle(response, Streams.InfoSubject) ||
                 AuthenticationResponse.TryHandle(response, Streams.AuthenticationSubject));
        }
コード例 #5
0
        public WalletResponse Read(long BankId)
        {
            WalletResponse response = new WalletResponse();

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    response.wallet = conn.Get <Wallet>(BankId);
                    if (response.wallet != null)
                    {
                        response.Status      = true;
                        response.Description = "Successful";
                    }
                    else
                    {
                        response.Status      = false;
                        response.Description = "No data";
                    }
                }
            }
            catch (Exception ex)
            {
                response.Status      = false;
                response.Description = ex.Message;
            }
            return(response);
        }
コード例 #6
0
        public IActionResult GetWithChanges(int id)
        {
            var wallet     = _db.Wallets.FirstOrDefault(x => x.Id == id);
            var changes    = _db.WalletValueChanges.Where(x => x.WalletId == id).ToList();
            var categories = _db.Categorys.ToList();

            var responseChanges = changes.OrderByDescending(x => x.Date).Select(x => new WalletChangeResponse {
                Id          = x.Id,
                Value       = x.ChangeValue,
                Date        = x.Date.ToStringCustom(),
                Description = x.Description,
                Color       = categories.FirstOrDefault(y => y.Id == x.CategoryId)?.Color,
                Category    = categories.FirstOrDefault(y => y.Id == x.CategoryId)?.Name
            }).ToList();

            var responseWallet = new WalletResponse();

            responseWallet.Id                = wallet.Id;
            responseWallet.Name              = wallet.Name;
            responseWallet.Currency          = "PLN"; // TODO
            responseWallet.CurrentState      = changes.Sum(x => x.ChangeValue);
            responseWallet.WalletChanges     = responseChanges;
            responseWallet.DefaultCategoryId = wallet.DefaultCategoryId;

            return(Json(responseWallet));
        }
コード例 #7
0
        /// <exception cref="ErrorResponseException"/>
        /// <exception cref="UnknownResponseException"/>
        public async Task <WalletModel> CreateWalletAsync()
        {
            var response = await _api.CreateWalletAsync();

            WalletResponse wallet = ConvertToOrHandleErrorResponse <WalletResponse>(response);

            return(new WalletModel(wallet.PublicAddress));
        }
コード例 #8
0
 private void HandleWalletSafe(WalletResponse response)
 {
     try
     {
         HandleWallet(response);
     }
     catch (Exception e)
     {
         Log.Error(e, $"[Coinbase] Failed to handle wallet info, error: '{e.Message}'");
     }
 }
コード例 #9
0
        /// <exception cref="ErrorResponseException"/>
        /// <exception cref="UnknownResponseException"/>
        public async Task <WalletModel> GetWalletByPublicAddressAsync(string publicAddress)
        {
            var response = await _api.GetByPublicAddressAsync(publicAddress);

            WalletResponse wallet = ConvertToOrHandleErrorResponse <WalletResponse>(response);

            if (wallet == null)
            {
                return(null);
            }

            return(new WalletModel(wallet.PublicAddress));
        }
コード例 #10
0
        public async Task <IActionResult> Receipt(WalletResponse form)
        {
            var command = new ReceiptRequest {
                WalletId = form.Receipt.WalletId, DateDue = form.Receipt.DateDue,
                Account  = form.Receipt.Account, Agency = form.Receipt.Agency,
            };

            if (ModelState.IsValid)
            {
                await Post <BaseResponse>($"wallet/receipt/update", command);
            }

            return(RedirectToAction(nameof(Wallet)));
        }
コード例 #11
0
        public static void GetWalletValue()
        {
            var            rest     = new RequestBuilder($"https://bitskins.com/api/v1/get_account_balance/?api_key={ApiKey}&code={Get2FAToken()}").GET().Execute();
            WalletResponse response = JsonConvert.DeserializeObject <WalletResponse>(rest.Content);

            if (response.status == "success")
            {
                string wallet = response.data.available_balance.ToString("N2");
                Console.Write($"Bitskins Wallet:");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"${wallet}");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
コード例 #12
0
        private CryptoWallet ConvertWallet(WalletResponse response)
        {
            var id = response.Currency;

            var wallet = new CryptoWallet
            {
                Type             = "Exchange",
                Currency         = CryptoPairsHelper.Clean(response.Currency),
                Balance          = Math.Abs(response.Balance),
                BalanceAvailable = response.Available
            };

            _lastWallet = wallet;
            return(wallet);
        }
コード例 #13
0
        protected T RpcRequest <T>(WalletRequest walletRequest)
        {
            id++;
            walletRequest.UpdateId(id);
            string jsonRequest = JsonConvert.SerializeObject(walletRequest);
            string result      = MakeRequest(jsonRequest);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters = new JsonConverter[] { new UnixDateTimeConverter(), new JsonEnumTypeConverter <TransactionCategory>() };
            WalletResponse <T> walletResponse = JsonConvert.DeserializeObject <WalletResponse <T> >(result, settings);

            if (walletResponse.Error != null)
            {
                throw new BitcoinRpcException(walletResponse.Error);
            }
            return(walletResponse.Result);
        }
コード例 #14
0
        public IEnumerable <WalletResponse> LeerWallet(string pUser_id)
        {
            string lineagg = "0";

            try
            {
                List <WalletResponse> lstWallet = new List <WalletResponse>();
                lineagg += ",1";
                using (SqlConnection con = new SqlConnection(Data.Data.StrCnx_WebsSql))
                {
                    SqlCommand cmd = new SqlCommand("latinamericajourneys.LAJ_Wallet_S", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@User_id", SqlDbType.VarChar).Value = pUser_id;

                    lineagg += ",2";
                    con.Open();
                    cmd.ExecuteNonQuery();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    lineagg += ",3";
                    while (rdr.Read())
                    {
                        lineagg += ",4";
                        WalletResponse fWallet = new WalletResponse();

                        fWallet.Saldo = rdr["saldo"].ToString();
                        fWallet.Movs  = new List <Movs>();

                        var ListaMovs = LeerMovs(pUser_id);
                        fWallet.Movs.AddRange(ListaMovs);
                        lstWallet.Add(item: fWallet);
                    }

                    lineagg += ",5";
                    con.Close();
                }
                return(lstWallet);
            }
            catch (Exception ex)
            {
                throw new Exception {
                          Source = lineagg
                };
            }
        }
コード例 #15
0
        public WalletResponse GetWallet(string userId)
        {
            WalletResponse wallet = null;

            if (!string.IsNullOrWhiteSpace(userId))
            {
                if (_applicationUserDataService.Value.Query().Any(x => x.Id == userId))
                {
                    wallet = new WalletResponse();
                    var incomeTotal = _userTargetDonationDataService.Value.Query().Where(x => x.UserTarget.ApplicationUserId == userId).Sum(x => (decimal?)x.DonationTotal) ?? 0;
                    var outcome     = _userTargetDonationDataService.Value.Query().Where(x => x.DonationFromUserId == userId).Sum(x => (decimal?)x.DonationTotal) ?? 0;
                    if (incomeTotal >= outcome)
                    {
                        wallet.Total = incomeTotal - outcome;
                    }
                }
            }
            return(wallet);
        }
コード例 #16
0
        public WalletResponse GetStatus(UserParameter param)
        {
            WalletResponse result = new WalletResponse();

            try
            {
                result.wallet = wr.GetWallet(param.User.UserId);
                if (result.wallet == null)
                {
                    throw new Exception("Пользователь не найден");
                }
            }
            catch (Exception e)
            {
                result.IsError      = true;
                result.ErrorMessage = e.Message;
            }
            return(result);
        }
コード例 #17
0
        public override async Task <WalletResponse> GetWallet(WalletRequest request, ServerCallContext context)
        {
            var result = new WalletResponse();

            var token    = context.GetBearerToken();
            var response = await _walletApiV1Client.WalletsGetByIdAsync(request.AssetId, token);

            if (response.Result != null)
            {
                result.Body = _mapper.Map <WalletResponse.Types.Body>(response.Result);
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// Returns up to [count] most recent transactions skipping the first [from] transactions for account [account].
        /// If [account] not provided it'll return recent transactions from all accounts.
        /// </summary>
        /// <param name="walletAccount">List from this wallet account</param>
        /// <param name="count">How many transactions should be listed</param>
        /// <param name="from">Start index for the listing</param>
        /// <returns>Wallet response wrapper; Success: Json array of the transactions, Error: WalletError object</returns>
        public static async Task <ParsedWalletResponse <JArray> > ListTransactionsAsync(this WalletClient client,
                                                                                        string walletAccount  = null,
                                                                                        int count             = 10,
                                                                                        int from              = 0,
                                                                                        bool includeWatchonly = false)
        {
            WalletResponse response = null;

            //this has to be checked for null because if the walletAccount is null in the request object, this will be invalid request
            if (walletAccount != null)
            {
                //make internal request to the wallet implementation
                response = await client.MakeRequestAsync("listtransactions",
                                                         walletAccount,
                                                         count,
                                                         from,
                                                         includeWatchonly);
            }
            else
            {
                //not defining wallet account in the request is fine, but it cannot be defined as null
                //make internal request to the wallet implementation
                response = await client.MakeRequestAsync("listtransactions");
            }

            if (response.Error == null)
            {
                try
                {
                    var jsonArray = JArray.Parse(response.Result);
                    return(ParsedWalletResponse <JArray> .CreateContent(jsonArray));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(ParsedWalletResponse <JArray> .CreateError(response.Error));
            }
        }
コード例 #19
0
        public override Task <WalletResponse> GetWallet(WalletRequest request, ServerCallContext context)
        {
            var resp = new WalletResponse();

            resp.Result = new WalletResponse.Types.WalletPayload()
            {
                Id           = "BTC",
                AssetPairId  = "BTCUSD",
                Symbol       = "BTC",
                Balance      = "1",
                Reserved     = "0",
                Accuracy     = 4,
                AmountInBase = "10000",
                Name         = "Bitcoin",
                CategoryId   = "Crypto",
                HideIfZero   = false,
                IssuerId     = "market"
            };

            return(Task.FromResult(resp));
        }
コード例 #20
0
        /// <summary>
        /// implement IWalletClient interface
        /// </summary>
        /// <param name="method">wallet method</param>
        /// <param name="parameters">parameters required by the wallet method</param>
        /// <returns>Deserialized wallet response</returns>
        public async Task <WalletResponse> MakeRequestAsync(string method, params object[] parameters)
        {
            var response = await MakeInternalRequestAsync(method, parameters);

            WalletResponse data = new WalletResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string json = await response.Content.ReadAsStringAsync();

                data.FromJson(json);
            }
            else
            {
                var error = CreateHttpErrorResponse(response);
                data.Error = error;
            }

            data.StatusCode = response.StatusCode;
            return(data);
        }
コード例 #21
0
        private bool HandleObjectMessage(string msg)
        {
            var response = CoinbaseJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return
                (HeartbeatResponse.TryHandle(response, Streams.HeartbeatSubject) ||
                 TradeResponse.TryHandle(response, Streams.TradesSubject) ||
                 OrderBookUpdateResponse.TryHandle(response, Streams.OrderBookUpdateSubject) ||
                 OrderBookSnapshotResponse.TryHandle(response, Streams.OrderBookSnapshotSubject) ||
                 TickerResponse.TryHandle(response, Streams.TickerSubject) ||
                 ErrorResponse.TryHandle(response, Streams.ErrorSubject) ||
                 SubscribeResponse.TryHandle(response, Streams.SubscribeSubject) ||
                 StatusResponse.TryHandle(response, Streams.StatusSubject) ||
                 OrderResponse.TryHandle(response, Streams.OrdersSubject) ||
                 WalletResponse.TryHandle(response, Streams.WalletsSubject) ||
                 OrdersSnapshotResponse.TryHandle(response, Streams.OrdersSnapshotSubject) ||
                 WalletsSnapshotResponse.TryHandle(response, Streams.WalletsSnapshotSubject));
        }
コード例 #22
0
 private void HandleWallet(WalletResponse response)
 {
     WalletChangedSubject.OnNext(new[] { ConvertWallet(response) });
 }
コード例 #23
0
ファイル: ApiResponse.cs プロジェクト: Paulito123/BitMEX
        /// <summary>
        /// Finds the expected response object derived from the URI of the call.
        /// </summary>
        /// <returns></returns>
        private object ApiResponseDispatcher()
        {
            // Json is empty > Shit...
            if (String.IsNullOrEmpty(Json))
            {
                //log.Error("Json == null or empty");
                return(null);
            }

            // Uri is empty > Shit...
            if (this.Uri == null || this.Uri.AbsolutePath == "")
            {
                //log.Error("Uri.AbsolutePath null or empty");
                return(null);
            }

            object o;

            // Return the correct type based on the Uri
            switch (this.Uri.AbsolutePath.ToLower())
            {
            case "/api/v1/order":
                if (this.Json.Substring(0, 1) == "[")
                {
                    o = OrdersResponse.FromJson(this.Json);
                }
                else
                {
                    o = OrderResponse.FromJson(this.Json);
                }
                break;

            case "/api/v1/order/all":
            case "/api/v1/order/bulk":
                o = OrdersResponse.FromJson(this.Json);
                break;

            case "/api/v1/position/leverage":
                o = PositionResponse.FromJson(this.Json);
                break;

            case "/api/v1/position":
                o = PositionsResponse.FromJson(this.Json);
                break;

            case "/api/v1/order/closeposition":
                o = OrderResponse.FromJson(this.Json);
                break;

            case "/api/v1/user/wallet":
                o = WalletResponse.FromJson(this.Json);
                break;

            case "/api/v1/order/cancelallafter":
            default:
                o = null;
                //log.Error("Uri unknown. Please add [" + this.Uri.AbsolutePath + "] to the evaluated Uri's.");
                break;
            }

            return(o);
        }