Coder Social home page Coder Social logo

jkorf / okx.net Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 15.0 4.47 MB

A C# .netstandard client library for the OKX REST and Websocket Spot and Futures API focusing on clear usage and models

Home Page: https://jkorf.github.io/OKX.Net/

License: MIT License

C# 100.00%
okx-net api-client cryptocurrencies cryptocurrency cryptocurrency-exchanges okex okex-api okex-v5-api okx okx-api

okx.net's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

okx.net's Issues

error from GetAlgoOrderAsync

When i use: dim ItemOrderOKX= clientFutureOKX.UnifiedApi.Trading.GetAlgoOrderAsync(AlgoId)
i got error from ItemOrderOKX.Error.Message:
Deserialize JsonSerializationException: Error converting value "" to type 'System.Boolean'. Path 'data[0].amendPxOnTriggerType', line 1, position 187.

My Type Order is Trigger and State is Live

Exception in SetAccountLeverageAsync

When I call this code

ClienteRest.UnifiedApi.Account.SetAccountLeverageAsync(7, OKX.Net.Enums.OKXMarginMode.Isolated).Result;

It gives me this Exception:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred. (Either instId or ccy is required; if both are passed, instId will be used by default.)
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   ...

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ArgumentException: Either instId or ccy is required; if both are passed, instId will be used by default.

CryptoExchange.Net 6.2.1
JK.OKX.Net 1.4.3
.NET 8.0

data.Data.Symbol returning empty in SubscribeToKlineUpdatesAsync

