Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
/ OKEx.Net Public archive

Open source .Net API wrapper for the @okex V5 Rest API and V5 Websocket API

License

Notifications You must be signed in to change notification settings

burakoner/OKEx.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Critical Announcement

It's highly recommended to migrate to OKX.Api in order to get next updates and avoid from CryptoExchange.Net derived errors. It's available on both Github and Nuget

Github Repository: https://github.com/burakoner/OKX.Api

Nuget Package: https://www.nuget.org/packages/OKX.Api

Icon! OKEx.Net

A .Net wrapper for the OKEx API as described on OKEx, including all features the API provides using clear and readable objects.

If you think something is broken, something is missing or have any questions, please open an Issue

CryptoExchange.Net

Implementation is build upon the CryptoExchange.Net library, make sure to also check out the documentation on that: docs

My CryptoExchange.Net implementations:

Image

OKEx

Image

Chiliz

Image

BitMax

Image

BtcTurk

Image

Paribu

Image

Thodex

Image

Coinzo

Image

Tatum

JKorf CryptoExchange.Net implementations:

Image

Binance

Image

Bitfinex

Image

Bittrex

Image

CoinEx

Image

Huobi

Image

Kraken

Image

Kucoin

Implementations from third parties:

Image

Bitmex

Image

Exante

Image

HitBTC

Image

Liquid

Image

LiveCoin

Image

Switcheo

Donations

Donations are greatly appreciated and a motivation to keep improving.

BTC: 33WbRKqt7wXARVdAJSu1G1x3QnbyPtZ2bH
ETH: 0x65b02db9b67b73f5f1e983ae10796f91ded57b64

Installation

Nuget version Nuget downloads Available on Nuget.

PM> Install-Package OKEx.Net

To get started with OKEx.Net first you will need to get the library itself. The easiest way to do this is to install the package into your project using NuGet. Using Visual Studio this can be done in two ways.

Using the package manager

In Visual Studio right click on your solution and select 'Manage NuGet Packages for solution...'. A screen will appear which initially shows the currently installed packages. In the top bit select 'Browse'. This will let you download net package from the NuGet server. In the search box type 'OKEx.Net' and hit enter. The OKEx.Net package should come up in the results. After selecting the package you can then on the right hand side select in which projects in your solution the package should install. After you've selected all project you wish to install and use OKEx.Net in hit 'Install' and the package will be downloaded and added to you projects.

Using the package manager console

In Visual Studio in the top menu select 'Tools' -> 'NuGet Package Manager' -> 'Package Manager Console'. This should open up a command line interface. On top of the interface there is a dropdown menu where you can select the Default Project. This is the project that OKEx.Net will be installed in. After selecting the correct project type Install-Package OKEx.Net in the command line interface. This should install the latest version of the package in your project.

After doing either of above steps you should now be ready to actually start using OKEx.Net.

Getting started

After installing it's time to actually use it. To get started we have to add the OKEx.Net namespace: using Okex.Net;.

OKEx.Net provides two clients to interact with the OKEx API. The OkexClient provides all rest API calls. The OkexSocketClient provides functions to interact with the websocket provided by the OKEx API. Both clients are disposable and as such can be used in a usingstatement.

Rest Api Examples

Public Endpoints (Unsigned)

OkexClient api = new OkexClient();
var public_01 = api.GetInstruments(OkexInstrumentType.Spot);
var public_02 = api.GetInstruments(OkexInstrumentType.Margin);
var public_03 = api.GetInstruments(OkexInstrumentType.Swap);
var public_04 = api.GetInstruments(OkexInstrumentType.Futures);
var public_05 = api.GetInstruments(OkexInstrumentType.Option, "USD");
var public_06 = api.GetDeliveryExerciseHistory(OkexInstrumentType.Futures, "BTC-USD");
var public_07 = api.GetDeliveryExerciseHistory(OkexInstrumentType.Option, "BTC-USD");
var public_08 = api.GetOpenInterests(OkexInstrumentType.Futures);
var public_09 = api.GetOpenInterests(OkexInstrumentType.Option, "BTC-USD");
var public_10 = api.GetOpenInterests(OkexInstrumentType.Swap);
var public_11 = api.GetFundingRates("BTC-USD-SWAP");
var public_12 = api.GetFundingRateHistory("BTC-USD-SWAP");
var public_13 = api.GetLimitPrice("BTC-USD-SWAP");
var public_14 = api.GetOptionMarketData("BTC-USD");
var public_15 = api.GetEstimatedPrice("BTC-USD-211004-41000-C");
var public_16 = api.GetDiscountInfo();
var public_17 = api.GetSystemTime();
var public_18 = api.GetLiquidationOrders(OkexInstrumentType.Futures, underlying: "BTC-USD", alias: OkexInstrumentAlias.Quarter, state: OkexLiquidationState.Unfilled);
var public_19 = api.GetMarkPrices(OkexInstrumentType.Futures);
var public_20 = api.GetPositionTiers(OkexInstrumentType.Futures, OkexMarginMode.Isolated, "BTC-USD");
var public_21 = api.GetInterestRates();
var public_22 = api.GetVIPInterestRates();
var public_23 = api.GetUnderlying(OkexInstrumentType.Futures);
var public_24 = api.GetUnderlying(OkexInstrumentType.Option);
var public_25 = api.GetUnderlying(OkexInstrumentType.Swap);
var public_26 = api.GetInsuranceFund(OkexInstrumentType.Margin, currency:"BTC");
var public_27 = api.UnitConvert( OkexConvertType.CurrencyToContract, instrumentId:"BTC-USD-SWAP", price:35000, size:0.888m);

Market Endpoints (Unsigned)

OkexClient api = new OkexClient();
var market_01 = api.GetTickers(OkexInstrumentType.Spot);
var market_02 = api.GetTicker("BTC-USDT");
var market_03 = api.GetIndexTickers(instrumentId: "BTC-USDT");
var market_04 = api.GetOrderBook("BTC-USDT", 40);
var market_05 = api.GetCandlesticks("BTC-USDT", OkexPeriod.OneHour);
var market_06 = api.GetCandlesticksHistory("BTC-USDT", OkexPeriod.OneHour);
var market_07 = api.GetIndexCandlesticks("BTC-USDT", OkexPeriod.OneHour);
var market_08 = api.GetMarkPriceCandlesticks("BTC-USDT", OkexPeriod.OneHour);
var market_09 = api.GetTrades("BTC-USDT");
var market_10 = api.GetTradesHistory("BTC-USDT");
var market_11 = api.Get24HourVolume();
var market_12 = api.GetOracle();
var market_13 = api.GetIndexComponents("BTC-USDT");
var market_14 = api.GetBlockTickers(OkexInstrumentType.Spot);
var market_15 = api.GetBlockTickers(OkexInstrumentType.Futures);
var market_16 = api.GetBlockTickers(OkexInstrumentType.Option);
var market_17 = api.GetBlockTickers(OkexInstrumentType.Swap);
var market_18 = api.GetBlockTicker("BTC-USDT");
var market_19 = api.GetBlockTrades("BTC-USDT");

Trading Endpoints (Unsigned)

OkexClient api = new OkexClient();
var rubik_01 = api.GetRubikSupportCoin();
var rubik_02 = api.GetRubikTakerVolume("BTC", OkexInstrumentType.Spot);
var rubik_03 = api.GetRubikMarginLendingRatio("BTC", OkexPeriod.OneDay);
var rubik_04 = api.GetRubikLongShortRatio("BTC", OkexPeriod.OneDay);
var rubik_05 = api.GetRubikContractSummary("BTC", OkexPeriod.OneDay);
var rubik_06 = api.GetRubikOptionsSummary("BTC", OkexPeriod.OneDay);
var rubik_07 = api.GetRubikPutCallRatio("BTC", OkexPeriod.OneDay);
var rubik_08 = api.GetRubikInterestVolumeExpiry("BTC", OkexPeriod.OneDay);
var rubik_09 = api.GetRubikInterestVolumeStrike("BTC", "20210623", OkexPeriod.OneDay);
var rubik_10 = api.GetRubikTakerFlow("BTC", OkexPeriod.OneDay);

Account Endpoints (Signed)

