-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
What is the preferred way to add futures/swap support #536
Comments
Are you talking about OKEx? |
OKEx, Huobi, Binance, Deribit, KuCoin etc. |
For OKEx, can you determine whether it's futures / swap from the symbol name? I haven't looked into he others. |
Maybe futures/swap can be determined by symbol name. But margin/spot share the same symbol names and depths. |
In that case, I think option (b) would be better and less confusing. |
Which methods would need the parameter? |
Actually, a better option would be to create a property in protected bool isMarginTradingEnabled = false;
public virtual bool IsMarginTradingEnabled
{
get { return isMarginTradingEnabled; }
set { throw new NotImplementedException(
"Margin trading is not implemented for this exchange. Please submit a PR if you would like to implement it."); }
} Any exchanges that do implement it can override the property to set the field |
Would returning false be better, that way people don't have unexpected exceptions? I suppose if we document the setter with a NotImplementedException that may be sufficient? |
|
Also, the exception would only be thrown if someone tries to use margin trading where not implemented. All existing user code would still work fine w/o any changes. |
What would a derived class look like trying to set the bool to true? Would it need it's own bool? |
The derived class would have this: public override bool IsMarginTradingEnabled
{
get { return isMarginTradingEnabled; }
set { isMarginTradingEnabled = value; }
} |
I would propose the following, where derived classes opt in and override IsMarginTradingPossible to true if desired. ///<summary>Indicates if margin trading is possible. Derived classes can override and return true. The default is false.</summary>
public virtual bool IsMarginTradingPossible => false;
private bool isMarginTradingEnabled = false;
///<summary>Gets whether margin trading has been turned on. If IsMarginTradingPossible is false, any attempt to set this value will throw a NotImplementedException.</summary>
public bool IsMarginTradingEnabled
{
get { return isMarginTradingEnabled; }
set
{
if (!IsMarginTradingPossible)
{
throw new NotImplementedException(
"Margin trading is not implemented for this exchange. Please submit a PR if you would like to implement it, derived classes can override IsMarginTradingPossible to return true .");
}
isMarginTradingEnabled = value;
}
} |
Yes, I like that |
Awesome, sounds like a plan for whoever tackles this beast :) |
How is isMarginEnabled related to futures/swap? |
isMarginEnabled is just for whether the user wants to use margin vs spot. Since the symbol names for futures/swap are different, those can be added to the existing methods without adding any parameters. |
a) Add another virtual exchange that works only for futures, yet another one for swap.
b) Add a marketType parameter to all methods of the existing exchange.
The first one is closer to the native APIs provided by most exchanges.
The second one is more user friendly in my opinion.
The text was updated successfully, but these errors were encountered: