Ejemplo n.º 1
0
        private BalanceReply GetBalance()
        {
            var path = "/api/accounts/balance";
            var req  = BuildRequest(path);

            return(RestUtil.ExecuteRequest <BalanceReply>(_restClient, req));
        }
Ejemplo n.º 2
0
        private OpenOrdersReply GetOpenOrders()
        {
            var path = "/api/exchange/orders/opens";
            var req  = BuildRequest(path);

            return(RestUtil.ExecuteRequest <OpenOrdersReply>(_restClient, req));
        }
Ejemplo n.º 3
0
        private List <ExecutionReply> GetExecutions(string acceptanceId)
        {
            var path = $"/v1/me/getexecutions?child_order_acceptance_id={acceptanceId}";
            var req  = BuildRequest(path);

            return(RestUtil.ExecuteRequest <List <ExecutionReply> >(_restClient, req));
        }
Ejemplo n.º 4
0
        private void Cancel(string orderId)
        {
            var method = "PUT";
            var path   = $"/orders/{orderId}/cancel";
            var req    = BuildRequest(path, method);

            RestUtil.ExecuteRequest(_restClient, req);
        }
Ejemplo n.º 5
0
        public decimal GetBtcPosition()
        {
            var path     = "/trading_accounts";
            var req      = BuildRequest(path);
            var accounts = RestUtil.ExecuteRequest <List <TradingAccounts> >(_restClient, req);
            var account  = accounts.Find(b => b.CurrencyPairCode == "BTCJPY");

            return(account.Position);
        }
Ejemplo n.º 6
0
        private CancelReply Cancel(string orderId)
        {
            var method = "DELETE";
            var path   = $"/api/exchange/orders/{orderId}";
            var req    = BuildRequest(path, method);
            var reply  = RestUtil.ExecuteRequest <CancelReply>(_restClient, req);

            return(reply);
        }
Ejemplo n.º 7
0
        public decimal GetBtcPosition()
        {
            var path        = "/v1/me/getbalance";
            var req         = BuildRequest(path);
            var balanceList = RestUtil.ExecuteRequest <List <Balance> >(_restClient, req);
            var btcBalance  = balanceList.Find(b => b.CurrencyCode == "BTC");

            return(btcBalance.Amount);
        }
Ejemplo n.º 8
0
        private SendReply Send(SendChildOrderParam param)
        {
            var method = "POST";
            var path   = "/v1/me/sendchildorder";
            var body   = JsonConvert.SerializeObject(param);
            var req    = BuildRequest(path, method, body);

            return(RestUtil.ExecuteRequest <SendReply>(_restClient, req));
        }
Ejemplo n.º 9
0
        private SendReply Send(object param)
        {
            var method = "POST";
            var path   = "/orders/";
            var body   = JsonConvert.SerializeObject(param);
            var req    = BuildRequest(path, method, body);
            var reply  = RestUtil.ExecuteRequest <SendReply>(_restClient, req);

            return(reply);
        }
Ejemplo n.º 10
0
        private void Cancel(string productCode, string acceptanceId)
        {
            var method = "POST";
            var path   = "/v1/me/cancelchildorder";
            var param  = new CancelChildOrderParam
            {
                product_code = productCode,
                child_order_acceptance_id = acceptanceId
            };
            var body = JsonConvert.SerializeObject(param);
            var req  = BuildRequest(path, method, body);

            RestUtil.ExecuteRequest(_restClient, req);
        }
Ejemplo n.º 11
0
        private IList <LeveragePosition> GetLeverageOpenPositions()
        {
            var path  = "/api/exchange/leverage/positions?status=open&limit=25";
            var req   = BuildRequest(path);
            var reply = RestUtil.ExecuteRequest <LeveragePositionReply>(_restClient, req);

            if (reply.data.Count > 25)
            {
                throw new InvalidOperationException("Paging handling not implemented.");
            }
            var leveragePositions = reply.data.Select(record => new LeveragePosition
            {
                Id   = record.id,
                Side = Util.ParseEnum <OrderSide>(record.side),
                Size = record.amount
            }).ToList();

            return(leveragePositions);
        }
Ejemplo n.º 12
0
        private TransactionsReply GetTransactions(string after = null, string before = null, int limit = 20,
                                                  string order = "desc")
        {
            var path = $"/api/exchange/orders/transactions_pagination?limit={limit}&order={order}";

            if (after != null)
            {
                path += $"&starting_after={after}";
            }

            if (before != null)
            {
                path += $"&ending_before={before}";
            }

            var req = BuildRequest(path);

            return(RestUtil.ExecuteRequest <TransactionsReply>(_restClient, req));
        }
Ejemplo n.º 13
0
        public void Send(Order order)
        {
            if (order.Broker != Broker)
            {
                throw new InvalidOperationException();
            }

            var orderType = GetBrokerOrderType(order);
            var method    = "POST";
            var path      = "/api/exchange/orders";
            var body      = $"pair=btc_jpy&order_type={orderType}&amount={order.Size}";

            if (order.Type != OrderType.Market)
            {
                body += $"&rate={order.Price}";
            }

            if (order.CashMarginType == CashMarginType.MarginClose && order.ClosingMarginPositionId != null)
            {
                if (order.ClosingMarginPositionId == null)
                {
                    throw new InvalidOperationException("Margin close order requires the closing position ID.");
                }

                body += $"&position_id={order.ClosingMarginPositionId}";
            }

            var req   = BuildRequest(path, method, body);
            var reply = RestUtil.ExecuteRequest <SendReply>(_restClient, req);

            if (!reply.Success)
            {
                throw new InvalidOperationException("Send failed.");
            }

            order.SentTime      = Util.IsoDateTimeToLocal(reply.CreatedAt);
            order.Status        = OrderStatus.New;
            order.BrokerOrderId = reply.Id;
            order.LastUpdated   = DateTime.Now;
        }
Ejemplo n.º 14
0
        private LeveragePositionReply GetLeveragePositions(
            string status,
            int limit,
            string order  = "desc",
            string after  = null,
            string before = null)
        {
            var path = $"/api/exchange/leverage/positions?status={status}&limit={limit}";

            if (after != null)
            {
                path += $"&starting_after={after}";
            }

            if (before != null)
            {
                path += $"&ending_before={before}";
            }
            var req = BuildRequest(path);

            return(RestUtil.ExecuteRequest <LeveragePositionReply>(_restClient, req));
        }