Skip to content
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

Open
szmcdull opened this issue Apr 16, 2020 · 17 comments
Open

What is the preferred way to add futures/swap support #536

szmcdull opened this issue Apr 16, 2020 · 17 comments

Comments

@szmcdull
Copy link
Contributor

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.

@vslee
Copy link
Collaborator

vslee commented Apr 16, 2020

Are you talking about OKEx?

@szmcdull
Copy link
Contributor Author

OKEx, Huobi, Binance, Deribit, KuCoin etc.

@vslee
Copy link
Collaborator

vslee commented Apr 16, 2020

For OKEx, can you determine whether it's futures / swap from the symbol name? I haven't looked into he others.

@szmcdull
Copy link
Contributor Author

Maybe futures/swap can be determined by symbol name. But margin/spot share the same symbol names and depths.

@vslee
Copy link
Collaborator

vslee commented Apr 20, 2020

In that case, I think option (b) would be better and less confusing.

@jjxtra
Copy link
Collaborator

jjxtra commented Apr 20, 2020

Which methods would need the parameter?

@vslee
Copy link
Collaborator

vslee commented Apr 22, 2020

Actually, a better option would be to create a property in ExchangeAPI:

		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 isMarginTradingEnabled. This way, no new classes need to be created, and no method signatures need to be changed.

@jjxtra
Copy link
Collaborator

jjxtra commented Apr 22, 2020

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?

@vslee
Copy link
Collaborator

vslee commented Apr 22, 2020

isMarginTradingEnabled is by default set to false (I updated the code above to make it clearer). I think it is better to throw an execption, than to have ppl set it to true and thinking that they are using margin trading when they are not. This would be set in the initialization part of ppl's code anyways, so it's not like it would interrupt their trading in the middle of the day.

@vslee
Copy link
Collaborator

vslee commented Apr 22, 2020

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.

@jjxtra
Copy link
Collaborator

jjxtra commented Apr 22, 2020

What would a derived class look like trying to set the bool to true? Would it need it's own bool?

@vslee
Copy link
Collaborator

vslee commented Apr 22, 2020

The derived class would have this:

		public override bool IsMarginTradingEnabled
		{
			get { return isMarginTradingEnabled; }
			set { isMarginTradingEnabled = value; }
		}

@jjxtra
Copy link
Collaborator

jjxtra commented Apr 22, 2020

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;
    }
}

@vslee
Copy link
Collaborator

vslee commented Apr 22, 2020

Yes, I like that

@jjxtra
Copy link
Collaborator

jjxtra commented Apr 22, 2020

Awesome, sounds like a plan for whoever tackles this beast :)

@szmcdull
Copy link
Contributor Author

How is isMarginEnabled related to futures/swap?

@vslee
Copy link
Collaborator

vslee commented Apr 24, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants