Skip to content

Commit

Permalink
update cs SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadadayuer committed Apr 22, 2020
1 parent 924de66 commit dc9522f
Show file tree
Hide file tree
Showing 46 changed files with 1,199 additions and 793 deletions.
Binary file modified okex-cs-sdk-api/.vs/OKExSDK/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file modified okex-cs-sdk-api/.vs/OKExSDK/v16/.suo
Binary file not shown.
Binary file modified okex-cs-sdk-api/.vs/OKExSDK/v16/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion okex-cs-sdk-api/OKExSDK/obj/OKExSDK.csproj.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"dgSpecHash": "voLopVl+6TTdcHgI51+L2PxIzUzBXj38bnR197ljgNEqCMwVAG7J79bZKlDMk4DYmUN9xddGkMPcXUNgFSNDzg==",
"dgSpecHash": "tLZHI1zJa7ZCnaTHa5eMst8AgdkU9B4Wsn7sBh5hEkfFZLXrJ1xNcmvXV0fUKA/GFXBXuetxoFzNCoSV2SmlrQ==",
"success": true
}
10 changes: 5 additions & 5 deletions okex-cs-sdk-api/OKExSDK/obj/OKExSDK.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj": {}
"D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj": {}
},
"projects": {
"D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj": {
"D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj": {
"version": "1.0.1",
"restore": {
"projectUniqueName": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectUniqueName": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectName": "OKExSDKTest",
"projectPath": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectPath": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"packagesPath": "C:\\Users\\oker\\.nuget\\packages\\",
"outputPath": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\obj\\",
"outputPath": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\oker\\AppData\\Roaming\\NuGet\\NuGet.Config",
Expand Down
6 changes: 3 additions & 3 deletions okex-cs-sdk-api/OKExSDK/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@
"project": {
"version": "1.0.1",
"restore": {
"projectUniqueName": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectUniqueName": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectName": "OKExSDKTest",
"projectPath": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"projectPath": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\OKExSDK.csproj",
"packagesPath": "C:\\Users\\oker\\.nuget\\packages\\",
"outputPath": "D:\\ProgramData\\Project\\ok-open-api\\okex-cs-sdk-api\\OKExSDK\\obj\\",
"outputPath": "D:\\ProgramData\\Project\\newSDK\\V3-Open-API-SDK\\okex-cs-sdk-api\\OKExSDK\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\oker\\AppData\\Roaming\\NuGet\\NuGet.Config",
Expand Down
8 changes: 2 additions & 6 deletions okex-cs-sdk-api/OKExSDKLibrary/AccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public async Task<JContainer> getWithDrawalHistoryByCurrencyAsync(string currenc
/// <param name="to">请求此页码之前的分页内容(举例页码为:1,2,3,4,5。from 4 只返回第5页,to 4只返回第3页)</param>
/// <param name="limit">分页返回的结果集数量,默认为100,最大为100,按时间顺序排列,越早下单的在前面</param>
/// <returns></returns>
public async Task<JContainer> getLedgerAsync(string currency, string type, int? after, int? before, int? limit)
public async Task<string> getLedgerAsync(string currency, string type, int? after, int? before, int? limit)
{
var url = $"{this.BASEURL}{this.ACCOUNT_SEGMENT}/ledger";
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, null)))
Expand Down Expand Up @@ -225,11 +225,7 @@ public async Task<JContainer> getLedgerAsync(string currency, string type, int?
var paramsStr = await encodedContent.ReadAsStringAsync();
var res = await client.GetAsync($"{url}?{paramsStr}");
var contentStr = await res.Content.ReadAsStringAsync();
if (contentStr[0] == '[')
{
return JArray.Parse(contentStr);
}
return JObject.Parse(contentStr);
return contentStr;
}
}

Expand Down
28 changes: 26 additions & 2 deletions okex-cs-sdk-api/OKExSDKLibrary/FuturesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,14 @@ public async Task<string> getHoldsAsync(string instrument_id)
return contentStr;
}
}
public async Task<string> order_algo(string instrument_id, string type, string order_type, string size, string trigger_price, string algo_price)
public async Task<string> order_algo(string instrument_id, string type, string order_type, string size, string trigger_price, string algo_price,string algo_type)
{
//止盈止损 trigger_price algo_price
//跟踪委托callback_rate, trigger_price
//冰山委托algo_variance, avg_amount, price_limit
//时间加权 sweep_range, sweep_ratio , single_limit,price_limit,time_interval
var url = $"{this.BASEURL}{this.FUTURES_SEGMENT}/order_algo";
var body = new { instrument_id = instrument_id, type = type, order_type = order_type, size = size, trigger_price = trigger_price, algo_price = algo_price };
var body = new { instrument_id = instrument_id, type = type, order_type = order_type, size = size, trigger_price = trigger_price, algo_price = algo_price, algo_type= algo_type };
var bodyStr = JsonConvert.SerializeObject(body);
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
Expand Down Expand Up @@ -764,5 +764,29 @@ public async Task<string> getTrade_fee()
return content;
}
}
public async Task<string> margin(string instrument_id, string direction,string type,string amount)
{
string url = $"{this.BASEURL}{this.FUTURES_SEGMENT}/position/margin";
var body = new { instrument_id = instrument_id, direction = direction, type = type, amount = amount };
string bodyStr = JsonConvert.SerializeObject(body).Replace("\"[", "[").Replace("]\"", "]").Replace("\\\"", "\"");
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
var res = await client.PostAsync(url, new StringContent(bodyStr, Encoding.UTF8, "application/json"));
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
public async Task<string> auto_margin(string underlying, string type)
{
string url = $"{this.BASEURL}{this.FUTURES_SEGMENT}/accounts/auto_margin";
var body = new { underlying = underlying, type = type};
string bodyStr = JsonConvert.SerializeObject(body).Replace("\"[", "[").Replace("]\"", "]").Replace("\\\"", "\"");
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
var res = await client.PostAsync(url, new StringContent(bodyStr, Encoding.UTF8, "application/json"));
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
}
}
29 changes: 29 additions & 0 deletions okex-cs-sdk-api/OKExSDKLibrary/IndexApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace OKExSDK
{
public class IndexApi:SdkApi
{
private string INDEX_SEGMENT = "api/index/v3";
public IndexApi(string apiKey, string secret, string passPhrase) : base(apiKey, secret, passPhrase) { }
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<string> constituents(string instrument_id)
{
var url = $"{this.BASEURL}{this.INDEX_SEGMENT}/{instrument_id}/constituents";
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, null)))
{
var res = await client.GetAsync(url);
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
}
}
1 change: 1 addition & 0 deletions okex-cs-sdk-api/OKExSDKLibrary/Models/Account/Transfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ public class Transfer
/// </summary>
public string instrument_id { get; set; }
public string to_instrument_id { get; set; }
public string type { get; set; }
}
}
2 changes: 2 additions & 0 deletions okex-cs-sdk-api/OKExSDKLibrary/OKExSDKLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="FuturesApi.cs" />
<Compile Include="GeneralApi.cs" />
<Compile Include="HttpInterceptor.cs" />
<Compile Include="IndexApi.cs" />
<Compile Include="MarginApi.cs" />
<Compile Include="Models\Account\AccountLedger.cs" />
<Compile Include="Models\Account\Currency.cs" />
Expand Down Expand Up @@ -202,6 +203,7 @@
<Compile Include="SdkApi.cs" />
<Compile Include="SpotApi.cs" />
<Compile Include="SwapApi.cs" />
<Compile Include="SystemApi.cs" />
<Compile Include="WebSocketor.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion okex-cs-sdk-api/OKExSDKLibrary/SpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,12 @@ public async Task<string> getCandlesAsync(string instrument_id, DateTime? start,
}
public async Task<string> getOrder_algoAsync(string instrument_id, int order_type, int? status, int? algo_id, int? before, int? after, int? limit)
{
var url = $"{ this.BASEURL}{this.SPOT_SEGMENT}/order_algo/{instrument_id}";
var url = $"{ this.BASEURL}{this.SPOT_SEGMENT}/algo";

using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, null)))
{
var queryParams = new Dictionary<string, string>();
queryParams.Add("instrument_id", instrument_id);
queryParams.Add("order_type", order_type.ToString());
if (status.HasValue)
{
Expand Down
29 changes: 26 additions & 3 deletions okex-cs-sdk-api/OKExSDKLibrary/SwapApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@ public async Task<string> getTrade_fee()
}
}
//委托策略下单
public async Task<string> order_algo(string instrument_id, string type, string order_type, string size, string trigger_price, string algo_price)
public async Task<string> order_algo(string instrument_id, string type, string order_type, string size, string trigger_price, string algo_price, string algo_type)
{
//止盈止损 trigger_price algo_price
//跟踪委托callback_rate, trigger_price
//冰山委托algo_variance, avg_amount, price_limit
//时间加权 sweep_range, sweep_ratio , single_limit,price_limit,time_interval
var url = $"{this.BASEURL}{this.SWAP_SEGMENT}/order_algo";
var body = new { instrument_id = instrument_id, type = type, order_type = order_type, size = size, trigger_price = trigger_price, algo_price = algo_price };
var body = new { instrument_id = instrument_id, type = type, order_type = order_type, size = size, trigger_price = trigger_price, algo_price = algo_price , algo_type = algo_type };
var bodyStr = JsonConvert.SerializeObject(body);
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
Expand Down Expand Up @@ -746,6 +746,29 @@ public async Task<JContainer> getHistoricalFundingRateAsync(string instrument_id
return JObject.Parse(contentStr);
}
}

public async Task<string> close_position(string instrument_id,string direction)
{
var url = $"{this.BASEURL}{this.SWAP_SEGMENT}/close_position";
var body =new { instrument_id =instrument_id, direction = direction };
string bodyStr = JsonConvert.SerializeObject(body).Replace("\"[", "[").Replace("]\"", "]").Replace("\\\"", "\"");
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
var res = await client.PostAsync(url, new StringContent(bodyStr, Encoding.UTF8, "application/json"));
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
public async Task<string> cancel_all(string instrument_id, string direction)
{
var url = $"{this.BASEURL}{this.SWAP_SEGMENT}/cancel_all";
var body = new { instrument_id = instrument_id, direction = direction };
string bodyStr = JsonConvert.SerializeObject(body).Replace("\"[", "[").Replace("]\"", "]").Replace("\\\"", "\"");
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, bodyStr)))
{
var res = await client.PostAsync(url, new StringContent(bodyStr, Encoding.UTF8, "application/json"));
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
}
}
29 changes: 29 additions & 0 deletions okex-cs-sdk-api/OKExSDKLibrary/SystemApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace OKExSDK
{
public class SystemApi:SdkApi
{
private string SYSTEM_SEGMENT = "api/system/v3";
public SystemApi(string apiKey, string secret, string passPhrase) : base(apiKey, secret, passPhrase) { }
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<string> status()
{
var url = $"{this.BASEURL}{this.SYSTEM_SEGMENT}/status";
using (var client = new HttpClient(new HttpInterceptor(this._apiKey, this._secret, this._passPhrase, null)))
{
var res = await client.GetAsync(url);
var contentStr = await res.Content.ReadAsStringAsync();
return contentStr;
}
}
}
}
28 changes: 23 additions & 5 deletions okex-cs-sdk-api/OKExSDKLibrary/WebSocketor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace OKExSDK
{
public class WebSocketor : IDisposable
{
string url = "wss://real.okex.com:10442/ws/v3";
string url = "wss://real.okex.com:8443/ws/v3";
ClientWebSocket ws = null;
CancellationTokenSource cts = new CancellationTokenSource();
public event WebSocketPushHandler WebSocketPush;
Expand Down Expand Up @@ -48,16 +48,16 @@ public WebSocketor()
await rebootAsync();
};
}
public void test()
{
receive();
}

