-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplace_order.py
More file actions
52 lines (36 loc) · 2.09 KB
/
place_order.py
File metadata and controls
52 lines (36 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from ibapi.client import *
from ibapi.wrapper import *
class TestApp(EClient, EWrapper):
def __init__(self):
EClient.__init__(self, self)
def nextValidId(self, orderId: int):
mycontract = Contract()
mycontract.symbol = 'AAPL'
mycontract.secType = 'STK'
mycontract.exchange = 'SMART'
mycontract.currency = 'USD'
self.reqContractDetails(orderId, mycontract)
def contractDetails(self, reqId: int, contractDetails: ContractDetails):
# return super().contractDetails(reqId, contractDetails)
print(contractDetails.contract)
myorder = Order()
myorder.orderId = reqId
myorder.action = 'SELL'
myorder.tif = 'GTC'
myorder.orderType = 'LMT'
myorder.lmtPrice = 150.50
myorder.totalQuantity = 10
self.placeOrder(reqId, contractDetails.contract, myorder)
# self.disconnect()
def openOrder(self, orderId: OrderId, contract: Contract, order: Order, orderState: OrderState):
# return super().openOrder(orderId, contract, order, orderState)
print(f'openOrder. orderId: {orderId}, contract: {contract}, order: {order}')
def orderStatus(self, orderId: OrderId, status: str, filled: Decimal, remaining: Decimal, avgFillPrice: float, permId: int, parentId: int, lastFillPrice: float, clientId: int, whyHeld: str, mktCapPrice: float):
# return super().orderStatus(orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld, mktCapPrice)
print(f'orderStatus. orderId: {orderId}, status: {status}, filled: {filled}, remaining: {remaining}, avgFillPrice: {avgFillPrice}, permId: {permId}, parentId: {parentId}, lastFillPrice: {lastFillPrice}, clientId: {clientId}, whyHeld: {whyHeld}, mktCapPrice: {mktCapPrice}')
def execDetails(self, reqId: int, contract: Contract, execution: Execution):
# return super().execDetails(reqId, contract, execution)
print(f'execDetails. reqId: {reqId}, contract: {contract}, execution: {execution}')
app = TestApp()
app.connect('127.0.0.1', 7497, 3000)
app.run()