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

Placing A Basic Order #13

Open
dshanabrook opened this issue Jul 23, 2015 · 5 comments
Open

Placing A Basic Order #13

dshanabrook opened this issue Jul 23, 2015 · 5 comments

Comments

@dshanabrook
Copy link

I am trying to figure out how to place an order. Is this currently possible?

I found the PlaceOrder type, but am unclear on how to actually place the order. I found the .write method on it, but it doesn't seem to be used anywhere and is private.

@dsouzae
Copy link
Contributor

dsouzae commented Jul 25, 2015

Here is my example on how I do a buy (both market and limit orders):

func NewContract(symbol string) ib.Contract {
    return ib.Contract{
        Symbol:       symbol,
        SecurityType: "STK",
        Exchange:     "SMART",
        Currency:     "USD",
    }
}

func doBuy(engine *ib.Engine, symbol string, quantity uint64, market bool, price float64) {
    request := ib.PlaceOrder{
        Contract: NewContract(symbol),
    }

    request.Order, _ = ib.NewOrder()
    request.Order.Action = "BUY"
    request.Order.TotalQty = int64(quantity)

    if market {
        request.Order.OrderType = "MKT"
    } else {
        request.Order.OrderType = "LMT"
        request.Order.LimitPrice = price
    }
    request.SetID(NextOrderID())

    engine.Send(&request)
}

Function NextOrderID() is my own creation and should be set to the valid return value from the NextValidID object when doing: engine.Send(&ib.RequestIDs{})

I've got a functional command line programming using readline that I use for my current trading. If anyone is interesting I will work on making it a separate repository under my account.

@saulshanabrook
Copy link

@dsouzae It would be great to see that code open sourced. Even if I wouldn't use it myself, seeing an example of all this together would be really helpful.

@uwe
Copy link
Contributor

uwe commented Jul 25, 2015

I would also like to see the code. More examples are necessary, especially for getting started. It was your example @dsouzae in a ticket, that helped me getting started with gofinance/ib.

@dsouzae
Copy link
Contributor

dsouzae commented Jul 26, 2015

I have created repository for my current version. It needs some clean up and proper documentation. But It should be relatively easy to read.

https://github.com/dsouzae/ibstockcli

@dshanabrook
Copy link
Author

@dsouzae Thanks for the repository. I am trying to place a trade with an advisor account. If I want to place an buy order with a specific AccountCode, should I just set the ClientID on the Order?

If not, how would I do it?

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

4 participants