-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0fb6c1
commit 4c3a4de
Showing
28 changed files
with
449 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
binding/csharp/example/enable_library_logging/MainProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class MainProgram { | ||
class MyLogger : ccapi.Logger { | ||
public override void LogMessage(string severity, string threadId, string timeISO, string fileName, string lineNumber, string message) { | ||
lock (this._myLock) { | ||
System.Console.WriteLine( | ||
string.Format("{0}: [{1}] {{{2}:{3}}} {4}{5}{6}", threadId, timeISO, fileName, lineNumber, severity, new string(' ', 8), message)); | ||
} | ||
} | ||
private readonly object _myLock = new object(); | ||
} | ||
public static void Main(string[] args) { | ||
var myLogger = new MyLogger(); | ||
ccapi.Logger.logger = myLogger; | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config); | ||
var subscription = new ccapi.Subscription("okx", "BTC-USDT", "MARKET_DEPTH"); | ||
session.Subscribe(subscription); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<Configuration>Release</Configuration> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
3 changes: 3 additions & 0 deletions
3
binding/csharp/example/enable_library_logging/user_specified_cmake_include.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_compile_definitions(CCAPI_ENABLE_LOG_TRACE) | ||
# usage: when generating the binding code, do cmake -DCMAKE_PROJECT_INCLUDE=<path-to-this-file> ..., see https://github.com/crypto-chassis/ccapi#non-c | ||
# see https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_INCLUDE.html |
74 changes: 36 additions & 38 deletions
74
binding/csharp/example/execution_management_simple_request/MainProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
class MainProgram | ||
{ | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
System.Console.WriteLine(System.String.Format("Received an event:\n%s", event_.ToStringPretty(2, 2))); | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) | ||
{ | ||
if(System.Environment.GetEnvironmentVariable("OKX_API_KEY") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_KEY"); | ||
return; | ||
} | ||
if(System.Environment.GetEnvironmentVariable("OKX_API_SECRET") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_SECRET"); | ||
return; | ||
} | ||
if(System.Environment.GetEnvironmentVariable("OKX_API_PASSPHRASE") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_PASSPHRASE"); | ||
return; | ||
} | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var request = new ccapi.Request(Request.Operation.CREATE_ORDER, "okx", "BTC-USDT"); | ||
var param = new ccapi.MapStringString(); | ||
param.Add("SIDE","BUY"); | ||
param.Add("QUANTITY","0.0005"); | ||
param.Add("LIMIT_PRICE","20000"); | ||
request.AppendParam(param); | ||
session.SendRequest(request); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} | ||
class MainProgram { | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
System.Console.WriteLine(string.Format("Received an event:\n{0}", event_.ToStringPretty(2, 2))); | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) { | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_KEY") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_KEY"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_SECRET") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_SECRET"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_PASSPHRASE") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_PASSPHRASE"); | ||
return; | ||
} | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var request = new ccapi.Request(ccapi.Request.Operation.CREATE_ORDER, "okx", "BTC-USDT"); | ||
var param = new ccapi.MapStringString(); | ||
param.Add("SIDE", "BUY"); | ||
param.Add("QUANTITY", "0.0005"); | ||
param.Add("LIMIT_PRICE", "20000"); | ||
request.AppendParam(param); | ||
session.SendRequest(request); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
23 changes: 12 additions & 11 deletions
23
binding/csharp/example/execution_management_simple_request/main.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<Configuration>Release</Configuration> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
46 changes: 46 additions & 0 deletions
46
binding/csharp/example/execution_management_simple_subscription/MainProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class MainProgram { | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
if (event_.GetType_() == ccapi.Event.Type.SUBSCRIPTION_STATUS) { | ||
System.Console.WriteLine(string.Format("Received an event of type SUBSCRIPTION_STATUS:\n{0}", event_.ToStringPretty(2, 2))); | ||
var message = event_.GetMessageList()[0]; | ||
if (message.GetType_() == ccapi.Message.Type.SUBSCRIPTION_STARTED) { | ||
var request = new ccapi.Request(ccapi.Request.Operation.CREATE_ORDER, "okx", "BTC-USDT"); | ||
var param = new ccapi.MapStringString(); | ||
param.Add("SIDE", "BUY"); | ||
param.Add("QUANTITY", "0.0005"); | ||
param.Add("LIMIT_PRICE", "20000"); | ||
request.AppendParam(param); | ||
session.SendRequest(request); | ||
} | ||
} else if (event_.GetType_() == ccapi.Event.Type.SUBSCRIPTION_DATA) { | ||
System.Console.WriteLine(string.Format("Received an event of type SUBSCRIPTION_DATA:\n{0}", event_.ToStringPretty(2, 2))); | ||
} | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) { | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_KEY") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_KEY"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_SECRET") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_SECRET"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("OKX_API_PASSPHRASE") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable OKX_API_PASSPHRASE"); | ||
return; | ||
} | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var subscriptionList = new ccapi.SubscriptionList(); | ||
subscriptionList.Add(new ccapi.Subscription("okx", "BTC-USDT", "ORDER_UPDATE")); | ||
session.Subscribe(subscriptionList); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
binding/csharp/example/execution_management_simple_subscription/main.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<Configuration>Release</Configuration> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class MainProgram { | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
if (event_.GetType_() == ccapi.Event.Type.AUTHORIZATION_STATUS) { | ||
System.Console.WriteLine(string.Format("Received an event of type AUTHORIZATION_STATUS:\n{0}", event_.ToStringPretty(2, 2))); | ||
var message = event_.GetMessageList()[0]; | ||
if (message.GetType_() == ccapi.Message.Type.AUTHORIZATION_SUCCESS) { | ||
var request = new ccapi.Request(ccapi.Request.Operation.FIX, "coinbase", "", "same correlation id for subscription and request"); | ||
var param = new ccapi.VectorPairIntString(); | ||
param.Add(new ccapi.PairIntString(35, "D")); | ||
param.Add(new ccapi.PairIntString(11, "6d4eb0fb-2229-469f-873e-557dd78ac11e")); | ||
param.Add(new ccapi.PairIntString(55, "BTC-USD")); | ||
param.Add(new ccapi.PairIntString(54, "1")); | ||
param.Add(new ccapi.PairIntString(44, "20000")); | ||
param.Add(new ccapi.PairIntString(38, "0.001")); | ||
param.Add(new ccapi.PairIntString(40, "2")); | ||
param.Add(new ccapi.PairIntString(59, "1")); | ||
request.AppendParamFix(param); | ||
session.SendRequest(request); | ||
} | ||
} else if (event_.GetType_() == ccapi.Event.Type.FIX) { | ||
System.Console.WriteLine(string.Format("Received an event of type FIX:\n{0}", event_.ToStringPretty(2, 2))); | ||
} | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) { | ||
if (System.Environment.GetEnvironmentVariable("COINBASE_API_KEY") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable COINBASE_API_KEY"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("COINBASE_API_SECRET") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable COINBASE_API_SECRET"); | ||
return; | ||
} | ||
if (System.Environment.GetEnvironmentVariable("COINBASE_API_PASSPHRASE") is null) { | ||
System.Console.Error.WriteLine("Please set environment variable COINBASE_API_PASSPHRASE"); | ||
return; | ||
} | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var subscription = new ccapi.Subscription("coinbase", "", "FIX", "", "same correlation id for subscription and request"); | ||
session.SubscribeByFix(subscription); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<Configuration>Release</Configuration> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class MainProgram { | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
try { | ||
throw new System.Exception("oops"); | ||
} catch (System.Exception e) { | ||
System.Console.WriteLine(e.ToString()); | ||
System.Environment.Exit(0); | ||
} | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) { | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var subscriptionList = new ccapi.SubscriptionList(); | ||
subscriptionList.Add(new ccapi.Subscription("okx", "BTC-USDT", "MARKET_DEPTH")); | ||
session.Subscribe(subscriptionList); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<Configuration>Release</Configuration> | ||
<CcapiLibraryPath>to be provided in command line</CcapiLibraryPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="ccapi"> | ||
<HintPath>$(CcapiLibraryPath)</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
34 changes: 34 additions & 0 deletions
34
binding/csharp/example/market_data_multiple_subscription/MainProgram.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class MainProgram { | ||
class MyEventHandler : ccapi.EventHandler { | ||
public override bool ProcessEvent(ccapi.Event event_, ccapi.Session session) { | ||
if (event_.GetType_() == ccapi.Event.Type.SUBSCRIPTION_DATA) { | ||
foreach (var message in event_.GetMessageList()) { | ||
var correlationId = message.GetCorrelationIdList()[0]; | ||
System.Console.WriteLine(string.Format("{0}: Best bid and ask at {1} are:", correlationId, message.GetTimeISO())); | ||
foreach (var element in message.GetElementList()) { | ||
var elementNameValueMap = element.GetNameValueMap(); | ||
foreach (var entry in elementNameValueMap) { | ||
var name = entry.Key; | ||
var value = entry.Value; | ||
System.Console.WriteLine(string.Format(" {0} = {1}", name, value)); | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
static void Main(string[] args) { | ||
var eventHandler = new MyEventHandler(); | ||
var option = new ccapi.SessionOptions(); | ||
var config = new ccapi.SessionConfigs(); | ||
var session = new ccapi.Session(option, config, eventHandler); | ||
var subscriptionList = new ccapi.SubscriptionList(); | ||
subscriptionList.Add(new ccapi.Subscription("okx", "BTC-USDT", "MARKET_DEPTH", "", "BTC")); | ||
subscriptionList.Add(new ccapi.Subscription("okx", "ETH-USDT", "MARKET_DEPTH", "", "ETH")); | ||
session.Subscribe(subscriptionList); | ||
System.Threading.Thread.Sleep(10000); | ||
session.Stop(); | ||
System.Console.WriteLine("Bye"); | ||
} | ||
} |
Oops, something went wrong.