/// <summary>
        /// Places a new order
        /// </summary>
        /// <param name="type">The type of the order</param>
        /// <param name="symbol">The symbol the order is for</param>
        /// <param name="amount">The amount of the order, positive for buying, negative for selling</param>
        /// <param name="groupId">Group id to assign to the order</param>
        /// <param name="clientOrderId">Client order id to assign to the order</param>
        /// <param name="price">Price of the order</param>
        /// <param name="priceTrailing">Trailing price of the order</param>
        /// <param name="priceAuxiliaryLimit">Auxiliary limit price of the order</param>
        /// <param name="priceOcoStop">Oco stop price of the order</param>
        /// <param name="flags">Additional flags</param>
        /// <returns></returns>
        public async Task <CallResult <BitfinexOrder> > PlaceOrderAsync(OrderType type, string symbol, decimal amount, long?groupId = null, long?clientOrderId = null, decimal?price = null, decimal?priceTrailing = null, decimal?priceAuxiliaryLimit = null, decimal?priceOcoStop = null, OrderFlags?flags = null)
        {
            symbol.ValidateBitfinexSymbol();
            log.Write(LogVerbosity.Info, "Going to place order");
            if (clientOrderId == null)
            {
                clientOrderId = GenerateClientOrderId();
            }

            var query = new BitfinexSocketQuery(clientOrderId.ToString(), BitfinexEventType.OrderNew, new BitfinexNewOrder
            {
                Amount              = amount,
                OrderType           = type,
                Symbol              = symbol,
                Price               = price,
                ClientOrderId       = clientOrderId,
                Flags               = flags,
                GroupId             = groupId,
                PriceAuxiliaryLimit = priceAuxiliaryLimit,
                PriceOCOStop        = priceOcoStop,
                PriceTrailing       = priceTrailing
            });

            return(await Query <BitfinexOrder>(query, true).ConfigureAwait(false));
        }
        private async Task <CallResult <bool> > CancelOrdersAsync(IEnumerable <long>?orderIds = null, Dictionary <long, DateTime>?clientOrderIds = null, Dictionary <long, long?>?groupOrderIds = null)
        {
            if (orderIds == null && clientOrderIds == null && groupOrderIds == null)
            {
                throw new ArgumentException("Either orderIds, clientOrderIds or groupOrderIds should be provided");
            }

            log.Write(LogVerbosity.Info, "Going to cancel multiple orders");
            var cancelObject = new BitfinexMultiCancel {
                OrderIds = orderIds
            };

            if (clientOrderIds != null)
            {
                cancelObject.ClientIds = new object[clientOrderIds.Count][];
                for (var i = 0; i < cancelObject.ClientIds.Length; i++)
                {
                    cancelObject.ClientIds[i] = new object[]
                    {
                        clientOrderIds.ElementAt(i).Key,
                        clientOrderIds.ElementAt(i).Value.ToString("yyyy-MM-dd")
                    };
                }
            }
            if (groupOrderIds != null)
            {
                cancelObject.GroupIds = new[] { groupOrderIds.Select(g => g.Key).ToArray() }
            }
            ;

            var query = new BitfinexSocketQuery(null, BitfinexEventType.OrderCancelMulti, cancelObject);

            return(await Query <bool>(query, true).ConfigureAwait(false));
        }
예제 #3
0
        /// <inheritdoc />
        public async Task <CallResult <BitfinexOrder> > PlaceOrderAsync(OrderType type, string symbol, decimal quantity, long?groupId = null, long?clientOrderId = null, decimal?price = null, decimal?priceTrailing = null, decimal?priceAuxiliaryLimit = null, decimal?priceOcoStop = null, OrderFlags?flags = null, string?affiliateCode = null)
        {
            symbol.ValidateBitfinexSymbol();
            _log.Write(LogLevel.Information, "Going to place order");
            clientOrderId ??= GenerateClientOrderId();

            var affCode = affiliateCode ?? _affCode;
            var query   = new BitfinexSocketQuery(clientOrderId.ToString(), BitfinexEventType.OrderNew, new BitfinexNewOrder
            {
                Amount              = quantity,
                OrderType           = type,
                Symbol              = symbol,
                Price               = price,
                ClientOrderId       = clientOrderId,
                Flags               = flags,
                GroupId             = groupId,
                PriceAuxiliaryLimit = priceAuxiliaryLimit,
                PriceOCOStop        = priceOcoStop,
                PriceTrailing       = priceTrailing,
                Meta = affCode == null ? null : new BitfinexMeta()
                {
                    AffiliateCode = affCode
                }
            });

            return(await _baseClient.QueryInternalAsync <BitfinexOrder>(this, query, true).ConfigureAwait(false));
        }
        /// <summary>
        /// Cancels an order
        /// </summary>
        /// <param name="orderId">The id of the order to cancel</param>
        /// <returns></returns>
        public async Task <CallResult <BitfinexOrder> > CancelOrderAsync(long orderId)
        {
            log.Write(LogVerbosity.Info, "Going to cancel order " + orderId);
            var query = new BitfinexSocketQuery(orderId.ToString(), BitfinexEventType.OrderCancel, new JObject {
                ["id"] = orderId
            });

            return(await Query <BitfinexOrder>(query, true).ConfigureAwait(false));
        }
예제 #5
0
        ///// <summary>
        ///// Cancel all open orders
        ///// </summary>
        ///// <returns></returns>
        //public CallResult<bool> CancelAllOrders() => CancelAllOrdersAsync().Result;
        ///// <summary>
        ///// Cancel all open orders
        ///// </summary>
        ///// <returns></returns>
        //public async Task<CallResult<bool>> CancelAllOrdersAsync()
        //{
        //    // Doesn't seem to work even though it is implemented as described at https://docs.bitfinex.com/v2/reference#ws-input-order-cancel-multi
        //    log.Write(LogLevel.Information, "Going to cancel all orders");
        //    var query = new BitfinexSocketQuery(null, BitfinexEventType.OrderCancelMulti, new BitfinexMultiCancel { All = true });

        //    return await Query<bool>(query, true).ConfigureAwait(false);
        //}

        /// <inheritdoc />
        public async Task <CallResult <BitfinexOrder> > CancelOrderAsync(long orderId)
        {
            _log.Write(LogLevel.Information, "Going to cancel order " + orderId);
            var query = new BitfinexSocketQuery(orderId.ToString(CultureInfo.InvariantCulture), BitfinexEventType.OrderCancel, new JObject {
                ["id"] = orderId
            });

            return(await _baseClient.QueryInternalAsync <BitfinexOrder>(this, query, true).ConfigureAwait(false));
        }
        /// <summary>
        /// Updates an order
        /// </summary>
        /// <param name="orderId">The id of the order to update</param>
        /// <param name="price">The new price of the order</param>
        /// <param name="amount">The new amount of the order</param>
        /// <param name="delta">The delta to change</param>
        /// <param name="priceAuxiliaryLimit">the new aux limit price</param>
        /// <param name="priceTrailing">The new trailing price</param>
        /// <param name="flags">The new flags</param>
        /// <returns></returns>
        public async Task <CallResult <BitfinexOrder> > UpdateOrderAsync(long orderId, decimal?price = null, decimal?amount = null, decimal?delta = null, decimal?priceAuxiliaryLimit = null, decimal?priceTrailing = null, OrderFlags?flags = null)
        {
            log.Write(LogVerbosity.Info, "Going to update order " + orderId);
            var query = new BitfinexSocketQuery(orderId.ToString(), BitfinexEventType.OrderUpdate, new BitfinexUpdateOrder
            {
                OrderId             = orderId,
                Amount              = amount,
                Price               = price,
                Flags               = flags,
                PriceAuxiliaryLimit = priceAuxiliaryLimit?.ToString(CultureInfo.InvariantCulture),
                PriceTrailing       = priceTrailing?.ToString(CultureInfo.InvariantCulture)
            });

            return(await Query <BitfinexOrder>(query, true).ConfigureAwait(false));
        }
예제 #7
0
        /// <inheritdoc />
        public async Task <CallResult <BitfinexOrder> > UpdateOrderAsync(long orderId, decimal?price = null, decimal?quantity = null, decimal?delta = null, decimal?priceAuxiliaryLimit = null, decimal?priceTrailing = null, OrderFlags?flags = null)
        {
            _log.Write(LogLevel.Information, "Going to update order " + orderId);
            var query = new BitfinexSocketQuery(orderId.ToString(CultureInfo.InvariantCulture), BitfinexEventType.OrderUpdate, new BitfinexUpdateOrder
            {
                OrderId             = orderId,
                Amount              = quantity,
                Price               = price,
                Flags               = flags,
                PriceAuxiliaryLimit = priceAuxiliaryLimit?.ToString(CultureInfo.InvariantCulture),
                PriceTrailing       = priceTrailing?.ToString(CultureInfo.InvariantCulture)
            });

            return(await _baseClient.QueryInternalAsync <BitfinexOrder>(this, query, true).ConfigureAwait(false));
        }