OkexClient api = new OkexClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
var account_01 = api.GetAccountBalance();
var account_02 = api.GetAccountPositions();
var account_03 = api.GetAccountPositionsHistory();
var account_04 = api.GetAccountPositionRisk();
var account_05 = api.GetBillHistory();
var account_06 = api.GetBillArchive();
var account_07 = api.GetAccountConfiguration();
var account_08 = api.SetAccountPositionMode(OkexPositionMode.LongShortMode);
var account_09 = api.GetAccountLeverage("BTC-USD-211008", OkexMarginMode.Isolated);
var account_10 = api.SetAccountLeverage(30, null, "BTC-USD-211008", OkexMarginMode.Isolated, OkexPositionSide.Long);
var account_11 = api.GetMaximumAmount("BTC-USDT", OkexTradeMode.Isolated);
var account_12 = api.GetMaximumAvailableAmount("BTC-USDT", OkexTradeMode.Isolated);
var account_13 = api.SetMarginAmount("BTC-USDT", OkexPositionSide.Long, OkexMarginAddReduce.Add, 100.0m);
var account_14 = api.GetMaximumLoanAmount("BTC-USDT", OkexMarginMode.Cross);
var account_15 = api.GetFeeRates(OkexInstrumentType.Spot, category: OkexFeeRateCategory.ClassA);
var account_16 = api.GetFeeRates(OkexInstrumentType.Futures, category: OkexFeeRateCategory.ClassA);
var account_17 = api.GetInterestAccrued();
var account_18 = api.GetInterestRate();
var account_19 = api.SetGreeks(OkexGreeksType.GreeksInCoins);
var account_20 = api.GetMaximumWithdrawals();

SubAccount Endpoints (Signed)

OkexClient api = new OkexClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
var subaccount_01 = api.GetSubAccounts();
var subaccount_02 = api.ResetSubAccountApiKey("subAccountName", "apiKey", "apiLabel", true, true, "");
var subaccount_03 = api.GetSubAccountTradingBalances("subAccountName");
var subaccount_04 = api.GetSubAccountFundingBalances("subAccountName");
var subaccount_05 = api.GetSubAccountBills();
var subaccount_06 = api.TransferBetweenSubAccounts("BTC", 0.5m, OkexAccount.Funding, OkexAccount.Unified, "fromSubAccountName", "toSubAccountName");

Funding Endpoints (Signed)

OkexClient api = new OkexClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
var funding_01 = api.GetCurrencies();
var funding_02 = api.GetFundingBalance();
var funding_03 = api.FundTransfer("BTC", 0.5m, OkexTransferType.TransferWithinAccount, OkexAccount.Margin, OkexAccount.Spot);
var funding_04 = api.GetFundingBillDetails("BTC");
var funding_05 = api.GetLightningDeposits("BTC", 0.001m);
var funding_06 = api.GetDepositAddress("BTC");
var funding_07 = api.GetDepositAddress("USDT");
var funding_08 = api.GetDepositHistory("USDT");
var funding_09 = api.Withdraw("USDT", 100.0m, OkexWithdrawalDestination.DigitalCurrencyAddress, "toAddress", "password", 1.0m, "USDT-TRC20");
var funding_10 = api.GetLightningWithdrawals("BTC", "invoice", "password");
var funding_11 = api.GetWithdrawalHistory("USDT");
var funding_12 = api.GetSavingBalances();
var funding_13 = api.SavingPurchaseRedemption("USDT", 10.0m, OkexSavingActionSide.Purchase);

Trade Endpoints (Signed)

OkexClient api = new OkexClient();
api.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");
var trade_01 = api.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Long, OkexOrderType.MarketOrder, 0.1m);
var trade_02 = api.PlaceMultipleOrders(new List<OkexOrderPlaceRequest>());
var trade_03 = api.CancelOrder("BTC-USDT");
var trade_04 = api.CancelMultipleOrders(new List<OkexOrderCancelRequest>());
var trade_05 = api.AmendOrder("BTC-USDT");
var trade_06 = api.AmendMultipleOrders(new List<OkexOrderAmendRequest>());
var trade_07 = api.ClosePosition("BTC-USDT", OkexMarginMode.Isolated);
var trade_08 = api.GetOrderDetails("BTC-USDT");
var trade_09 = api.GetOrderList();
var trade_10 = api.GetOrderHistory( OkexInstrumentType.Swap);
var trade_11 = api.GetOrderArchive( OkexInstrumentType.Futures);
var trade_12 = api.GetTransactionHistory();
var trade_13 = api.GetTransactionArchive( OkexInstrumentType.Futures);
var trade_14 = api.PlaceAlgoOrder("BTC-USDT", OkexTradeMode.Isolated, OkexOrderSide.Sell, OkexAlgoOrderType.Conditional, 0.1m);
var trade_15 = api.CancelAlgoOrder(new List<OkexAlgoOrderRequest>());
var trade_16 = api.CancelAdvanceAlgoOrder(new List<OkexAlgoOrderRequest>());
var trade_17 = api.GetAlgoOrderList( OkexAlgoOrderType.OCO);
var trade_18 = api.GetAlgoOrderHistory( OkexAlgoOrderType.Conditional);

