CryptoTradingFramework icon indicating copy to clipboard operation
CryptoTradingFramework copied to clipboard

Do you support futures?

Open xyong6024 opened this issue 3 years ago • 3 comments

view binance api in project ,not found buy long or buy short

xyong6024 avatar Aug 21 '21 15:08 xyong6024

Hi, I added BuyLong and SellLong (previously Buy and Sell) and BuyShort and SellShort. The last two methods I implemented only for Binance.

Here is the code:

       public override TradingResult BuyLong(AccountInfo account, Ticker ticker, double rate, double amount) {
            return MakeTrade(account, ticker, rate, amount, "BUY", "LONG");
       }

       public override TradingResult BuyShort(AccountInfo account, Ticker ticker, double rate, double amount) {
            return MakeTrade(account, ticker, rate, amount, "BUY", "SHORT");
       }

       public override TradingResult SellShort(AccountInfo account, Ticker ticker, double rate, double amount) {
            return MakeTrade(account, ticker, rate, amount, "SELL", "SHORT");
       }

       public override TradingResult SellLong(AccountInfo account, Ticker ticker, double rate, double amount) {
            return MakeTrade(account, ticker, rate, amount, "SELL", "LONG");
       }

       protected TradingResult MakeTrade(AccountInfo account, Ticker ticker, double rate, double amount, string side, string positionSide) {
            string queryString = string.Format("symbol={0}&side={1}&positionSide={2}&quantity={3:0.########}&price={4:0.########}&timestamp={5}&type=LIMIT&timeInForce=GTC&recvWindow=5000", 
                ticker.Name, side, positionSide, amount, rate, GetNonce());
            string signature = account.GetSign(queryString);

            string address = string.Format("https://api.binance.com/api/v3/order?{0}&signature={1}",
                queryString, signature);
            MyWebClient client = GetWebClient();

            client.Headers.Clear();
            client.Headers.Add("X-MBX-APIKEY", account.ApiKey);

            try {
                return OnTradeResult(account, ticker, client.UploadValues(address, new HttpRequestParamsCollection()));
            }
            catch(Exception e) {
                LogManager.Default.Log(e.ToString());
                return null;
            }
        }

I implement them according this documentation: https://binance-docs.github.io/apidocs/futures/en/#new-order-trade

ArsenAbazian avatar Aug 21 '21 17:08 ArsenAbazian

Thank you. I have a look. There is a lack of futures module on the whole. For example, the front desk has only the spot part, but there is no futures market part, including the account is also the spot account

xyong6024 avatar Aug 22 '21 04:08 xyong6024

I see... Well, currently I am busy with another project (which is, honesty, more preferrable, because one pays me for that). I'll implement this functionality when I have time. Currently you can do it by your own, it is not so difficult. Please take a look at binancemodule.cs and try to implement similar functionality using this documentation.

ArsenAbazian avatar Aug 23 '21 10:08 ArsenAbazian