นี่คือ API ที่ใช้ Pyhton โดยใช้ซีลีเนียมและขอให้รับข้อมูลจากแพลตฟอร์มการซื้อขาย 212 โปรดทราบว่าตัวเองหรือการซื้อขาย 212 รับผิดชอบต่อผลลัพธ์ที่เกี่ยวข้องกับการใช้ API นี้
ฉันจะทำงานต่อไปในโครงการนี้และจะนำความคิดเห็นใด ๆ มาใช้
PIP ติดตั้ง apit212
ในการเริ่มใช้ API นี้คุณจะต้องเข้าสู่บัญชีก่อนโดยใช้ APIT212 จากนั้นคุณจะสามารถใช้ฟังก์ชั่นทั้งหมดและสร้างบอทการซื้อขายของคุณเองหรือใช้กับข้อมูล scarpe จากแพลตฟอร์มการซื้อขาย 212
from apit212 import *
api = Apit212 ()
api . setup ( username = "[email protected]" , password = "pass******" , mode = "demo" )
from apit212 import *
api = Apit212 ()
api . setup ( username = "[email protected]" , password = "pass******" , mode = "live" )
เป็นวิธีปฏิบัติที่ดีในการตั้งค่าไฟล์ Env เพื่อบันทึกข้อมูลที่ละเอียดอ่อนเช่นชื่อผู้ใช้หรือรหัสผ่านของคุณ นี่คือลิงค์ที่มีประโยชน์
USER = [email protected]
PASS = password123
from dotenv import load_dotenv
from apit212 import *
import os
load_dotenv ( '.env' )
username : str = os . getenv ( 'USER' )
password : str = os . getenv ( 'PASS' )
api = Apit212 ()
api . setup ( username = "[email protected]" , password = "pass******" , mode = "demo" )
API นี้ไร้ประโยชน์หากไม่มีสัญลักษณ์ทิกเกอร์ที่ถูกต้องดังนั้นฉันจึงมีวิธีแก้ปัญหา
from apit212 import Tickers
ticker = Tickers ()
print ( ticker . fetch_symbols ( symbol = 'META' ))
print ( ticker . find_by_name ( full_name = 'tesla' ))
มีข้อมูลค่อนข้างน้อยที่จะอ่าน แต่คีย์ที่คุณเป็นหลังจากนั้นคือ ticker สิ่งนี้จะส่งคืนสัญลักษณ์ที่ใช้โดยแพลตฟอร์มการซื้อขาย 212
[{ ' ticker ' : ' FB ' , ' type ' : ' STOCK ' , ' currency ' : ' USD ' , ' shortName ' : ' META ' , ' fullName ' : ' Meta Platforms ' , ' description ' : ' Meta Platforms Inc ' , ' minTrade ' : 0.1, ' digitsPrecision ' : 2, ' exchangeId ' : 68, ' tradable ' : True, ' underlyingInstrumentTicker ' : ' FB_US_EQ ' , ' underlyingLeverageCoefficient ' : 1.0, ' dealerExclusions ' : [], ' maxOpenLong ' : 1121, ' leverage ' : ' 1:5 ' , ' insignificantDigits ' : 0, ' baseTicker ' : nan, ' expiryDate ' : nan, ' minTradeSizeCoefficient ' : 10.0, ' isin ' : ' US30303M1027 ' , ' countryOfOrigin ' : ' US ' , ' quantityPrecision ' : 1.0, ' priorityIndex ' : 25.0, ' maxTrade ' : nan, ' conditionalVisibility ' : nan, ' suspended ' : nan}]
[{ ' ticker ' : ' TSLA ' , ' type ' : ' STOCK ' , ' currency ' : ' USD ' , ' shortName ' : ' TSLA ' , ' fullName ' : ' Tesla ' , ' description ' : ' Tesla, Inc. ' , ' minTrade ' : 0.1, ' digitsPrecision ' : 2, ' exchangeId ' : 68, ' tradable ' : True, ' underlyingInstrumentTicker ' : ' TSLA_US_EQ ' , ' underlyingLeverageCoefficient ' : 1.0, ' dealerExclusions ' : [], ' maxOpenLong ' : 1405, ' leverage ' : ' 1:5 ' , ' insignificantDigits ' : 0, ' baseTicker ' : nan, ' expiryDate ' : nan, ' minTradeSizeCoefficient ' : 10.0, ' isin ' : ' US88160R1014 ' , ' countryOfOrigin ' : ' US ' , ' quantityPrecision ' : 1.0, ' priorityIndex ' : 100.0, ' maxTrade ' : nan, ' conditionalVisibility ' : nan, ' suspended ' : nan}]
from apit212 import Tickers
ticker = Tickers ()
meta = ticker . fetch_symbols ( symbol = 'META' )
print ( len ( meta ))
print ( meta [ 0 ][ 'ticker' ])
การค้นหาทิกเกอร์โดยใช้ทิกเกอร์ที่ใช้กันอย่างแพร่หลายมักจะส่งคืนผลลัพธ์ 1 ครั้ง แต่ในบางโอกาสคุณอาจได้ผลลัพธ์หลายอย่างดังนั้นการปฏิบัติที่ดีในการตรวจสอบเลนส์ของสตริงที่ส่งคืน
1
FB
เพื่อแลกเปลี่ยน CFD เพียงแค่เรียกคลาส CFD
from apit212 import *
api = Apit212 ()
api . setup ( username = "[email protected]" , password = "pass******" , mode = "demo" )
cfd = CFD ( cred = api )
เพื่อซื้อขายหุ้นของผู้ถือหุ้น
from apit212 import *
client = Apit212 ( username = "[email protected]" , password = "pass******" , mode = "live" )
equity = Equity ()
ฟังก์ชั่น auth_validate จะส่งคืนรหัสบัญชีและประเภทการค้า
validate = cfd . auth_validate ()
print ( validate )
{ ' id ' : ' *******-****-****-****-************ ' , ' accountId ' : ******** , ' customerId ' : ********* , ' tradingType ' : ' CFD ' , ' customerUuid ' : ' ********-****-****-****-************ ' , ' frontend ' : ' WC4 ' , ' readyToTrade ' : True, ' deviceUuid ' : ' ' }
ฟังก์ชั่น get_account จะส่งคืนรายละเอียดบัญชีของคุณ
account = cfd . get_account ()
print ( account )
{ ' demoAccounts ' : [{ ' id ' : ******** , ' type ' : ' DEMO ' , ' tradingType ' : ' CFD ' , ' customerId ' : ******** ,
' createdDate ' : ' 2023-01-17T03:20:48.000+00:00 ' , ' status ' : ' ACTIVE ' , ' registerSource ' : ' WC4 ' ,
' currencyCode ' : ' GBP ' , ' readyToTrade ' : True}], ' liveAccounts ' : [{ ' id ' : ******** , ' type ' : ' LIVE ' ,
' tradingType ' : ' CFD ' , ' customerId ' : ******** , ' createdDate ' : ' 2023-01-17T03:20:32.000+00:00 ' ,
' status ' : ' PENDING_ACTIVATION ' , ' registerSource ' : ' WC4 ' , ' currencyCode ' : ' GBP ' , ' readyToTrade ' : False}]}
ฟังก์ชั่น get_funds จะส่งคืนกองทุนบัญชี
funds = cfd . get_funds ()
print ( funds )
{ ' ******* ' : { ' accountId ' : ******** , ' tradingType ' : ' CFD ' , ' currency ' : ' GBP ' ,
' freeForWithdraw ' : 486.83, ' freeForCfdTransfer ' : 0, ' total ' : 486.83,
' lockedCash ' : { ' totalLockedCash ' : 0, ' lockedCash ' : []}}}
get_summary ส่งคืนบัญชีสรุปของคุณ
summary = cfd . get_summary ()
print ( summary )
' open ' : { ' unfilteredCount ' : 1, ' items ' : [{ ' positionId ' : ' ********-****-****-****-************ ' , ' humanId ' : ' ******** ' ,
' created ' : ' 2023-07-03T18:17:46.563+03:00 ' , ' averagePrice ' : 192.25, ' averagePriceConverted ' : 150.73025341182984,
' currentPrice ' : 192.2, ' value ' : 1054.82, ' investment ' : 1055.11, ' code ' : ' AAPL ' , ' margin ' : 212.02, ' ppl ' : -0.28,
' quantity ' : 7, ' maxBuy ' : 9.0, ' maxSell ' : 7, ' maxOpenBuy ' : 2033.0, ' maxOpenSell ' : 2040.0, ' swap ' : -1.06, ' frontend ' : ' WC4 ' }]}
GET_COMPANIES ส่งคืนเครื่องมือที่มีความสามารถในการซื้อขายบนแพลตฟอร์มการซื้อขาย 212
companies = cfd . get_companies ()
print ( companies )
[{ ' ticker ' : ' SIGTl_EQ ' , ' isin ' : ' GB0008769993 ' }, { ' ticker ' : ' PDYPY_US_EQ ' , ' isin ' : ' US3440441026 ' }...]
get_instruments_info จะส่งคืนข้อมูลเกี่ยวกับเครื่องมือ
info = cfd . get_instruments_info ( instrument = "TSLA" )
print ( info )
{ ' code ' : ' TSLA ' , ' type ' : ' STOCK ' , ' margin ' : 0.2, ' shortPositionSwap ' : -0.07030593058663,
' longPositionSwap ' : -0.27928156941337, ' tsSwapCharges ' : ' 1970-01-01T23:00:00.000+02:00 ' ,
' marginPercent ' : ' 20 ' , ' leverage ' : ' 1:5 ' }
GET_ORDOR_INFO รับ
orderInfo = cfd . get_order_info ( instrument = "TSLA" , quamtity = 1.5 )
print ( orderInfo )
{ ' buyMargin ' : 40.18, ' sellMargin ' : 40.18, ' buySwap ' : -0.2, ' sellSwap ' : -0.05}
tickers = [ "TSLA" , "AAPL" ]
deviation = cfd . get_deviations ( instruments = tickers )
print ( deviation )
[{ ' request ' : { ' ticker ' : ' TSLA ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1694073610000, ' price ' : 250.68, ' period ' : ' d1 ' }}, { ' request ' : { ' ticker ' : ' AAPL ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1694073610000, ' price ' : 178.18, ' period ' : ' d1 ' }}]
get_position ส่งคืนข้อมูลสำหรับรหัสตำแหน่งที่กำหนด ID นี้สามารถถูกส่งออกจากฟังก์ชัน get_summary
position = cfd . get_position ( position_id = 274187113 )
print ( position )
[{ ' eventType ' : { ' action ' : ' opened ' , ' source ' : ' MARKET_ORDER ' },
' eventNumber ' : { ' name ' : ' MO3053019640 ' , ' id ' : ' 274187113 ' , ' frontend ' : ' WC4 ' }, ' time ' : ' 2023-08-02T22:42:54.000+03:00 ' ,
' direction ' : ' sell ' , ' quantity ' : 1.0, ' price ' : ' 105.29 ' , ' avgQuantity ' : 1.0, ' avgPrice ' : ' 105.2900 ' , ' modifiedDirection ' :
' sell ' }]
ฟังก์ชั่น get_all_result จะส่งคืนรายการผลการซื้อขายทั้งหมดของคุณ คุณจะต้องขอแต่ละหน้า คุณอาจต้องผ่านเขตเวลาของคุณ
results = cfd . get_all_results ()
print ( results )
{ ' data ' : [{ ' direction ' : ' buy ' , ' code ' : ' AAPL ' , ' quantity ' : 0.1, ' orderNumber ' : { ' name ' : ' P************ ' , ' link ' : ' positionHistory/********-****-****-****-************ ' , ' id ' : ' ********-****-****-****-************ ' , ' frontend ' : ' WC4 ' }, ' price ' : ' 176.6700 ' , ' closePrice ' : ' 181.98 ' , ' result ' : ' 0.42 ' , ' eventNumber ' : { ' name ' : ' PO3062546222 ' , ' id ' : ' ********-****-****-****-************ ' }, ' eventType ' : ' closed ' , ' time ' : ' 2023-08-29T17:15:55.000+03:00 ' , ' openingTime ' : ' 2023-08-25T11:51:15.000+03:00 ' }, ...], ' nextPage ' : ' result?perPage=20&onlyFullyClosed=false&page=2 ' , ' currentPage ' : ' result?perPage=20&onlyFullyClosed=false&page=1 ' , ' totalSize ' : 133}
orderHist = cfd . get_order_hist ( page_number = 1 )
print ( orderHist )
{ ' data ' : [], ' currentPage ' : ' order?filter=all&perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1 ' , ' totalSize ' : 0}
positionHist = cfd . get_posistion_hist ( page_number = 1 )
print ( positionHist )
{ ' data ' : [], ' currentPage ' : ' position?perPage=20&from=2023-09-06T02:00:00.000+03:00&to=2023-09-08T01:59:59.173+03:00&page=1 ' , ' totalSize ' : 0}
FAST_PRICE กลับราคาตราสารเป็นลอย หากคำขอไม่ถูกส่งคืน
price = cfd . fast_price ( instrument = "TSLA" )
print ( price )
253.49
Chart_data ส่งคืนพจนานุกรมด้วยวันที่เทียน OHLC (เปิด, สูง, ต่ำ, ปิด) ระยะเวลาที่ร้องขอ ซึ่งตั้งค่าเป็น 1 นาทีโดยค่าเริ่มต้น
charts = cfd . chart_data ( instrument = "TSLA" , period = "ONE_MINUTE" )
print ( charts )
[{ ' request ' : { ' ticker ' : ' TSLA ' , ' period ' : ' ONE_MINUTE ' , ' size ' : 500, ' useAskPrice ' : False}, ' response ' : { ' candles ' : [[1691152740000, 259.6, 259.97, 259.43, 259.49, 47], [1691152800000, 259.38, 259.94, 259.17, 259.56, 58], [1691152860000, 259.62, 260.34, 259.62, 260.19, 42]
ฟังก์ชั่น multi_price จะส่งคืนราคา Qouted ล่าสุดสำหรับเครื่องมือที่ผ่านทั้งหมด
tickers = [ "TSLA" , "AAPL" , "GOOG" ]
multiprice = cfd . multi_price ( instruments = tickers )
print ( multiprice )
[{ ' ticker ' : ' TSLA ' , ' price ' : 251.34}, { ' ticker ' : ' AAPL ' , ' price ' : 181.96}, { ' ticker ' : ' GOOG ' , ' price ' : 135.18}]
ฟังก์ชั่น Market_order ส่งคำสั่งซื้อของตลาดและต้องการราคาปัจจุบันของตราสาร
targetPrice = cfd . fast_price ( instrument = "TSLA" )
marketOrder = cfd . market_order ( instrument = "TSLA" , target_price = targePrice ,
quantity = 1.5 , take_profit = 10 , stop_loss = 10 )
ฟังก์ชั่ น Limit_order
marketOrder = cfd . limit_order ( instrument = "TSLA" , target_price = 127 ,
quantity = 1.5 , take_profit = 10 , stop_loss = 10 )
ฟังก์ชั่น set_limits ช่วยให้คุณสามารถแก้ไขหรือเพิ่ม stoploss หรือ takeprofit ลงในตำแหน่งที่มีอยู่ (ตำแหน่งตัวกำหนดจำเป็นต้องใช้ฟังก์ชันนี้)
limits = cfd . set_limits ( position_id = 27361748 , TP = 10 , SL = 10 )
ฟังก์ชั่น add_trailing_stop เพิ่มการหยุดต่อท้ายไปยังตำแหน่งที่มีอยู่
trailing = cfd . add_trailing_stop ( position_id = 27361748 , distance = 1 )
ฟังก์ชั่น close_position ใช้เพื่อปิดตำแหน่งเปิด มันจะต้องใช้ราคาปัจจุบัน
currentPrice = cfd . fast_price ( instrument = "TSLA" )
close = cfd . close_position ( position_id = 23948174 , current_price = currentPrice )
cancelAll = cfd . cancel_all_orders ()
ฟังก์ ชั่น cancel_order ใช้เพื่อยกเลิกคำสั่ง จำกัด
cancel = cfd . cancel_order ( order_id = ** ** ** ** ** )
ฟังก์ชั่น get_live จะส่งคืนราคาปัจจุบันของ ticker
tickers = [ "TSLA" , "AAPL" ]
prices = cfd . live_price ( instruments = tickers )
print ( prices )
[{ ' request ' : { ' ticker ' : ' TSLA ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1690531210000, ' price ' : 255.8, ' period ' : ' d1 ' }}, { ' request ' : { ' ticker ' : ' AAPL ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1690531210000, ' price ' : 193.29, ' period ' : ' d1 ' }}]
ฟังก์ชั่น get_funds จะส่งคืนเงินในบัญชีของคุณ
funds = cfd . get_funds ()
print ( funds )
{ ' 20434246 ' : { ' accountId ' : ******** , ' tradingType ' : ' CFD ' , ' currency ' : ' GBP ' ,
' freeForWithdraw ' : 486.83, ' freeForCfdTransfer ' : 0, ' total ' : 486.83,
' lockedCash ' : { ' totalLockedCash ' : 0, ' lockedCash ' : []}}}
ฟังก์ชั่น trailing_stop ช่วยให้คุณสามารถเพิ่มจุดหยุดต่อท้ายไปยังตำแหน่งที่เปิดได้
trailing_stop = cfd . trailing_stop ( position_id = "***-****-***" , distance = 0.5 )
ฟังก์ชั่น add_limits ช่วยให้คุณเพิ่ม stoploss และ takeprofit ไปยังตำแหน่งที่มีอยู่
update_limits = client . add_limits ( position_id = "***-****-***" , TP = 1 , SL = 1 )
ในการตั้งค่า stoploss ใหม่หรือ takeprofit เพียงผ่านระยะทางไปยังพารามิเตอร์ TP (ทำกำไร) หรือ SL (หยุดขาดทุน) ฟังก์ชั่นจะได้รับราคาปัจจุบันและใช้ระยะทาง
ฟังก์ชั่น all_position_hist จะส่งคืนประวัติตำแหน่ง
position_history = cfd . all_position_hist ()
ข้อมูลคำสั่งซื้อ all_order_hist
order_history = cfd . all_order_hist ()
ฟังก์ชั่น get_instrument จะ retunr ข้อมูลเกี่ยวกับเครื่องมือ
tsla_info = cfd . get_instruments_info ( instrument = 'TSLA' )
print ( tsla_info )
{ ' code ' : ' TSLA ' , ' type ' : ' STOCK ' , ' margin ' : 0.2, ' shortPositionSwap ' : -0.07030593058663,
' longPositionSwap ' : -0.27928156941337, ' tsSwapCharges ' : ' 1970-01-01T23:00:00.000+02:00 ' ,
' marginPercent ' : ' 20 ' , ' leverage ' : ' 1:5 ' }
ฟังก์ชั่น get_position จะส่งคืนข้อมูลสำหรับ qouted positionId
position = cfd . get_position ( position_id = "***-****-***" )
print ( position )
[{ ' eventType ' : { ' action ' : ' opened ' , ' source ' : ' MARKET_ORDER ' },
' eventNumber ' : { ' name ' : ' MO3053019640 ' , ' id ' : ' 274187113 ' , ' frontend ' : ' WC4 ' }, ' time ' : ' 2023-08-02T22:42:54.000+03:00 ' ,
' direction ' : ' sell ' , ' quantity ' : 1.0, ' price ' : ' 105.29 ' , ' avgQuantity ' : 1.0, ' avgPrice ' : ' 105.2900 ' , ' modifiedDirection ' :
' sell ' }]
ฟังก์ชั่น get_summary จะส่งคืนสรุปบัญชี ฟังก์ชั่นนี้สามารถใช้เพื่อรับ ID คำสั่งซื้อและมี ppl ปัจจุบัน
summary = cfd . get_summary ()
print ( summary )
' open ' : { ' unfilteredCount ' : 1, ' items ' : [{ ' positionId ' : ' ********-****-****-****-************ ' , ' humanId ' : ' ******** ' ,
' created ' : ' 2023-07-03T18:17:46.563+03:00 ' , ' averagePrice ' : 192.25, ' averagePriceConverted ' : 150.73025341182984,
' currentPrice ' : 192.2, ' value ' : 1054.82, ' investment ' : 1055.11, ' code ' : ' AAPL ' , ' margin ' : 212.02, ' ppl ' : -0.28,
' quantity ' : 7, ' maxBuy ' : 9.0, ' maxSell ' : 7, ' maxOpenBuy ' : 2033.0, ' maxOpenSell ' : 2040.0, ' swap ' : -1.06, ' frontend ' : ' WC4 ' }]}
ฟังก์ชั่น live_price จะส่งคืนราคาถามปัจจุบันสำหรับเครื่องมือที่ผ่าน
ticker = [ "TSLA" , "AAPL" , "GOOG" ]
live_price = cfd . live_price ( instruments = ticker )
print ( live_price )
[{ ' ticker ' : ' TSLA ' , ' price ' : 253.49}, { ' ticker ' : ' AAPL ' , ' price ' : 182.08}, { ' ticker ' : ' GOOG ' , ' price ' : 128.44}]
ฟังก์ชั่น FAST_PRICE จะส่งคืนราคาแผนภูมิ QOUTED ล่าสุดเป็นลอย
price = cfd . fast_price ( instrument = "TSLA" )
print ( price )
253.49
ฟังก์ชั่น Chart_Data จะส่งคืนข้อมูลแผนภูมิล่าสุดสำหรับเครื่องมือที่ผ่าน
chart = cfd . chart_data ( instrument = "TSLA" )
print ( chart )
[{ ' request ' : { ' ticker ' : ' TSLA ' , ' period ' : ' ONE_MINUTE ' , ' size ' : 500, ' useAskPrice ' : False}, ' response ' : { ' candles ' : [[1691152740000, 259.6, 259.97, 259.43, 259.49, 47], [1691152800000, 259.38, 259.94, 259.17, 259.56, 58], [1691152860000, 259.62, 260.34, 259.62, 260.19, 42]
ฟังก์ชั่น get_deviations จะส่งคืนการเบี่ยงเบนราคา
ticker = [ "TSLA" , "AAPL" , "GOOG" ]
deviations = cfd . get_deviations ( instruments = ticker )
print ( deviations )
[{ ' request ' : { ' ticker ' : ' TSLA ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1691136010000, ' price ' : 259.38, ' period ' : ' d1 ' }}, { ' request ' : { ' ticker ' : ' AAPL ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1691136010000, ' price ' : 188.99, ' period ' : ' d1 ' }}, { ' request ' : { ' ticker ' : ' GOOG ' , ' useAskPrice ' : False}, ' response ' : { ' timestamp ' : 1691136010000, ' price ' : 129.05, ' period ' : ' d1 ' }}]
ฟังก์ชั่น GET_COMPANIES จะส่งคืน บริษัท ในปัจจุบันใน T212 และ ISIN ID ที่เกี่ยวข้อง
companies = cfd . get_companies ()
print ( companies )
[{ ' ticker ' : ' SIGTl_EQ ' , ' isin ' : ' GB0008769993 ' }, { ' ticker ' : ' PDYPY_US_EQ ' , ' isin ' : ' US3440441026 ' }...]
ฟังก์ชั่น limit_order ส่งคำสั่ง จำกัด และใช้ปริมาณ, target_price, take_profit & stop_loss parms
limit_order = cfd . limit_order ( instrument = "TSLA" ,
quantity = 5 , target_price = 129 , take_profit = 130 , stop_loss = 128 )
{'account': {'dealer': 'AVUSUK', 'positions': [{'positionId': '********-****-****-****-************',
'humanId': '**********', 'created': '2023-07-03T18:17:46.563+03:00' ...
ฟังก์ชั่น Market_order ส่งคำสั่งซื้อของตลาดและใช้ปริมาณ, target_price, take_profit & stop_loss parms
market_order = cfd . market_order ( instrument = "TSLA" ,
quantity = 5 , target_price = 129 , take_profit = 130 , stop_loss = 128 )
ฟังก์ชั่น cancel_order จะยกเลิกคำสั่งซื้อที่ค้างอยู่ซึ่งต้องใช้ orderId
cancel_order = cfd . cancel_order ( order_id )
นอกจากนี้คุณยังสามารถใช้ cancel_all_orders เพื่อยกเลิกคำสั่งซื้อที่ค้างอยู่ทั้งหมด
cancel_all = cfd . cancel_all_orders ()
ฟังก์ชั่น close_position จะส่งคำขอเพื่อยกเลิกตำแหน่งเปิด
close_position = cfd . close_position ( position_id = 'ordexxxxx' , current_price = current_price )
username = "[email protected]"
password = "password132"
api = Apit212 ()
api . setup ( username = username , password = password , mode = "demo" )
cfd = CFD ( cred = api )
target_price = 128
while True :
sleep ( 60 )
price = cfd . fast_price ( "TSLA" )
if price <= target_price :
marketOrder = cfd . market_order ( instrument = "TSLA" , target_price = price , quantity = 1 , take_profit = 10 ,
stop_loss = 10 )
break
เมื่อทำการค้าขายคุณอาจพบปัญหาและเป็นเรื่องดีเสมอที่จะมีโปรโตคอลในการจัดการกับปัญหาเหล่านี้เมื่อเกิดขึ้น
ด้านล่างเป็นรายการของข้อยกเว้น บางอย่าง ที่คุณอาจเจอเมื่อทำการค้าขาย
เพียงแค่หยุดการร้องขอหากคุณได้รับคำตอบนี้
ขณะนี้ทำงานกับบัญชีผู้ถือหุ้นเท่านั้นและคุณสามารถส่งการซื้อขายในบัญชีสาธิตของคุณเท่านั้น โปรดอ่านเอกสารอย่างเป็นทางการเพื่อรับความเข้าใจและข้อ จำกัด ของ API ที่ดีขึ้น
ในการใช้ API อย่างเป็นทางการคุณจะต้องสร้างคีย์โดยใช้แอพ Trading212 /การตั้งค่า/API (เบต้า) จากนั้นเพียงสร้างคีย์ใหม่และส่งผ่านไปยังคลาส APITKEY (). Equity ()
from apit212 import *
key = "20557******************************"
client = Apitkey ()
info = client . Equity ( api_key = key , mode = "live" )
นี่คือฟังก์ชั่นที่สามารถใช้งานได้โดยใช้ TRADING212 API-TOKEN
นี่คือ API ที่ไม่เป็นทางการและตัวฉันเองของการซื้อขาย 212 มีหน้าที่รับผิดชอบในการใช้ API นี้ ขอแนะนำอย่างยิ่งให้คุณใช้บัญชีฝึกซ้อมก่อนที่จะย้ายไปที่เงินจริง APIT212 ไม่ใช่ บอทการซื้อขาย