6262import velox .api .layer1 .layers .utils .OrderBook ;
6363
6464@ Layer1ApiVersion (Layer1ApiVersionValue .VERSION1 )
65- @ Layer0LiveModule (shortName = "MEX" , fullName = "BitMEX" )
65+ @ Layer0LiveModule (shortName = "MEX" , fullName = "BitMEX" )
6666public class Provider extends ExternalLiveBaseProvider {
6767
6868 private BmConnector connector ;
@@ -87,10 +87,8 @@ public class Provider extends ExternalLiveBaseProvider {
8787 private Map <String , Double > trailingStops = new HashMap <>();
8888 private List <String > batchCancels = new LinkedList <>();
8989 private Map <String , BalanceInfo .BalanceInCurrency > balanceMap = new HashMap <>();
90-
91- private CopyOnWriteArrayList <SubscribeInfo > knownInstruments = new CopyOnWriteArrayList <>();
9290
93-
91+ private CopyOnWriteArrayList < SubscribeInfo > knownInstruments = new CopyOnWriteArrayList <>();
9492
9593 protected class Instrument {
9694 protected final String alias ;
@@ -119,7 +117,7 @@ public HashMap<String, OrderInfoBuilder> getWorkingOrders() {
119117 public BmConnector getConnector () {
120118 return connector ;
121119 }
122-
120+
123121 public List <SubscribeInfo > getKnownInstruments () {
124122 return knownInstruments ;
125123 }
@@ -157,7 +155,7 @@ public void subscribe(SubscribeInfo subscribeInfo) {
157155 final String symbol = subscribeInfo .symbol ;
158156 final String exchange = subscribeInfo .exchange ;
159157 final String type = subscribeInfo .type ;
160-
158+
161159 Log .info ("[bitmex] Provider subscribe" );
162160 String alias = createAlias (symbol , exchange , type );
163161 // Since instruments also will be accessed from the data generation
@@ -292,7 +290,7 @@ private SimpleOrderSendParameters createStopLossFromParameters(SimpleOrderSendPa
292290 int offsetMultiplier = simpleParams .isBuy ? 1 : -1 ;
293291
294292 double limitPriceChecked = checkLImitPriceForBracket (simpleParams , bmInstrument );
295-
293+
296294 SimpleOrderSendParameters stopLoss = new SimpleOrderSendParameters (
297295 simpleParams .alias ,
298296 !simpleParams .isBuy , // !
@@ -321,13 +319,12 @@ private SimpleOrderSendParameters createTakeProfitFromParameters(SimpleOrderSend
321319 simpleParams .sizeMultiplier );
322320 return takeProfit ;
323321 }
324-
325- private double checkLImitPriceForBracket (SimpleOrderSendParameters simpleParams , BmInstrument bmInstrument ){
322+
323+ private double checkLImitPriceForBracket (SimpleOrderSendParameters simpleParams , BmInstrument bmInstrument ) {
326324 double limitPriceChecked = simpleParams .limitPrice ;
327325 if (Double .isNaN (simpleParams .limitPrice )) {
328326 OrderBook orderBook = bmInstrument .getOrderBook ();
329- limitPriceChecked = simpleParams .isBuy ?
330- orderBook .getBestAskPriceOrNone () * bmInstrument .getTickSize ()
327+ limitPriceChecked = simpleParams .isBuy ? orderBook .getBestAskPriceOrNone () * bmInstrument .getTickSize ()
331328 : orderBook .getBestBidPriceOrNone () * bmInstrument .getTickSize ();
332329 }
333330 return limitPriceChecked ;
@@ -894,26 +891,26 @@ public void listenForPosition(UnitPosition pos) {
894891 }
895892
896893 public void listenForWallet (UnitWallet wallet ) {
894+ BalanceInfo .BalanceInCurrency currentBic = balanceMap .get (wallet .getCurrency ());
895+ BalanceInfo .BalanceInCurrency newBic ;
896+ if (currentBic == null ) {// no current balance balance
897+ newBic = new BalanceInfo .BalanceInCurrency (0.0 , 0.0 , 0.0 , 0.0 , 0.0 ,
898+ null , null );
899+ }
900+
897901 long tempMultiplier = 100000000 ;// temp
898- Double balance = (double ) wallet .getAmount () / tempMultiplier ;
899902 // PNLs and NetLiquidityValue are taken from UnitMargin topic
900- Double previousDayBalance = (double ) wallet .getPrevAmount () / tempMultiplier ;
901903 Double netLiquidityValue = 0.0 ;// to be calculated
902904 String currency = wallet .getCurrency ();
903905 Double rateToBase = null ;
904906
905- BalanceInfo .BalanceInCurrency currentBic = balanceMap .get (wallet .getCurrency ());
906- BalanceInfo .BalanceInCurrency newBic ;
907- if (currentBic == null ) {// no current balance balance
908- newBic = new BalanceInfo .BalanceInCurrency (balance , 0.0 , 0.0 , previousDayBalance , netLiquidityValue ,
909- currency , rateToBase );
910- } else {
911- newBic = new BalanceInfo .BalanceInCurrency (balance == null ? currentBic .balance : balance ,
912- currentBic .realizedPnl , currentBic .unrealizedPnl ,
913- previousDayBalance == null ? currentBic .previousDayBalance : previousDayBalance ,
914- netLiquidityValue == null ? currentBic .netLiquidityValue : netLiquidityValue , currentBic .currency ,
915- rateToBase == null ? currentBic .rateToBase : rateToBase );
916- }
907+ newBic = new BalanceInfo .BalanceInCurrency (
908+ wallet .getAmount () == null ? currentBic .balance : (double ) wallet .getAmount () / tempMultiplier ,
909+ currentBic .realizedPnl , currentBic .unrealizedPnl ,
910+ wallet .getPrevAmount () == null ? currentBic .previousDayBalance : (double ) wallet .getPrevAmount () / tempMultiplier ,
911+ netLiquidityValue == null ? currentBic .netLiquidityValue : netLiquidityValue , currentBic .currency ,
912+ rateToBase == null ? currentBic .rateToBase : rateToBase );
913+
917914 balanceMap .remove (currency );
918915 balanceMap .put (currency , newBic );
919916 BalanceInfo info = new BalanceInfo (new ArrayList <BalanceInfo .BalanceInCurrency >(balanceMap .values ()));
@@ -1097,20 +1094,20 @@ public Layer1ApiProviderSupportedFeatures getSupportedFeatures() {
10971094 }
10981095
10991096 a .setOco (true )
1100- .setBrackets (true )
1101- .setSupportedOrderDurations (Arrays .asList (new OrderDuration [] { OrderDuration .GTC }))
1102- // At the moment of writing this method it was not possible to
1103- // report limit orders support, but no stop orders support
1104- // If you actually need it, you can report stop orders support
1105- // but reject stop orders when those are sent.
1106- .setSupportedStopOrders (Arrays .asList (new OrderType [] { OrderType .LMT , OrderType .MKT }))
1107- .setBalanceSupported (true )
1108- .setTrailingStopsAsIndependentOrders (true )
1109- .setExchangeUsedForSubscription (false )
1110- .setTypeUsedForSubscription (false )
1111- .setHistoricalDataInfo (new BmSimpleHistoricalDataInfo (
1112- "http://bitmex.historicaldata.bookmap.com:38080/historical-data-server-1.0/" ))
1113- .setKnownInstruments (knownInstruments );
1097+ .setBrackets (true )
1098+ .setSupportedOrderDurations (Arrays .asList (new OrderDuration [] { OrderDuration .GTC }))
1099+ // At the moment of writing this method it was not possible to
1100+ // report limit orders support, but no stop orders support
1101+ // If you actually need it, you can report stop orders support
1102+ // but reject stop orders when those are sent.
1103+ .setSupportedStopOrders (Arrays .asList (new OrderType [] { OrderType .LMT , OrderType .MKT }))
1104+ .setBalanceSupported (true )
1105+ .setTrailingStopsAsIndependentOrders (true )
1106+ .setExchangeUsedForSubscription (false )
1107+ .setTypeUsedForSubscription (false )
1108+ .setHistoricalDataInfo (new BmSimpleHistoricalDataInfo (
1109+ "http://bitmex.historicaldata.bookmap.com:38080/historical-data-server-1.0/" ))
1110+ .setKnownInstruments (knownInstruments );
11141111
11151112 // Log.info("PROVIDER getSupportedFeatures INVOKED");
11161113 return a .build ();
0 commit comments