public async Task ConnectAsync()
{

await ws.ConnectAsync(new Uri(url), cts.Token);

closeCheckTimer.Interval = 31000;
closeCheckTimer.Start();
receive();
keeponline();
}

public async Task LoginAsync(string apiKey, string secret, string phrase)
Expand Down Expand Up @@ -111,6 +111,24 @@ public async Task Subscribe(List<string> args)
setPendingTimer();
}
}
public void keeponline()
{
Task.Factory.StartNew(
async () =>
{
while (ws.State == WebSocketState.Open)
{
Thread.Sleep(10000);
if (ws.State == WebSocketState.Open)
{
byte[] buffer = Encoding.UTF8.GetBytes("ping");
await ws.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
closeCheckTimer.Interval = 31000;
}
}
}, cts.Token, TaskCreationOptions.LongRunning,
TaskScheduler.Default);
}
public async Task UnSubscribe(List<string> args)
{
foreach (var channel in args)
Expand Down
Binary file modified okex-cs-sdk-api/OKExSDKLibrary/bin/Debug/OKExSDKLibrary.dll
Binary file not shown.
Binary file modified okex-cs-sdk-api/OKExSDKLibrary/bin/Debug/OKExSDKLibrary.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,27 @@ D:\ProgramData\Project\ok-open-api\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKEx
D:\ProgramData\Project\ok-open-api\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.csproj.CopyComplete
D:\ProgramData\Project\ok-open-api\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.dll
D:\ProgramData\Project\ok-open-api\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.pdb
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\OKExSDKLibrary.dll.config
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\OKExSDKLibrary.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\OKExSDKLibrary.pdb
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\DotNetZip.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.Extensions.Desktop.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.Extensions.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Newtonsoft.Json.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\System.Net.Http.Extensions.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\System.Net.Http.Primitives.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\DotNetZip.pdb
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\DotNetZip.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.Extensions.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Microsoft.Threading.Tasks.Extensions.Desktop.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Newtonsoft.Json.pdb
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\Newtonsoft.Json.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\System.Net.Http.Extensions.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\bin\Debug\System.Net.Http.Primitives.xml
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.csproj.App.config
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.csprojAssemblyReference.cache
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.csproj.CopyComplete
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.dll
D:\ProgramData\Project\newSDK\V3-Open-API-SDK\okex-cs-sdk-api\OKExSDKLibrary\obj\Debug\OKExSDKLibrary.pdb
Binary file not shown.
Binary file modified okex-cs-sdk-api/OKExSDKLibrary/obj/Debug/OKExSDKLibrary.dll
Binary file not shown.
Binary file modified okex-cs-sdk-api/OKExSDKLibrary/obj/Debug/OKExSDKLibrary.pdb
Binary file not shown.
Loading

0 comments on commit dc9522f

Please sign in to comment.