Closed blackchestnut closed 1 year ago
client.share_by id_type: InvestTinkoff::V2::InstrumentIdType::TICKER, id: 'MAC', class_code: 'SPBXM'
a. Пример для сигнала:
b. client.share_by id_type: InvestTinkoff::V2::InstrumentIdType::TICKER, id: s.symbol.name, class_code: 'SPBXM'
client.order_book(figi: 'BBG000BL9C59', depth: 1).payload['bids'][0]
client.create_order account_id: '20000xxxxx', figi: 'BBG000BL9C59', quantity: 1, price: 11.35, direction: InvestTinkoff::V2::OrderDirection::BUY, order_type: InvestTinkoff:: V2::OrderType::LIMIT, order_id: s.id.to_s
Чтобы проверить, что с ордером:
client.order_state account_id: '20000xxxxx', order_id: '422315101350'
# =>
{"orderId"=>"422315101350",
"executionReportStatus"=>"EXECUTION_REPORT_STATUS_NEW",
"lotsRequested"=>"1",
"lotsExecuted"=>"0",
"initialOrderPrice"=>{"currency"=>"usd", "units"=>"11", "nano"=>350000000},
"executedOrderPrice"=>{"currency"=>"usd", "units"=>"0", "nano"=>0},
"totalOrderAmount"=>{"currency"=>"usd", "units"=>"11", "nano"=>350000000},
"averagePositionPrice"=>{"currency"=>"usd", "units"=>"0", "nano"=>0},
"initialCommission"=>{"currency"=>"usd", "units"=>"0", "nano"=>10000000},
"executedCommission"=>{"currency"=>"usd", "units"=>"0", "nano"=>0},
"figi"=>"BBG000BL9C59",
"direction"=>"ORDER_DIRECTION_BUY",
"initialSecurityPrice"=>{"currency"=>"usd", "units"=>"11", "nano"=>350000000},
"stages"=>[],
"serviceCommission"=>{"currency"=>"rub", "units"=>"0", "nano"=>0},
"currency"=>"USD",
"orderType"=>"ORDER_TYPE_LIMIT",
"orderDate"=>"2022-06-06T20:27:16.804920Z"}
Проверка исполнения ордера:
r = client.order_state account_id: '20000xxxxx', order_id: '422315101350'
r.payload['lotsRequested'] == r.payload['lotsExecuted']
Отмена ордера:
client.cancel_order account_id: '20000xxxx', order_id: '422315101350'
# => #<struct InvestTinkoff::V2::Response payload={"time"=>"2022-06-06T17:56:26.710960Z"}, http_code=200>
[x] create TP with notification (на основе данных в executedCommission из состояния ордера)
Для закрытия открытых ордеров можно использовать вот это (пример):