2323using QuantConnect . Brokerages ;
2424using QuantConnect . Tests . Common . Securities ;
2525using QuantConnect . Lean . Engine . DataFeeds ;
26+ using QuantConnect . Orders ;
2627
2728namespace QuantConnect . Tests . Brokerages . Bitfinex
2829{
@@ -37,9 +38,10 @@ public partial class BitfinexBrokerageTests : BrokerageTests
3738 /// <returns></returns>
3839 protected override IBrokerage CreateBrokerage ( IOrderProvider orderProvider , ISecurityProvider securityProvider )
3940 {
41+ var security = securityProvider . GetSecurity ( Symbol ) ;
4042 var securities = new SecurityManager ( new TimeKeeper ( DateTime . UtcNow , TimeZones . NewYork ) )
4143 {
42- { Symbol , SecurityProvider . GetSecurity ( Symbol ) }
44+ { Symbol , security }
4345 } ;
4446
4547 var transactions = new SecurityTransactionManager ( null , securities ) ;
@@ -48,8 +50,9 @@ protected override IBrokerage CreateBrokerage(IOrderProvider orderProvider, ISec
4850
4951 var algorithm = new Mock < IAlgorithm > ( ) ;
5052 algorithm . Setup ( a => a . Transactions ) . Returns ( transactions ) ;
51- algorithm . Setup ( a => a . BrokerageModel ) . Returns ( new BitfinexBrokerageModel ( ) ) ;
53+ algorithm . Setup ( a => a . BrokerageModel ) . Returns ( new BitfinexBrokerageModel ( AccountType . Cash ) ) ;
5254 algorithm . Setup ( a => a . Portfolio ) . Returns ( new SecurityPortfolioManager ( securities , transactions , algorithmSettings ) ) ;
55+ algorithm . Setup ( a => a . Securities ) . Returns ( securities ) ;
5356
5457 return new BitfinexBrokerage (
5558 Config . Get ( "bitfinex-api-key" ) ,
@@ -64,13 +67,21 @@ protected override IBrokerage CreateBrokerage(IOrderProvider orderProvider, ISec
6467 /// Gets the symbol to be traded, must be shortable
6568 /// </summary>
6669 protected override Symbol Symbol => StaticSymbol ;
67- private static Symbol StaticSymbol => Symbol . Create ( "ETHUSD " , SecurityType . Crypto , Market . Bitfinex ) ;
70+ private static Symbol StaticSymbol => Symbol . Create ( "TESTBTCTESTUSD " , SecurityType . Crypto , Market . Bitfinex ) ;
6871
6972 /// <summary>
7073 /// Gets the security type associated with the <see cref="BrokerageTests.Symbol" />
7174 /// </summary>
7275 protected override SecurityType SecurityType => SecurityType . Crypto ;
7376
77+ private static TestCaseData [ ] OrderParameters =>
78+ [
79+ new TestCaseData ( new MarketOrderTestParameters ( StaticSymbol ) ) ,
80+ new TestCaseData ( new LimitOrderTestParameters ( StaticSymbol , 1000m , 100m ) ) ,
81+ new TestCaseData ( new StopMarketOrderTestParameters ( StaticSymbol , 1000m , 100m ) ) ,
82+ new TestCaseData ( new StopLimitOrderTestParameters ( StaticSymbol , 1000m , 100m ) ) ,
83+ ] ;
84+
7485 /// <summary>
7586 /// Gets the current market price of the specified security
7687 /// </summary>
@@ -95,43 +106,61 @@ protected override decimal GetAskPrice(Symbol symbol)
95106 /// </summary>
96107 protected override decimal GetDefaultQuantity ( ) => 0.04m ;
97108
98- [ Explicit ( "Ignore a test" ) ]
109+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
99110 public override void CancelOrders ( OrderTestParameters parameters )
100111 {
101112 base . CancelOrders ( parameters ) ;
102113 }
103114
104- [ Explicit ( "Ignore a test" ) ]
115+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
105116 public override void LongFromZero ( OrderTestParameters parameters )
106117 {
107118 base . LongFromZero ( parameters ) ;
119+
120+ if ( parameters is not MarketOrderTestParameters )
121+ {
122+ // We expect the orders to be open
123+ var openOrders = Brokerage . GetOpenOrders ( ) ;
124+ Assert . AreEqual ( 1 , openOrders . Count ) ;
125+
126+ var expectedOrderType = parameters switch
127+ {
128+ LimitOrderTestParameters _ => typeof ( LimitOrder ) ,
129+ StopMarketOrderTestParameters _ => typeof ( StopMarketOrder ) ,
130+ StopLimitOrderTestParameters _ => typeof ( StopLimitOrder ) ,
131+ _ => throw new ArgumentException ( "Unsupported order type for this test" , nameof ( parameters ) )
132+ } ;
133+
134+ // Check that the order type matches the expected type
135+ Assert . IsInstanceOf ( expectedOrderType , openOrders [ 0 ] ) ;
136+ }
108137 }
109138
110- [ Explicit ( "Ignore a test" ) ]
139+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
111140 public override void CloseFromLong ( OrderTestParameters parameters )
112141 {
113142 base . CloseFromLong ( parameters ) ;
114143 }
115144
116- [ Explicit ( "Ignore a test" ) ]
145+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
117146 public override void ShortFromZero ( OrderTestParameters parameters )
118147 {
119148 base . ShortFromZero ( parameters ) ;
120149 }
121150
122- [ Explicit ( "Ignore a test" ) ]
151+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
123152 public override void CloseFromShort ( OrderTestParameters parameters )
124153 {
125154 base . CloseFromShort ( parameters ) ;
126155 }
127156
128- [ Explicit ( "Ignore a test" ) ]
157+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
129158 public override void ShortFromLong ( OrderTestParameters parameters )
130159 {
131160 base . ShortFromLong ( parameters ) ;
132161 }
133162
134- [ Explicit ( "Ignore a test" ) ]
163+ [ TestCaseSource ( nameof ( OrderParameters ) ) ]
135164 public override void LongFromShort ( OrderTestParameters parameters )
136165 {
137166 base . LongFromShort ( parameters ) ;
0 commit comments