-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Add support for rate limits introduced by Upstox. 2. Introduced 'RetryPolicyFactory' to provide support for retries on failed API requests. 3. Add method for new API endpoint - Fetch Subscribed Symbols. 4. Add support for the new Historical endpoint. 5. WebSocket reconnect feature provided by the OkHTTP library is now disabled by default. 6. Updated Google Guava to '27.0.1-jre'. 7. Updated the tests.
- Loading branch information
Showing
26 changed files
with
1,014 additions
and
263 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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/github/rishabh9/riko/upstox/common/RetryPolicyFactory.java
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,55 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Rishabh Joshi | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.rishabh9.riko.upstox.common; | ||
|
||
import net.jodah.failsafe.RetryPolicy; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Optional; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
* A simple factory to create policies for retrying when an API call fails. | ||
* Riko uses the open source <a href="https://github.com/jhalterman/failsafe">Failsafe</a> | ||
* library for implementing retries. | ||
* | ||
* @see RikoRetryPolicyFactory | ||
*/ | ||
public interface RetryPolicyFactory { | ||
|
||
/** | ||
* @return A {@link RetryPolicy} that expresses when retries should be performed. | ||
* An {@code empty} {@link RetryPolicy} indicates retries should be disabled. | ||
*/ | ||
@Nonnull | ||
Optional<RetryPolicy> createRetryPolicy(); | ||
|
||
/** | ||
* @return A {@link ScheduledExecutorService} to allow for asynchronous executions. | ||
* Cannot be {@code null}. | ||
*/ | ||
@Nonnull | ||
ScheduledExecutorService createExecutorService(); | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/github/rishabh9/riko/upstox/common/RikoRetryPolicyFactory.java
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,59 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Rishabh Joshi | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.rishabh9.riko.upstox.common; | ||
|
||
import net.jodah.failsafe.RetryPolicy; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* The Riko's default retry policy factory. | ||
* | ||
* @see RetryPolicyFactory | ||
*/ | ||
public class RikoRetryPolicyFactory implements RetryPolicyFactory { | ||
|
||
/** | ||
* @return The default {@link RetryPolicy} | ||
*/ | ||
@Override | ||
public Optional<RetryPolicy> createRetryPolicy() { | ||
return Optional.of(new RetryPolicy() | ||
.retryOn(Throwable.class) | ||
.withBackoff(1, 5, TimeUnit.SECONDS) | ||
.withMaxRetries(3)); | ||
} | ||
|
||
/** | ||
* @return The default {@link ScheduledExecutorService} to be used by {@link RetryPolicy}. | ||
*/ | ||
@Override | ||
public ScheduledExecutorService createExecutorService() { | ||
return Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors()); | ||
} | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/github/rishabh9/riko/upstox/common/constants/RateLimits.java
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,48 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018 Rishabh Joshi | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.rishabh9.riko.upstox.common.constants; | ||
|
||
public class RateLimits { | ||
public static final double LIVE_FEED_RATE_LIMIT = 1.0D; | ||
public static final double SUBSCRIBE_RATE_LIMIT = 1.0D; | ||
public static final double UNSUBSCRIBE_RATE_LIMIT = 1.0D; | ||
public static final double SYMBOLS_SUBSCRIBED_RATE_LIMIT = 1.0D; | ||
public static final double HISTORICAL_RATE_LIMIT = 10.0D; | ||
public static final double LOGIN_RATE_LIMIT = 1.0D; | ||
public static final double ORDER_HISTORY_RATE_LIMIT = 1.0D; | ||
public static final double ORDER_DETAILS_RATE_LIMIT = 1.0D; | ||
public static final double TRADE_BOOK_RATE_LIMIT = 1.0D; | ||
public static final double TRADE_HISTORY_RATE_LIMIT = 1.0D; | ||
public static final double PLACE_ORDER_RATE_LIMIT = 10.0D; | ||
public static final double MODIFY_ORDER_RATE_LIMIT = 1.0D; | ||
public static final double CANCEL_ORDER_RATE_LIMIT = 1.0D; | ||
public static final double PROFILE_RATE_LIMIT = 1.0D; | ||
public static final double BALANCE_RATE_LIMIT = 1.0D; | ||
public static final double POSITIONS_RATE_LIMIT = 1.0D; | ||
public static final double HOLDINGS_RATE_LIMIT = 1.0D; | ||
public static final double MASTER_CONTRACT_RATE_LIMIT = 1.0D; | ||
public static final double WS_PARAMS_RATE_LIMIT = 1.0D; | ||
public static final double WEB_SOCKET_RATE_LIMIT = 1.0D; | ||
} |
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
Oops, something went wrong.