Skip to content

Commit

Permalink
[Feature] Add OnStatusReceived to Websocket Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio committed Mar 11, 2021
1 parent 5fcde27 commit 8503ffe
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,62 @@ public static string CreateDoneResponse()
}";
}

public static string CreateStatusResponse()
{
return @"
{
""type"": ""status"",
""products"": [
{
""id"": ""BTC-USD"",
""base_currency"": ""BTC"",
""quote_currency"": ""USD"",
""base_min_size"": ""0.001"",
""base_max_size"": ""70"",
""base_increment"": ""0.00000001"",
""quote_increment"": ""0.01"",
""display_name"": ""BTC/USD"",
""status"": ""online"",
""status_message"": null,
""min_market_funds"": ""10"",
""max_market_funds"": ""1000000"",
""post_only"": false,
""limit_only"": false,
""cancel_only"": false
}
],
""currencies"": [
{
""id"": ""USD"",
""name"": ""United States Dollar"",
""min_size"": ""0.01000000"",
""status"": ""online"",
""status_message"": null,
""max_precision"": ""0.01"",
""convertible_to"": [""USDC""], ""details"": { }
},
{
""id"": ""USDC"",
""name"": ""USD Coin"",
""min_size"": ""0.00000100"",
""status"": ""online"",
""status_message"": null,
""max_precision"": ""0.000001"",
""convertible_to"": [""USD""], ""details"": { }
},
{
""id"": ""BTC"",
""name"": ""Bitcoin"",
""min_size"":"" 0.00000001"",
""status"": ""online"",
""status_message"": null,
""max_precision"": ""0.00000001"",
""convertible_to"": []
}
]
}";
}

public static string CreateMatchResponse()
{
return @"
Expand Down
18 changes: 16 additions & 2 deletions CoinbasePro.Specs/WebSocket/WebSocketSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class with_authentication_with_no_channels

It should_have_called_send_with_authentication_properties = () =>
The<IWebSocketFeed>().
WasToldTo(p => p.Send(@"{""type"":""subscribe"",""product_ids"":[""BTC-USD""],""channels"":[{""name"":""full"",""product_ids"":[""BTC-USD""]},{""name"":""heartbeat"",""product_ids"":[""BTC-USD""]},{""name"":""level2"",""product_ids"":[""BTC-USD""]},{""name"":""matches"",""product_ids"":[""BTC-USD""]},{""name"":""ticker"",""product_ids"":[""BTC-USD""]},{""name"":""user"",""product_ids"":[""BTC-USD""]}],""key"":""key"",""passphrase"":""passphrase"",""timestamp"":""-62135596800""}"));
WasToldTo(p => p.Send(@"{""type"":""subscribe"",""product_ids"":[""BTC-USD""],""channels"":[{""name"":""full"",""product_ids"":[""BTC-USD""]},{""name"":""heartbeat"",""product_ids"":[""BTC-USD""]},{""name"":""level2"",""product_ids"":[""BTC-USD""]},{""name"":""matches"",""product_ids"":[""BTC-USD""]},{""name"":""ticker"",""product_ids"":[""BTC-USD""]},{""name"":""user"",""product_ids"":[""BTC-USD""]},{""name"":""status"",""product_ids"":[""BTC-USD""]}],""key"":""key"",""passphrase"":""passphrase"",""timestamp"":""-62135596800""}"));
}

class with_authentication_with_specified_channels
Expand Down Expand Up @@ -178,7 +178,7 @@ class without_authentication

It should_have_called_send_without_authentication_properties = () =>
The<IWebSocketFeed>().
WasToldTo(p => p.Send(@"{""type"":""subscribe"",""product_ids"":[""BTC-USD""],""channels"":[{""name"":""full"",""product_ids"":[""BTC-USD""]},{""name"":""heartbeat"",""product_ids"":[""BTC-USD""]},{""name"":""level2"",""product_ids"":[""BTC-USD""]},{""name"":""matches"",""product_ids"":[""BTC-USD""]},{""name"":""ticker"",""product_ids"":[""BTC-USD""]},{""name"":""user"",""product_ids"":[""BTC-USD""]}],""timestamp"":""-62135596800""}"));
WasToldTo(p => p.Send(@"{""type"":""subscribe"",""product_ids"":[""BTC-USD""],""channels"":[{""name"":""full"",""product_ids"":[""BTC-USD""]},{""name"":""heartbeat"",""product_ids"":[""BTC-USD""]},{""name"":""level2"",""product_ids"":[""BTC-USD""]},{""name"":""matches"",""product_ids"":[""BTC-USD""]},{""name"":""ticker"",""product_ids"":[""BTC-USD""]},{""name"":""user"",""product_ids"":[""BTC-USD""]},{""name"":""status"",""product_ids"":[""BTC-USD""]}],""timestamp"":""-62135596800""}"));
}
}

Expand Down Expand Up @@ -327,6 +327,20 @@ class when_response_type_is_done
WasToldTo(p => p.Invoke(Param.IsAny<EventHandler<WebfeedEventArgs<Done>>>(), Param.IsAny<object>(), Param.IsAny<WebfeedEventArgs<Done>>()));
}

class when_response_type_is_status
{
Because of = () =>
{
Subject.Start(product_type_inputs, no_channel_type_inputs);

websocket_feed.Raise(e => e.MessageReceived += null, new MessageReceivedEventArgs(WebSocketTypeResponseFixture.CreateStatusResponse()));
};

It should_have_invoked_status_response = () =>
The<IWebSocketFeed>().
WasToldTo(p => p.Invoke(Param.IsAny<EventHandler<WebfeedEventArgs<CoinbasePro.WebSocket.Models.Response.Status>>>(), Param.IsAny<object>(), Param.IsAny<WebfeedEventArgs<CoinbasePro.WebSocket.Models.Response.Status>>()));
}

class when_response_type_is_match
{
Because of = () =>
Expand Down
1 change: 1 addition & 0 deletions CoinbasePro/WebSocket/IWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface IWebSocket
void WebSocket_Closed(object sender, EventArgs e);

event EventHandler<WebfeedEventArgs<Ticker>> OnTickerReceived;
event EventHandler<WebfeedEventArgs<Status>> OnStatusReceived;
event EventHandler<WebfeedEventArgs<Subscription>> OnSubscriptionReceived;
event EventHandler<WebfeedEventArgs<Snapshot>> OnSnapShotReceived;
event EventHandler<WebfeedEventArgs<Level2>> OnLevel2UpdateReceived;
Expand Down
84 changes: 84 additions & 0 deletions CoinbasePro/WebSocket/Models/Response/Status.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace CoinbasePro.WebSocket.Models.Response
{
public class Status : BaseMessage
{
public Product[] Products { get; set; }

public Currency[] Currencies { get; set; }
}

public class Currency
{
public string Id { get; set; }

public string Name { get; set; }

public decimal MinSize { get; set; }

public string Status { get; set; }

public string StatusMessage { get; set; }

public decimal MaxPrecision { get; set; }

public string[] ConvertibleTo { get; set; }

public Details Details { get; set; }
}

public class Details
{
public string Type { get; set; }

public string Symbol { get; set; }

public int NetworkConfirmations { get; set; }

public int SortOrder { get; set; }

public string CryptoAddressLink { get; set; }

public string CryptoTransactionLink { get; set; }

public string[] PushPaymentMethods { get; set; }

public long? MaxWithdrawalAmount { get; set; }

public string[] GroupTypes { get; set; }

public string DisplayName { get; set; }
}

public class Product
{
public string Id { get; set; }

public string BaseCurrency { get; set; }

public string QuoteCurrency { get; set; }

public decimal BaseMinSize { get; set; }

public decimal BaseMaxSize { get; set; }

public decimal BaseIncrement { get; set; }

public decimal QuoteIncrement { get; set; }

public string DisplayName { get; set; }

public string Status { get; set; }

public string StatusMessage { get; set; }

public decimal MinMarketFunds { get; set; }

public decimal MaxMarketFunds { get; set; }

public bool PostOnly { get; set; }

public bool LimitOnly { get; set; }

public bool CancelOnly { get; set; }
}
}
4 changes: 3 additions & 1 deletion CoinbasePro/WebSocket/Types/ChannelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum ChannelType
[EnumMember(Value = "ticker")]
Ticker,
[EnumMember(Value = "user")]
User
User,
[EnumMember(Value = "status")]
Status
}
}
3 changes: 2 additions & 1 deletion CoinbasePro/WebSocket/Types/ResponseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ResponseType
LastMatch,
Change,
Activate,
Error
Error,
Status
}
}
5 changes: 5 additions & 0 deletions CoinbasePro/WebSocket/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ public void WebSocket_MessageReceived(object sender, MessageReceivedEventArgs e)
var activate = JsonConfig.DeserializeObject<Activate>(json);
webSocketFeed.Invoke(OnActivateReceived, sender, new WebfeedEventArgs<Activate>(activate));
break;
case ResponseType.Status:
var status = JsonConfig.DeserializeObject<Status>(json);
webSocketFeed.Invoke(OnStatusReceived, sender, new WebfeedEventArgs<Status>(status));
break;
default:
Log.Error("Unknown ResponseType {@ResponseJson}. Ignoring message received.", json);
break;
Expand Down Expand Up @@ -323,6 +327,7 @@ private string SubscribeMessage(bool withAuthentication, List<Channel> channels,
}

public event EventHandler<WebfeedEventArgs<Ticker>> OnTickerReceived;
public event EventHandler<WebfeedEventArgs<Status>> OnStatusReceived;
public event EventHandler<WebfeedEventArgs<Subscription>> OnSubscriptionReceived;
public event EventHandler<WebfeedEventArgs<Snapshot>> OnSnapShotReceived;
public event EventHandler<WebfeedEventArgs<Level2>> OnLevel2UpdateReceived;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ The following methods are EventHandlers:
- OnHeartbeatReceived - EventHandler for data with response type `heartbeat`
- OnReceivedReceived - EventHandler for data with response type `received`
- OnOpenReceived - EventHandler for data with response type `open`
- OnStatusReceived - EventHandler for data with response type `status`
- OnDoneReceived - EventHandler for data with response type `done`
- OnMatchReceived - EventHandler for data with response type `match`
- OnChangeReceived - EventHandler for data with response type `change`
Expand Down

0 comments on commit 8503ffe

Please sign in to comment.