Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do you support futures? #22

Open
xyong6024 opened this issue Aug 21, 2021 · 3 comments
Open

Do you support futures? #22

xyong6024 opened this issue Aug 21, 2021 · 3 comments

Comments

@xyong6024
Copy link

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

@ArsenAbazian
Copy link
Owner

ArsenAbazian commented Aug 21, 2021

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
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants