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

Acess to Demo trading using OkexClient #37

Closed lcmgbra closed 2 years ago

lcmgbra commented 2 years ago

Please, Could you help me to acess Demo trade and make a SPOT order using: OkexClient api = new OkexClient(new Okex.Net.CoreObjects.OkexRestClientOptions { LogLevel = LogLevel.Debug, BaseAddress = baseUrl, }); var trade_01 = api.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Long, OkexOrderType.MarketOrder, 0.1m);

What the adress /baseUrl that I can use to acess the Demo trading ?

burakoner commented 2 years ago

As you can see in documentation (https://www.okex.com/docs-v5/en/#overview-demo-trading-services) Live and Demo endpoinst are same. You need to create a DEMO Api Key by following steps below. Then you can use it in live enpoints

Start API Demo Trading by the following steps: Login OKEx —> Assets —> Start Demo Trading —> Personal Center —> Demo Trading API -> Create Demo Trading V5 APIKey —> Start your Demo Trading

I just need to add a definition in client options for demo flag. This will place "x-simulated-trading:1" parameter in headers. I'll inform you when it finished

lcmgbra commented 2 years ago

It's okay. I have created the Demo ApiKey. I wait for your return . Thanks.

burakoner commented 2 years ago

Check this commit https://github.com/burakoner/OKEx.Net/commit/fc82ace730764e7052ddc32ae9eef7fe897e2e30 Nuget is also available https://www.nuget.org/packages/OKEx.Net/5.1.0

To create demo clients use codes below


// Rest Client
OkexClient demoClient = new OkexClient(new CoreObjects.OkexRestClientOptions { DemoTradingService = true });

// Socket Client
OkexSocketClient demoSocket = new OkexSocketClient(new CoreObjects.OkexSocketClientOptions { DemoTradingService = true });

`
lcmgbra commented 2 years ago

Dear, Burakoner, after install the new version 5.1.0 and set DemotradingService=true. OkexClient has returned the error below: Erro 50113: Invalid Sign

burakoner commented 2 years ago

I'll fix it

burakoner commented 2 years ago

Can you share your request please? Because I dont get error

lcmgbra commented 2 years ago
           OkexClient api = new OkexClient(new Okex.Net.CoreObjects.OkexRestClientOptions {
                DemoTradingService = demoTrading,
                LogLevel = LogLevel.Debug,
                BaseAddress = baseUrl,
            });
            api.SetApiCredentials(apiKey, apiSecret,apiPhrase);
            var trade_01 = api.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Long, OkexOrderType.MarketOrder, 0.1m);
lcmgbra commented 2 years ago

baseUrl = "https://aws.okex.com";

burakoner commented 2 years ago

I'll share 3 requests and responses

OkexClient demoClient = new OkexClient(new CoreObjects.OkexRestClientOptions { DemoTradingService = true });
demoClient.SetApiCredentials("e6e8d20a-4cab-420f-****-24e7e926188a", "E511393AE71C17A290F81007****2ED0", "12345678");

// Request - 1 (Your request)
demoClient.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Long, OkexOrderType.MarketOrder, 0.1m);

// Response - 1
{"code":"1","data":[{"clOrdId":"","ordId":"","sCode":"51000","sMsg":"Parameter posSide  error","tag":""}],"msg":""}

// Request - 2
demoClient.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Net, OkexOrderType.MarketOrder, 0.1m);

// Response - 2
{"code":"1","data":[{"clOrdId":"","ordId":"","sCode":"51020","sMsg":"Order amount should be greater than the min available amount. ","tag":""}],"msg":""}

// Request - 3
demoClient.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Net, OkexOrderType.MarketOrder, 1000.0m);

// Response - 3 (Success)
{"code":"0","data":[{"clOrdId":"","ordId":"384159609770090500","sCode":"0","sMsg":"","tag":""}],"msg":""}

Documentation says

Position side
The default is net in the net mode
It is required in the long/short mode, and can only be long or short.
Only applicable to FUTURES/SWAP.

And I OKEx is assuming the quantity as the quote asset quantity in market orders. So last sample buys BTC with 1000USDT (not 1000BTC)

No signature error :) Have a nice evening

lcmgbra commented 2 years ago

var trade_01 = api.PlaceOrder("BTC-USDT", OkexTradeMode.Cash, OkexOrderSide.Buy, OkexPositionSide.Net, OkexOrderType.MarketOrder, 1000.0m); 50113: Invalid Sign

lcmgbra commented 2 years ago

This is the result. I believe that I made the same as you. (i think)

lcmgbra commented 2 years ago

I will install again the package and come back to you

burakoner commented 2 years ago

Try with my codes. Maybe it causes from AWS node of OKEx. Try with default endpoint

lcmgbra commented 2 years ago

one moment I will try now.

lcmgbra commented 2 years ago

Perfect. it's working(https://www.okex.com) Thank you for everything. Have a nice evening

burakoner commented 2 years ago

I'm glad. Have a nice evening