Websocket Api Examples

The OKEx.Net socket client provides several socket endpoint to which can be subscribed.

Public Feeds

/* OKEx Socket Client */
var ws = new OkexSocketClient();

/* Sample Pairs */
var sample_pairs = new List<string> { "BTC-USDT", "LTC-USDT", "ETH-USDT", "XRP-USDT", "BCH-USDT", "EOS-USDT", "OKB-USDT", "ETC-USDT", "TRX-USDT", "BSV-USDT", "DASH-USDT", "NEO-USDT", "QTUM-USDT", "XLM-USDT", "ADA-USDT", "AE-USDT", "BLOC-USDT", "EGT-USDT", "IOTA-USDT", "SC-USDT", "WXT-USDT", "ZEC-USDT", };

/* WS Subscriptions */
var subs = new List<UpdateSubscription>();

/* Instruments (Public) */
ws.SubscribeToInstruments(OkexInstrumentType.Spot, (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Tickers (Public) */
foreach (var pair in sample_pairs)
{
    var subscription = ws.SubscribeToTickers(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
    subs.Add(subscription.Data);
}

/* Unsubscribe */
foreach (var sub in subs)
{
    _ = ws.UnsubscribeAsync(sub);
}

/* Interests (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToInterests(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Candlesticks (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToCandlesticks(pair, OkexPeriod.FiveMinutes, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Trades (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToTrades(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Estimated Price (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToTrades(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Mark Price (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToMarkPrice(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Mark Price Candlesticks (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToMarkPriceCandlesticks(pair, OkexPeriod.FiveMinutes, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Limit Price (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToPriceLimit(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Order Book (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToOrderBook(pair, OkexOrderBookType.OrderBook, (data) =>
    {
        if (data != null && data.Asks != null && data.Asks.Count() > 0 && data.Bids != null && data.Bids.Count() > 0)
        {
            // ... Your logic here
        }
    });
}

/* Option Summary (Public) */
ws.SubscribeToOptionSummary("USD", (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Funding Rates (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToFundingRates(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Index Candlesticks (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToIndexCandlesticks(pair, OkexPeriod.FiveMinutes, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* Index Tickers (Public) */
foreach (var pair in sample_pairs)
{
    ws.SubscribeToIndexTickers(pair, (data) =>
    {
        if (data != null)
        {
            // ... Your logic here
        }
    });
}

/* System Status (Public) */
ws.SubscribeToSystemStatus((data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

Private Feeds

/* OKEx Socket Client */
var ws = new OkexSocketClient();
ws.SetApiCredentials("XXXXXXXX-API-KEY-XXXXXXXX", "XXXXXXXX-API-SECRET-XXXXXXXX", "XXXXXXXX-API-PASSPHRASE-XXXXXXXX");

/* Account Updates (Private) */
ws.SubscribeToAccountUpdates((data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Position Updates (Private) */
ws.SubscribeToPositionUpdates(OkexInstrumentType.Futures, "INSTRUMENT", "UNDERLYING", (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Balance And Position Updates (Private) */
ws.SubscribeToBalanceAndPositionUpdates((data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Order Updates (Private) */
ws.SubscribeToOrderUpdates(OkexInstrumentType.Futures, "INSTRUMENT", "UNDERLYING", (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Algo Order Updates (Private) */
ws.SubscribeToAlgoOrderUpdates(OkexInstrumentType.Futures, "INSTRUMENT", "UNDERLYING", (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

/* Advance Algo Order Updates (Private) */
ws.SubscribeToAdvanceAlgoOrderUpdates(OkexInstrumentType.Futures, "INSTRUMENT", "UNDERLYING", (data) =>
{
    if (data != null)
    {
        // ... Your logic here
    }
});

Release Notes

Please refer to VERSION file.

About

Open source .Net API wrapper for the @okex V5 Rest API and V5 Websocket API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages