ArsenAbazian / CryptoTradingFramework

A self hosted, cryptocurrency trading bot and framework supporting multiple exchanges with GUI
Other
174 stars 81 forks source link

Do you support futures? #22

Open xyong6024 opened 3 years ago

xyong6024 commented 3 years ago

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

ArsenAbazian commented 3 years ago

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

xyong6024 commented 3 years ago

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

ArsenAbazian commented 3 years ago

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.