Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange impl #199

Merged
merged 24 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ license = "BSD-2-Clause"
repository = "https://github.com/nash-io/openlimits"
keywords = ["cryptocurrency", "exchange", "openlimits", "api"]

[[example]]
name = "orderbook"
path = "examples/rust/orderbook.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
bindings = ["ligen", "ligen-macro", "ligen-csharp"]
default = ["rust_gmp"]
rust_gmp = ["nash-protocol/rust_gmp", "nash-native-client/rust_gmp"]
num_bigint = ["nash-protocol/num_bigint", "nash-native-client/num_bigint"]
python = ["pyo3"]

[dependencies]
async-trait = "0.1"
Expand All @@ -41,8 +44,17 @@ tungstenite = "0.12"
sha2 = "0.9.1"
url = "2.1.1"
derive_more = "0.99"
nash-protocol = { version = "0.1", default-features = false, features = ["rustcrypto"] }
nash-native-client = { version = "0.1", default-features = false, features = ["rustcrypto"] }
#nash-protocol = { version = "0.1", default-features = false, features = ["rustcrypto"] }
#nash-native-client = { version = "0.1", default-features = false, features = ["rustcrypto"] }
nash-protocol = { path = "../nash-rust/nash-protocol", default-features = false, features = ["rustcrypto"] }
nash-native-client = { path = "../nash-rust/nash-native-client", default-features = false, features = ["rustcrypto"] }
pyo3 = { version = "0.12.3", optional = true }
openlimits-binance = { version = "0.1" }
openlimits-exchange = { version = "0.1" }
openlimits-binance = { path = "crates/openlimits-binance" }
openlimits-exchange = { path = "crates/openlimits-exchange" }
ligen-macro = { path = "../../sensorial/systems/ligen/ligen/macro", optional = true }
ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
lazy_static = "1.4.0"

[build-dependencies]
ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
ligen-csharp = { path = "../../sensorial/systems/ligen/generators/ligen-csharp", optional = true }
Empty file added bindings/REMOVE_ME
Empty file.
2 changes: 2 additions & 0 deletions bindings/csharp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obj
bin
47 changes: 47 additions & 0 deletions bindings/csharp/AskBid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace OpenLimits
{
using System;
using System.Runtime.InteropServices;
using System.Globalization;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct FFIAskBid
{
public readonly IntPtr price;
public readonly IntPtr qty;

public FFIAskBid(IntPtr price, IntPtr qty)
{
this.price = price;
this.qty = qty;
}

public void Dispose() {
ExchangeClient.FreeString(price);
ExchangeClient.FreeString(qty);
}

public AskBid ToAskBid() {
return new AskBid(
CString.ToString(this.price),
CString.ToString(this.qty)
);
}
}

public struct AskBid
{
public readonly decimal price;
public readonly decimal qty;

public AskBid(string price, string qty)
{
this.price = Decimal.Parse(price, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
this.qty = Decimal.Parse(qty, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
}

public override string ToString()
{
return "AskBid { price=" + price + ", qty=" + qty + "}";
}
}
}
41 changes: 41 additions & 0 deletions bindings/csharp/Balance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace OpenLimits
{
using System.Runtime.InteropServices;
using System;

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FFIBalance
{
public readonly IntPtr asset;
public readonly IntPtr total;
public readonly IntPtr free;

public void Dispose() {
ExchangeClient.FreeString(asset);
ExchangeClient.FreeString(total);
ExchangeClient.FreeString(free);
}

public Balance ToBalance() {
return new Balance(
CString.ToString(this.asset),
CString.ToString(this.total),
CString.ToString(this.free)
);
}
}

public struct Balance
{
public readonly string asset;
public readonly string total;
public readonly string free;

public Balance(string asset, string total, string free)
{
this.asset = asset;
this.total = total;
this.free = free;
}
}
}
27 changes: 27 additions & 0 deletions bindings/csharp/BinanceClientConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

namespace OpenLimits
{
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BinanceClientConfig
{
public readonly string apikey;
public readonly string secret;
public readonly bool sandbox;

private BinanceClientConfig(string apikey, string secret, bool sandbox)
{
this.apikey = apikey;
this.secret = secret;
this.sandbox = sandbox;
}

public static BinanceClientConfig Authenticated(string apikey, string secret, bool sandbox) {
return new BinanceClientConfig(apikey, secret, sandbox);
}

public static BinanceClientConfig Unauthenticated(bool sandbox) {
return new BinanceClientConfig(null, null, sandbox);
}
}
}
19 changes: 19 additions & 0 deletions bindings/csharp/CString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace OpenLimits
{
using System.Runtime.InteropServices;
using System;
using System.Text;

public class CString {
public static string ToString(IntPtr handle) {
if (handle.ToInt64() == 0) {
return null;
}
int len = 0;
while (Marshal.ReadByte(handle,len) != 0) { ++len; }
byte[] buffer = new byte[len];
Marshal.Copy(handle, buffer, 0, buffer.Length);
return Encoding.UTF8.GetString(buffer);
}
}
}
24 changes: 24 additions & 0 deletions bindings/csharp/Candle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace OpenLimits
{
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Candle
{
public readonly ulong time;
public readonly double low;
public readonly double high;
public readonly double open;
public readonly double close;
public readonly double volume;

public Candle(ulong time, double low, double high, double open, double close, double volume)
{
this.time = time;
this.low = low;
this.high = high;
this.open = open;
this.close = close;
this.volume = volume;
}
}
}
29 changes: 29 additions & 0 deletions bindings/csharp/CoinbaseClientConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

namespace OpenLimits
{
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CoinbaseClientConfig
{
public readonly string apikey;
public readonly string secret;
public readonly string passphrase;
public readonly bool sandbox;

private CoinbaseClientConfig(string apikey, string secret, string passphrase, bool sandbox)
{
this.apikey = apikey;
this.secret = secret;
this.passphrase = passphrase;
this.sandbox = sandbox;
}

public static CoinbaseClientConfig Authenticated(string apikey, string secret, string passphrase, bool sandbox) {
return new CoinbaseClientConfig(apikey, secret, passphrase, sandbox);
}

public static CoinbaseClientConfig Unauthenticated(bool sandbox) {
return new CoinbaseClientConfig(null, null, null, sandbox);
}
}
}
Loading