burakoner / OKEx.Net

Open source .Net API wrapper for the @OKEx V5 Rest API and V5 Websocket API
MIT License
86 stars 48 forks source link

Structure to use for Futures trading #34

Closed overstartup closed 2 years ago

overstartup commented 2 years ago

I want to use it, but it is a title bit difficult to understand how it works. Why it has different structure than other component (binance.net)?

There is any clear example to use for Futures?

burakoner commented 2 years ago

Okex has unified all endpoints for different trading tools in V5 API. You can check difference at these links. https://www.okex.com/docs/en/ and https://www.okex.com/docs-v5/en/. In earlier versions of OKEx.Net repository you could guess all methods for one trading tool. For example all Futures methods started with Futures_ prefix. Check last V3 wrapper at this link https://github.com/burakoner/OKEx.Net/tree/V3 .

But once OKEx unified all endpoints you cant guess anymore. Because If you want to place an order in V5, you use same endpoint for Spot, Margin, Swap, Futures, Options. So I can only advice you to read V5 API documentation and examples in Readme file on this repository https://github.com/burakoner/OKEx.Net/blob/master/README.md

overstartup commented 2 years ago

@burakoner thank you very much for your description. Could you please tell me how i can get last PriceChangePercent and PriceChange in futures?

burakoner commented 2 years ago
// Okex Client
OkexClient cli = new OkexClient();

// Sample for a ticker for specific instruemnt
var tickerOne = cli.GetTicker("BTC-USDT-211231");
var priceChange = tickerOne.Data.LastPrice - tickerOne.Data.Open;
var priceChangePercent = 100.0m * priceChange / tickerOne.Data.Open;

// Sample for all tickers
var tickerAll = cli.GetTickers(OkexInstrumentType.Futures);
foreach(var ticker in tickerAll.Data)
{
    var change = ticker.LastPrice - ticker.Open;
    var changePercent = 100.0m * change / ticker.Open;
}