When subscribing to kLineUpdates with SubscribeToKlineUpdatesAsync(symbol_name, OKX.Net.Enums.OKXPeriod.OneMinute... the event receives data with the variable "data.Data.Symbol" empty.

response received:

{
  "Timestamp": "2024-03-04T02:35:18.4118381Z",
  "Topic": "BTC-USD-240308",
  "OriginalData": "{\"arg\":{\"channel\":\"candle1m\",\"instId\":\"BTC-USD-240308\"},\"data\":[[\"1709519700000\",\"64148.8\",\"64148.8\",\"64127\",\"64127\",\"64\",\"0.0998\",\"6400\",\"0\"]]}",
  "UpdateType": 0,
  "Data": [
    1709519700000,
    64148.8,
    64148.8,
    64127.0,
    64127.0,
    64.0,
    0.0998,
    6400.0,
    "0"
  ]
}

As a workaround I used "data.Topic" to get the symbol name.

CryptoExchange.Net 7.0.0
JK.OKX.Net 1.6.1
.NET 8

GetSymbolsAsync error

This method return error, I'm using it is demo environment .
var result = okxRestClient.UnifiedApi.ExchangeData.GetSymbolsAsync(OKXInstrumentType.Swap).Result;

Deserialize JsonSerializationException: Error converting value {null} to type 'System.Decimal'. Path 'data[0].maxIcebergSz', line 1, position 264.

why i get error when i send my clientOrderId in placeing order?

i'm just sending a random client ID. do I need to set up a broker here? if you set it by some special id, please let me know how can i change it?

 var orderResult = await okxRestClient.UnifiedApi.Trading.PlaceOrderAsync(preOrder.Symbol, orderSide, OKXOrderType.MarketOrder, preOrder.Quantity, preOrder.PriceToBuy,
                        positionSide, trademode, clientOrderId: clientOrderId);

{51000: Parameter clOrdId error }

is "078ee129065aBCDE638315340601685538" yours:

{"clOrdId":"078ee129065aBCDE638315340601685538","instId":"BTC-USDT-SWAP","ordType":"market","posSide":"short","px":"27107.6","side":"sell","sz":"415","tag":"078ee129065aBCDE","tdMode":"cross"}

_socketClient.UnifiedApi.Trading.SubscribeToOrderUpdatesAsync cause high cpu, with no trading and data subscription.

I called this method (SubscribeToOrderUpdatesAsync()), and there's no trading, and of course no orderupdate callback received. wail for 20 minutes, the cpu usage will by very high. I'm using .net framework 4.7. and have tried on 3 different pc/server. all the same result. high cpu.
In this code, I firstly selected 20 symbols, and they called SubscribeToOrderUpdatesAsync() for each of them.

                var instrumentSecetedList = instrumentList.Where(record =>
                {
                    return record.Symbol.StartsWith("BTC-")
                           || record.Symbol.StartsWith("ETH-")
                           || record.Symbol.StartsWith("SOL-")
                           || record.Symbol.StartsWith("BCH-")
                           || record.Symbol.StartsWith("EOS-")
                           || record.Symbol.StartsWith("LTC-")
                           || record.Symbol.StartsWith("TRX-")
                           || record.Symbol.StartsWith("UNI-")
                           || record.Symbol.StartsWith("XLM-")
                           ;
                });

                Console.WriteLine(string.Join("\t", instrumentList.Select(a => a.Symbol)));

                foreach (var instrument in instrumentSecetedList)
                {

                    var result = _socketClient.UnifiedApi.Trading.SubscribeToOrderUpdatesAsync(OKXInstrumentType.Swap, instrument.Symbol, null, dataEvent => ExchangeTradingOrderUpdate(dataEvent.Data),
                        _clientCts.Token).Result;
                    Console.WriteLine($"{instrument} TradingApicSubscribed");

                    if (!result.Success)
                    {
                        Logger.Warn("futuresCoinUserDataUpdateResp failed! Message:(" + result.Error?.Message + ")");
                        throw new TxException("Client has not been initialized");
                    }
                }

Sub account balance

/api/v5/asset/subaccount/balances request should return List of OKXSubAccountFundingBalance instead of first element

GetTickersAsync Error

This method return error, I'm using it is demo environment
var result = okxRestClient.UnifiedApi.ExchangeData.GetTickersAsync(OKXInstrumentType.Swap).Result;

Deserialize JsonSerializationException: Error converting value {null} to type 'System.Decimal'. Path 'data[52].bidPx', line 1, position 15871.

PlaceOrderAsync fails with clientOrderId supplied

Using PlaceOrderAsync I supply a clientOrderId parameter of 32 characters but response gives me an error for this parameter.

When I check the actual request I see you've changed my clientOrderId putting the value you generate for Tag parameter at the beginning so now this value is too long, so I get the error.

https://github.com/JKorf/OKX.Net/blob/54c04284d36992cacffdbe8f6fb65ec1870a358e/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiTrading.cs#L73C83-L73C83

So the problems I can see are:

  1. If I supply a clientOrderId it should not be changed for any reason.
  2. It should be an optional parameter, not mandatory and not sent if I don't supply a value.
  3. Tag should be an optional parameter that I can pass.
  4. A few other places in OKXRestClientUnifiedApiTrading.cs you are doing the same issue.

error from GetAlgoOrderHistoryAsync

When i use:
ItemGetAllOrder = Await clientFutureOKX.UnifiedApi.Trading.GetAlgoOrderHistoryAsync(OKXOjectsOrderType_Algo.Trigger, OKX.Net.Enums.OKXAlgoOrderState.Live, instrumentType:=OKXInstrumentType.Swap, symbol:=Symbol)
i got error: sourceIncorrect type of state

If use OKX.Net.Enums.OKXAlgoOrderState.Effective or OKX.Net.Enums.OKXAlgoOrderState.Canceled. It is ok

Please check OKXAlgoOrderState.Live

error from PlaceMultipleOrdersAsync

          okxClient.UnifiedApi.Trading.PlaceMultipleOrdersAsync(new List<OKXOrderPlaceRequest>
            {
                new OKXOrderPlaceRequest
                {
                    Symbol = "nft-usdt-swap",
                    OrderSide = OKXOrderSide.Buy,
                    OrderType = OKXOrderType.ImmediateOrCancel,
                    Quantity = 1,
                    Price = 0.0000004373m,
                    PositionSide = OKXPositionSide.Net,
                    TradeMode = OKXTradeMode.Cross
                }
            });

[{"instId":"nft-usdt-swap","tdMode":"cross","side":"buy","posSide":"net","ordType":"ioc","sz":1.0,"px":0.0000004373,"ccy":"","clOrdId":"...","tag":"..."}]

The error in the PlaceMultipleOrdersAsync function is due to the quantity being in decimal form instead of string form for the 'sz' parameter.

Checking the log

How can I check the log in debug mode? In old version, I remember we could set it as parameter in client option.

property `Success` is true when GetOrderBookAsync gets an error result

When using the OKXRestClient.UnifiedApi.ExchangeData.GetOrderBookAsync method, I found that when the exchange returns an error, the result is misjudged as Success. The behavior I expect is that if the exchange returns an error, then the result should be marked as an error, not success.

Steps to reproduce: Call OKXRestClient.UnifiedApi.ExchangeData.GetOrderBookAsync with any symbol that not exist

I think the error comes from code like below:

        if (!result.Success || result.Data.Data.Count() == 0) return result.AsError<OKXOrderBook>(result.Error!);

when result.Error is null, the returned result‘s Success property will be true.

error from property TriggerTime in Class OKXAlgoOrder

When i get order (is Effective, triggered) from OKXAlgoOrder. The property TriggerTime get Null Value for all Function: GetAlgoOrderAsync, GetAlgoOrderListAsync, GetAlgoOrderHistoryAsync

Please check property TriggerTime

Thank you so much

Tag has missed in place order

Could you please add "tag parameter in "PlaceOrderAsync"? It is necessary to set broker ID.

It will be great if you put tag as an option to define the API in the beginning.

Time parameters is messed up

var withdrawalHistoryResult = await _apiClient.UnifiedApi.Account.GetWithdrawalHistoryAsync(endTime:DateTime.UtcNow, startTime:DateTime.UtcNow.AddDays(-1));

return empty collection

var withdrawalHistoryResult = await _apiClient.UnifiedApi.Account.GetWithdrawalHistoryAsync(startTime:DateTime.UtcNow, endTime:DateTime.UtcNow.AddDays(-1));

return existing data

Error tdMode from PlaceOrderAsync

Dim ItemStopOKX = Await clientFutureOKX.UnifiedApi.Trading.PlaceOrderAsync(symbol:="ETH-USD-SWAP", side:=OKXOrderSide.Buy, type:=OKXOrderType.MarketOrder, quantity:=5, tradeMode:=OKXMarginMode.Isolated, positionSide:=OKXPositionSide.Long)

i got error: ItemStopOKX.Error is Parameter tdMode error

When i check ItemStopOKX.RequestUrl

I got RequestUrl is: https://www.okx.com/api/v5/trade/order
Screenshot 2024-01-11 120027

When i check ItemStopOKX.RequestBody

i got:

Screenshot 2024-01-11 120820
i have used OKXMarginMode.Isolated but body show tdMode is cash

Please check that error

GetMaximumLoanAmountAsync error

this metthod gives error:
var maximumLoan = okxRestClient.UnifiedApi.Account.GetMaximumLoanAmountAsync(preOrder.Symbol, marginmode).Result;

{"code":"51000","data":[],"msg":"Parameter instIdBTC-USDT-SWAP error"}

error from GetAlgoOrderListAsync

Dim ItemOrderOKX_temp2 = Await clientFutureOKX.UnifiedApi.Trading.GetAlgoOrderListAsync(OKXOjectsOrderType_Algo.Trigger, algoId:=ID)
i got error: Deserialize JsonSerializationException: Error converting value "" to type 'System.Boolean'. Path 'data[0].amendPxOnTriggerType', line 1, position 187.
The same error from function GetAlgoOrderAsync

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.