public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var timestamp = (long)DateTime.UtcNow.ToUnixTimeStamp();

            var body = new Dictionary <string, object>
            {
                { "method", "trade" },
                { "moment", timestamp },
                { "type", context.IsBuy ? "buy" : "sell" },
                { "currency", context.Pair.Asset1.ShortCode },
                { "amount", context.Quantity },
                { "payment_currency", context.Pair.Asset2.ShortCode },
                { "rate", context.Rate.ToDecimalValue() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.order_id));
        }
示例#2
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            if (context.Pair == null)
            {
                throw new MarketNotSpecifiedException(this);
            }

            string side = context.IsBuy ? "buy" : "sell";

            var body = new Dictionary <string, object>
            {
                { "market", context.Pair.ToTicker(this).ToLower() },
                { "side", side },
                { "volume", context.Quantity.ToDecimalValue() },
                { "price", context.Rate.ToDecimalValue() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.id));
        }
示例#3
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProviderPrivate.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "pair", context.Pair.ToTicker(this) },
                { "type", context.IsBuy ? "buy" : "sell" },
                { "amount", context.Quantity },
                { "rate", context.Rate.ToDecimalValue() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            if (r.success == false)
            {
                throw new ApiResponseException("Unsuccessful request in PlaceOrderLimitAsync");
            }

            return(new PlacedOrderLimitResponse(r.returnData.order_id));
        }
示例#4
0
        private void PlaceOrderLimit(IOrderLimitProvider provider, AssetPair market, bool isBuy, decimal quantity, Money rate)
        {
            var context = new PlaceOrderLimitContext(UserContext.Current, market, isBuy, quantity, rate);

            var r = AsyncContext.Run(() => provider.PlaceOrderLimitAsync(context));

            Assert.IsTrue(!String.IsNullOrWhiteSpace(r.RemoteOrderGroupId));
            Trace.WriteLine($"Remote trade order id: {r.RemoteOrderGroupId}");
        }
示例#5
0
        private void PlaceOrderLimitTest(IOrderLimitProvider provider, AssetPair market, bool isBuy, Money quantity, Money rate)
        {
            var context = new PlaceOrderLimitContext(UserContext.Testing, market, isBuy, quantity, rate);

            var r = AsyncContext.Run(() => provider.PlaceOrderLimitAsync(context));

            Assert.True(!String.IsNullOrWhiteSpace(r.RemoteOrderGroupId), "Remote id is empty.");
            OutputWriter.WriteLine($"Remote trade order id: {r.RemoteOrderGroupId}");
        }
示例#6
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.NewOrderAsync(context.Pair.ToTicker(this), context.IsBuy? "BUY" : "SELL", context.Rate, context.Quantity).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.data.orderOid));
        }
示例#7
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api        = ApiProvider.GetApi(context);
            var remotePair = context.Pair.ToTicker(this);

            var r = context.IsSell ?
                    await api.GetMarketSellLimit(remotePair, context.Quantity, context.Rate).ConfigureAwait(false) :
                    await api.GetMarketBuyLimit(remotePair, context.Quantity, context.Rate).ConfigureAwait(false);

            CheckResponseErrors(r);

            return(new PlacedOrderLimitResponse(r.result.uuid));
        }
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            // Get payment method.
            var rPaymentMethodsRaw = await api.GetPaymentMethodsAsync().ConfigureAwait(false);

            CheckResponseErrors(rPaymentMethodsRaw);

            var rPaymentMethods = rPaymentMethodsRaw.GetContent();

            if (rPaymentMethods.data.Count == 0)
            {
                throw new ApiResponseException("No payment methods found in account", this);
            }

            // TODO: AY: HH, we don't support payment methods selection. Maybe we need to consider it in Prime architecture. Just selecting first payment method at the moment.
            var paymentMethodId = rPaymentMethods.data.FirstOrDefault()?.id;

            var body = new Dictionary <string, object>()
            {
                { "amount", context.Quantity.ToDecimalValue() }, // Buy amount without fees.
                { "currency", context.Pair.Asset1 },
                { "payment_method", paymentMethodId }
            };

            // Get account number.
            var asset      = context.Pair.Asset1.ToRemoteCode(this);
            var rAccountId = await GetFirstAccountId(context,
                                                     x => string.Equals(x.currency, asset, StringComparison.OrdinalIgnoreCase)).ConfigureAwait(false);

            var accountId = rAccountId.Result;

            // Call endpoint.
            var rRaw = context.IsBuy
                ? await api.PlaceBuyOrderAsync(accountId, body).ConfigureAwait(false)
                : await api.PlaceSellOrderAsync(accountId, body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.data.id)
            {
                ApiHitsCount = rAccountId.ApiHitsCount + 2
            });
        }
        public virtual async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProviderPrivate.GetApi(context);

            var body = CreatePostBody();

            body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.Trade]);
            body.Add("pair", context.Pair.ToTicker(this).ToLower());
            body.Add("type", context.IsBuy ? "buy" : "sell");
            body.Add("rate", context.Rate.ToDecimalValue());
            body.Add("amount", context.Quantity.ToDecimalValue());

            var r = await api.TradeAsync(body).ConfigureAwait(false);

            CheckResponse(r);

            return(new PlacedOrderLimitResponse(r.return_.order_id.ToString()));
        }
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var buy      = context.IsBuy;
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var body = CreatePoloniexBody(buy ? PoloniexBodyType.LimitOrderBuy : PoloniexBodyType.LimitOrderSell);

            body.Add("currencyPair", pairCode);
            body.Add("rate", context.Rate);
            body.Add("amount", context.Quantity);

            //fillOrKill //immediateOrCancel //postOnly

            var r = await api.PlaceOrderLimitAsync(body).ConfigureAwait(false);

            return(new PlacedOrderLimitResponse(r.orderNumber, r.resultingTrades.Select(x => x.tradeID)));
        }
示例#11
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api        = ApiProvider.GetApi(context);
            var remotePair = context.Pair.ToTicker(this);

            var quantity = context.Quantity.ToDecimalValue();
            var rate     = context.Rate.ToDecimalValue();

            var rRaw = context.IsSell ?
                       await api.PlaceMarketSellLimit(remotePair, quantity, rate).ConfigureAwait(false) :
                       await api.PlaceMarketBuyLimit(remotePair, quantity, rate).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.result.uuid));
        }
示例#12
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "amount", context.Quantity.ToDecimalValue() },
                { "rate", context.Rate.ToDecimalValue() },
                { "currencyPair", context.Pair.ToTicker(this) }
            };

            var rRaw = await api.NewOrderAsync(context.IsBuy? "buy" : "sell", body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(null));
        }
示例#13
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var buy      = context.IsBuy;
            var api      = ApiProvider.GetApi(context);
            var pairCode = context.Pair.ToTicker(this);

            var body = CreatePoloniexBody(buy ? PoloniexBodyType.LimitOrderBuy : PoloniexBodyType.LimitOrderSell);

            body.Add("currencyPair", pairCode);
            body.Add("rate", context.Rate.ToDecimalValue());
            body.Add("amount", context.Quantity.ToDecimalValue());

            var rRaw = await api.PlaceOrderLimitAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.orderNumber, r.resultingTrades.Select(x => x.tradeID)));
        }
示例#14
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "market", context.Pair.ToTicker(this).ToLower() },
                { "side", context.IsBuy ? "buy" : "sell" },
                { "volume", context.Quantity.ToDecimalValue() },
                { "price", context.Rate.ToDecimalValue() }
            };

            //TODO: SC - Documentation does not show example of response, so this has to be tested with real money to see what the endpoint returns
            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);
            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.id));
        }
示例#15
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new BitfinexSchema.NewOrderRequest.Descriptor
            {
                symbol = context.Pair.ToTicker(this),
                amount = context.Quantity.ToString(CultureInfo.InvariantCulture),
                price  = context.Rate.ToDecimalValue().ToString(CultureInfo.InvariantCulture),
                side   = context.IsSell ? "sell" : "buy"
            };

            var rRaw = await api.PlaceNewOrderAsync(body).ConfigureAwait(false);

            CheckBitfinexResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.order_id.ToString()));
        }
示例#16
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var market = context.Pair.ToTicker(this);
            var side   = context.IsBuy ? "Buy" : "Sell";

            var rRaw = await api.CreateNewLimitOrderAsync("Limit",
                                                          side,
                                                          market,
                                                          context.Quantity.ToDecimalValue(),
                                                          context.Rate.ToDecimalValue()
                                                          ).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.orderID));
        }
示例#17
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProviderPrivate.GetApi(context);

            var body = CreateBody();

            body.Add("method", "Trade");
            body.Add("pair", context.Pair.ToTicker(this));
            body.Add("type", context.IsBuy ? "buy" : "sell");
            body.Add("amount", context.Quantity);
            body.Add("rate", context.Rate.ToDecimalValue());

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.returnData.order_id));
        }
示例#18
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = CreatePostBody("trade");

            body.Add("type", context.IsBuy ? "buy" : "sell");
            body.Add("currency", context.Pair.Asset1.ToRemoteCode(this));
            body.Add("amount", context.Quantity);
            body.Add("payment_currency", context.Pair.Asset2.ToRemoteCode(this));
            body.Add("rate", context.Rate.ToDecimalValue());

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.order_id));
        }
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "listingCurrency", context.Pair.Asset1.ShortCode },
                { "referenceCurrency", context.Pair.Asset2.ShortCode },
                { "type", context.IsBuy ? "buy" : "sell" },
                { "amount", context.Quantity.ToDecimalValue().ToString() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r));
        }
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new CryptopiaSchema.SubmitTradeRequest
            {
                Market = context.Pair.ToTicker(this, "/"),
                Type   = context.IsBuy ? "Buy" : "Sell",
                Rate   = context.Rate,
                Amount = context.Quantity
            };

            var rRaw = await api.SubmitTradeAsync(body).ConfigureAwait(false);

            CheckCryptopiaResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.Data.OrderId.ToString()));
        }
示例#21
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "Symbol", context.Pair.ToTicker(this) },
                { "Side", context.IsBuy ? "Buy" : "Sell" },
                { "Type", "Limit" },
                { "Amount", context.Quantity.ToDecimalValue() },
                { "Price", context.Rate.ToDecimalValue() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.Id));
        }
示例#22
0
        //TODO: SC: This method still needs to be tested with a balance greater than 0 in the account, to see what it returns (documentation does not explain). It should return the order ID.
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "pair", context.Pair.ToTicker(this, '/').ToUpper() },
                { "side", context.IsBuy ? "BUY" : "SELL" },
                { "type", "LIMIT" },
                { "amount", context.Quantity.ToDecimalValue() },
                { "limit", context.Rate.ToDecimalValue() }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.data?.order_id));
        }
示例#23
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "currencyPair", context.Pair.ToTicker(this).ToLower() },
                { "amount", context.Quantity.ToDecimalValue() },
                { "price", context.Rate.ToDecimalValue() }
            };

            var rRaw = context.IsBuy
                ? await api.PlaceMarketBuyLimit(body).ConfigureAwait(false)
                : await api.PlaceMarketSellLimit(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.data));
        }
示例#24
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "amount", context.Quantity.ToDecimalValue() },
                { "rate", context.Rate.ToDecimalValue() },
                { "cryptoCurrency", context.Pair.Asset1.ShortCode },
                { "realCurrency", context.Pair.Asset2.ShortCode },
                { "type", context.IsBuy ? "buy" : "sell" }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(null)); //TODO - SC - Unable to see what object is returned since API doc does not show response
        }
示例#25
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api  = ApiProvider.GetApi(context);
            var pair = context.Pair.ToTicker(this);

            var body = CreateHitBtcRequestBody();

            body.Add("symbol", pair);
            body.Add("side", context.IsBuy ? "buy" : "sell");
            body.Add("quantity", context.Quantity.ToDecimalValue());
            body.Add("price", context.Rate.ToDecimalValue());
            body.Add("type", "limit");
            body.Add("timeInForce", "GTC");
            body.Add("strictValidate", "false");

            var rRaw = await api.CreateNewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.clientOrderId));
        }
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            if (context.Pair == null)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            var body = CreateBody();

            body.Add("command", context.IsBuy ? "buy" : "sell");
            body.Add("amount", context.Quantity.ToDecimalValue());
            body.Add("price", context.Rate.ToDecimalValue());
            body.Add("market", context.Pair.ToTicker(this).ToLower());

            var rRaw = await api.PlaceLimitOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.order_number));
        }
示例#27
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "MsgType", "D" },
                { "ClOrdID", 1 },
                { "Symbol", context.Pair.ToTicker(this) },
                { "Side", context.IsBuy ? "1" : "2" },
                { "OrdType", "2" },
                { "Price", context.Rate.ToInt64(null) },
                { "OrderQty", context.Quantity.ToInt32(null) },
                { "BrokerID", 5 }
            };

            var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.OrderID));
        }
 public Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
 {
     throw new NotImplementedException();
 }