Update app.py
Browse files
app.py
CHANGED
|
@@ -158,7 +158,6 @@ def get_authenticated_socket(account_id, access_token):
|
|
| 158 |
def resolve_symbol_id(ssl_sock, account_id, symbol_name):
|
| 159 |
req = ProtoOASymbolsListReq()
|
| 160 |
req.ctidTraderAccountId = int(account_id)
|
| 161 |
-
req.includeLightDetails = True
|
| 162 |
send_proto_message(ssl_sock, req, 2114)
|
| 163 |
|
| 164 |
while True:
|
|
@@ -206,18 +205,22 @@ def get_open_positions(ssl_sock, account_id):
|
|
| 206 |
return res.position
|
| 207 |
return []
|
| 208 |
|
| 209 |
-
# Helper: Place Market Order
|
| 210 |
def place_market_order(ssl_sock, account_id, symbol_id, trade_side, volume, position_id=None):
|
| 211 |
-
req = ProtoOANewOrderReq()
|
| 212 |
-
req.ctidTraderAccountId = int(account_id)
|
| 213 |
-
req.symbolId = int(symbol_id)
|
| 214 |
-
req.orderType = ProtoOAOrderType.MARKET
|
| 215 |
-
req.tradeSide = trade_side
|
| 216 |
-
req.volume = int(volume)
|
| 217 |
if position_id is not None:
|
|
|
|
|
|
|
| 218 |
req.positionId = int(position_id)
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
while True:
|
| 223 |
proto_msg = receive_proto_message(ssl_sock)
|
|
|
|
| 158 |
def resolve_symbol_id(ssl_sock, account_id, symbol_name):
|
| 159 |
req = ProtoOASymbolsListReq()
|
| 160 |
req.ctidTraderAccountId = int(account_id)
|
|
|
|
| 161 |
send_proto_message(ssl_sock, req, 2114)
|
| 162 |
|
| 163 |
while True:
|
|
|
|
| 205 |
return res.position
|
| 206 |
return []
|
| 207 |
|
| 208 |
+
# Helper: Place Market Order or Close Position
|
| 209 |
def place_market_order(ssl_sock, account_id, symbol_id, trade_side, volume, position_id=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
if position_id is not None:
|
| 211 |
+
req = ProtoOAClosePositionReq()
|
| 212 |
+
req.ctidTraderAccountId = int(account_id)
|
| 213 |
req.positionId = int(position_id)
|
| 214 |
+
req.volume = int(volume)
|
| 215 |
+
send_proto_message(ssl_sock, req, 2111)
|
| 216 |
+
else:
|
| 217 |
+
req = ProtoOANewOrderReq()
|
| 218 |
+
req.ctidTraderAccountId = int(account_id)
|
| 219 |
+
req.symbolId = int(symbol_id)
|
| 220 |
+
req.orderType = ProtoOAOrderType.MARKET
|
| 221 |
+
req.tradeSide = trade_side
|
| 222 |
+
req.volume = int(volume)
|
| 223 |
+
send_proto_message(ssl_sock, req, 2206)
|
| 224 |
|
| 225 |
while True:
|
| 226 |
proto_msg = receive_proto_message(ssl_sock)
|