Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

Программирование

Abaawadde amagezi okukola empeereza y’eby’emiwendo mu kkampuni ya Tinkoff Investments be bano:

Kiki ekigenda okuteesebwako?

  • Ekitundu ekikozesebwa kyokka ekikwata ku nkulaakulana.
  • Okumanya n’obumanyirivu obw’amazima, ebikulu ennyo mu kukola n’ebikozesebwa mu by’ensimbi.
  • Okulaba ensonga ezirina okukolebwako

Kale, njagala okubala ebibalo by’ebyobusuubuzi n’okukikola mu ngeri ennyangu. 

Okukola empeereza y’ebibalo mutendera ku mutendera: 

  1. Okuyungibwa ku Tinkoff Invest API
  2. Okukuba data okuva mu Tinkoff Invest API mu browser
  3. Okufuna lipoota za brokerage n’okutunda ebintu
  4. Okubala n’okufulumya amawulire agakwata ku nsonga
  5. Ebimalirizibwa n’enteekateeka z’ebiseera eby’omu maaso

Okuyungibwa ku Tinkoff Invest API

Okuyungibwa ku API, osobola okutwala sdk yonna okuva mu biwandiiko https://github.com/Tinkoff/investAPI#sdk . Oba ekipapula kya npm ` tinkoff-sdk-grpc-js `. Kikulu nti package eno etereezebwa okutuuka ku nkyusa eyasembyeyo okuva mu bakola. Okuzimba

npm nze nkuba-sdk-grpc-js

Okukebera

const { okutondaSdk } = kyetaagisa (‘tinkoff-sdk-grpc-js’);   // Akabonero akayinza okufunibwa nga kano  const TOKEN = ‘YOURAPI’;   // Erinnya ly’enkola gy’osobola okusangibwa mu biwandiiko bya TCS. const Erinnya ly’enkola = ‘tcsstat’;   const sdk = okukolaSdk (TOKEN, Erinnya ly’okukozesa); (async () => {     console.log (linda sdk.abakozesa.funaAccounts ()); }) ();

Ekivaamu: olukalala lwa akawunti zo lujja kulagibwa mu console. Okugeza, ka twekenneenye ebigambo ebitonotono:Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

  • Mu lukalala lwa akawunti mulimu “Investment bank”, gy’otosobola kukola nayo ng’okozesa API
  • Nsaba omanye nti ennimiro zijja mu camelCase, ate mu biwandiiko ennimiro zino ziragiddwa mu under_score. 
  • Kijja kuba bwe kiti buli wamu, kale tosobola kumala gatwala n’okukoppa ennimiro okuva mu biwandiiko.

A mugaso:

  • Koodi eno osobola okugisanga mu ttabi lya pulojekiti

https://github.com/pskucherov/tcsstat/omuti/omutendera1 https://github.com/pskucherov/tcsstat/geraageranya/omutendera1   

Okukuba data okuva mu Tinkoff Invest API mu browser

Nakwata next.js ne socket.io. Kino si kuteesa kwa maanyi, londa nga bw’oyagala. 

npx tonda-ekiddako-app@ekisembayo npm i socket.io socket.io-kasitoma

Amangu ago tweyongerayo ku mutendera gw’omukwano oguddako+socket+investapi, era laba ekitundu eky’Omugaso mu mutendera guno okumanya ebisingawo byonna.  Nja kunnyonnyola ebisingawo: 

  • Ku ludda lwa nodejs (server), waliwo fayiro ya pages/api/investapi.js. Wano we tukola socket.io server ne tuyungibwa ku investapi.
  • Ku ludda lwa browser (client), tuyungibwa ku server nga tuyita mu socket ne tusaba data ya account okuva ku broker. 
  • Tufuna data okuva ku broker ku server, olwo ne tugisindika eri client. Bwe zifunibwa ku kasitoma, ziragibwa mu browser. 

Ekivaamu:  mu browser console tusobola okulaba amawulire agakwata ku accounts. Kwe kugamba, mu mutendera ogusembayo, twalaba amawulire agakwata ku akawunti mu server console (nodejs), mu mutendera oguliwo kati, twakyusa amawulire gano eri kasitoma (browser).

Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

Kati katukikole osobole okulonda akawunti okuva mu browser, era bwe waba tewali token, olwo ensobi esindikibwa ku console. Omulimu mwangu era tewali kipya, kale mpa links zokka ku commits

  1. https://github.com/pskucherov/tcsstat/commit/7e1ac57061e5e971588479015b06d8814d6609a9
  2. https://github.com/pskucherov/tcsstat/commit/b28ac973a57494f5232589b4cb6b9fb13b8af759 

A mugaso:

  • Engeri y’okukolamu emikwano ekiddako ne socket eyogerwako mu bujjuvu wano
  • Koodi y’omukwano eddako+socket+investapi:

https://github.com/pskucherov/tcsstat/commit/a443a4ac1bb4f0aa898f638128755fe7391ee381 Ku abo ebyo waggulu bizibu, olwo tusigala ku mutendera guno ne tukola ku koodi. Bwoba olina ebibuuzo – buuza. https://github.com/pskucherov/tcsstat/omuti/omutendera2 https://github.com/pskucherov/tcsstat/geraageranya/omutendera1…omutendera2

Okufuna lipoota za brokerage n’okutunda ebintu

Waliwo enkola ssatu ez’okufuna lipoota za brokerage n’okutunda ebintu

  1. FunaAlipoota ya Broker
  2. FunaDividendsOmufulumya Omugwira
  3. GetEmirimuByCursor

Okuva ku ntandikwa kikulu okumanya: 

  • Lipoota ya brokerage ekolebwa mu mbeera ya T-3, i.e. eby’obusuubuzi byolesebwa eyo oluvannyuma lw’okubituukiriza ddala. 
  • Okusinziira ku kino, singa osaba lipoota eno okumala ennaku bbiri ezisembyeyo, ejja kuba ewedde mu nnaku ssatu. 
  • Okukola ddiiru z’ennaku ezisembayo, tukozesa enkola y’okufuna emirimu, naye jjukira nti id yazo n’ebirimu biyinza okukyuka oluvannyuma lw’okutondebwawo kwa lipoota ya brokerage.

FunaAlipoota ya Broker

Okufuna lipoota ya brokerage, olina okutwala account id, olunaku lw’okutandika n’olunaku lw’okuggwaako lipoota, naye nga tezisukka nnaku 31. Tusindika okusaba okukola lipoota eri API mu kukola _broker_report_request , okufuna taskId mu kuddamu. Oluvannyuma lw’ekyo, nga tukozesa taskId eno, tufuna data okuva mu get _broker_report_response.

Kale ebiwandiiko bigamba nti, mu butuufu waliwo nuances. Laba emikono gyo:

  • Olina okutereka TaskID emirembe gyonna ddala ku nnaku zino. 
  • Okuva bwe kiri nti bw’ogifiirwa, olwo ku nnaku ezisabiddwa lipoota ejja kusooka kujja ng’eyanukula okusaba kw’omulembe, . 
  • Era awo tekijja kujja n’akatono.

Ka tutandike okuwandiika code

Enkola y’okufuna olunaku, ng’otunuulidde okuggyako okuva ku lunaku oluliwo

const getDateSubDay = (Olunaku olutono = 5, okutandika = kituufu) => {     const olunaku = Olunaku olupya ();     olunaku.setUTCDate (olunaku.getUTCDate () – Olunaku olutono);       bwe kiba (okutandika) {         olunaku.setUTCHours (0, 0, 0, 0);     } else {         olunaku.setUTCHours (23, 59, 59, 999);     }       olunaku lw’okudda; };

Okusaba okukola lipoota 

const brokerReport = linda (sdk.operations.getBrokerReport) ({         okukolaOkusabaAlipoota ya Broker: {             accountId,             okuva,             okutuuka,         }, });

Alizaati:

  • Nga ekiva mu kukola ekiragiro ekisooka, tufuna taskId. 
  • Lipoota etandika okukolebwa ku ludda lwa broker. Bwe kiba nga kyetegefu tekimanyiddwa, tulinda era buli luvannyuma lwa kiseera tusika taskId nga tusuubira lipoota.
  • Lwaaki? Kubanga lipoota bw’eba tetegekeddwa, esuula ensobi. Singa lipoota teba yeetegese ku ludda lwa broker, olwo eno nsobi mu code yo. Nsaba okole: 30058|INVALID_ARGUMENT|omulimu tegunnaggwa, nsaba ogezeeko nate oluvannyuma

Koodi y’okulinda n’okufuna lipoota eringa bweti.

const timer = async time => {     return new Promise (okugonjoola => setTimeout (okugonjoola, obudde)); }   const getBrokerResponseByTaskId = async (taskId, olupapula = 0) => {     gezaako {         okuddamu okulinda (sdk.operations.getBrokerReport) ({             getBrokerReportRequest: {                 taskId,                 olupapula,             },         });     } okukwata (e) {         console.log (‘linda’, e);         linda ekiseera (10000);         okuddayo linda getBrokerResponseByTaskId (taskId, olupapula);     } };

Olwo obulogo bwe bumu ne bubaawo. Tuyimiriza script yaffe, tuddamu okugitandika, tetulina taskId. Tukola code n’okusaba kwa taskId, naye tetukyafuna taskId, wabula amangu ago lipoota. Obulogo! Era buli kimu kyandibadde kirungi singa bulijjo kiba bwe kiti. Naye mu mwezi gumu tewajja kubaawo data n’akatono. Omugaso : .

  • Akatono ku ndowooza kalambikiddwa wano ne wano .
  • Okuteeka code wamu, ebbago lijja kufaanana nga lino.

https://github.com/pskucherov/tcsstat/omuti/omutendera3.1 https://github.com/pskucherov/tcsstat/geraageranya/omutendera3.1

  • Singa omuntu asanga kino, olwo mwaniriziddwa ku nsonga . Oluvannyuma lw’okuddaabiriza obulogo buno, bujja kuggwaamu amaanyi era bujja kuba bwa njawulo mu ngeri emu oba endala. Naye mu kiseera kino (03/21/2023) kikola bwe kityo.

FunaDividendsOmufulumya Omugwira

Omuntu ayinza okulowooza nti enkola eno efaananako n’eyo eyasooka era osobola okukozesa enkola emu mw’okyusa erinnya ly’emirimu gyokka. Naye tebaateebereza!  Okutuuma amannya eyo kwa njawulo nnyo mu nkola ne mu mawulire agaddiziddwa. Era omuwendo gw’olupapula gutandikira ku 0, olwo okuva ku 1. Okusobola obutatabulwa mu bino byonna, kyangu okuwandiika enkola bbiri ez’enjawulo. Ekyewuunyisa, kubanga ensonga y’omulimu y’emu. Nafuuwa amalusu okumala ebbanga nga ngezaako okukola enkola emu era nga code ntono. Tewajja kubaawo byakulabirako wano.

GetEmirimuByCursor

Nze ekisinga okunnyumira ku bisatu. Wadde nga si y’esinga obutuufu, naye esinga okumala. Tukola okusaba okuva ku ntandikwa y’okukola akawunti okutuuka ku lunaku olusinga obunene (okuggalawo akawunti oba eriwo kati). Tufuna eky’okuddamu, tukwata cursor ne tuddamu okusaba kasita wabaawo data.  Era koodi eno nnyimpi nnyo okusinga mu byokulabirako waggulu.

const timer = async time => {     return new Promise (okugonjoola => setTimeout (okugonjoola, obudde)); }   const getOperationsByCursor = async (sdk, accountId, okuva, okutuuka, cursor = ”) => {     try {         const reqData = {             accountId,             okuva,             okutuuka,             ekkomo: 1000,             embeera: sdk.OperationState.OPERATION_STATE_EXECUTED,             awataliCommissions: bulimba,             withoutTrades: bulimba,             awataliOvernights: bulimba,             cursor,         };           okuddayo linda sdk.emirimu.getEmirimuByCursor (reqData);     } okukwata (e) {         linda ekiseera (60000);         okudda linda getOperationsByCursor (sdk, accountId, okuva, okutuuka, cursor = ”);     } };

Ebbago erigenda okuddukanyizibwa liri wano: https://github.com/pskucherov/tcsstat/tree/step3.3 https://github.com/pskucherov/tcsstat/compare/step3.3 Kati tuli beetegefu okwongerako emirimu gy’okufuna ku okusaba kwaffe. Bwe kiba nga kikoleddwa bulungi, olwo olina okufuna lipoota za brokerage ku kubeerawo kwonna okwa akawunti. Era ku data ebula, T-3 ezo ze zimu, ziddamu okutikka okuva mu mirimu. Naye kino kiyinza okwawulwamu ekitundu eky’enjawulo. Ku nuances enkulu z’ogenda okusanga kwe kusiiga emirimu ne lipoota ya brokerage.

  •  Bw’oba ​​leero ofunye lipoota ya brokerage n’okutunda ku nnaku ezeetaagisa, byonna biteeke mu database, olwo tewali buzibu. 
  • Ojja kufuna obuzibu enkya ng’ofunye ekitundu ekiddako ekya data okuva mu lipoota n’emirimu n’osalawo okubikwataganya ne database eriwo. 
  • A lot of nuances about mismatched oba okukyusa id oluvannyuma lw’okukola
  • Awo ku katale ka OTC, id’s tezikwatagana n’akatono.
  •  Nga kwotadde ne nuances z’ebivuga ebikwatagana, nga nate tezikwatagana, olw’enjawulo za API. Naye eyo mboozi ndala.

Ka twongere okufuna amawulire agakwata ku mirimu ku nkola yaffe. Ekibuuzo ekikulu kijja kuba wa data w’egenda okukolebwako n’okuterekebwa.

  •  Bw’okikola ku bubwo, ojja kukozesa data y’emu okuva ku byuma eby’enjawulo. Olwo olina okukola n’okutereka data ku seva.
  • Bw’oba ​​olina data nnyingi ez’enjawulo ezikozesebwa abakozesa bangi ab’enjawulo, olwo olina okusalawo ekisinga obukulu: sipiidi y’abakozesa oba okukekkereza ekyuma ku ludda lwo. Oyo yenna asobola okwesasulira omuwendo ogutaliiko kkomo ogwa hardware abala buli kimu ku server ye era n’akifuula super fast eri abakozesa, okukekkereza eby’obugagga by’abakozesa, gamba nga battery ne traffic, ekintu ekikulu ennyo ku masimu.

Mu ngeri y’emu, okubala mu browser si kye kigonjoola ekisinga obulungi mu nkola. N’olwekyo, ekitali kya bbeeyi, tukitwala ku seva yaffe. Ebisigadde tubirekera kasitoma. Njagala nnyo okutwala n’okubalirira commission ku server. Naye wano we wava nuance eyitibwa “interactivity”. Ka tugambe nti olina enkumi n’enkumi z’okulongoosebwa era kitwala eddakiika ttaano okuzifuna. Omukozesa agenda kuba na ki mu kiseera kino? Spinner? Okukulakulana? Infa ku ssente mmeka ezaateekebwa ku mukutu? Kirungi nnyo okukozesa “active waiting” ng’omukozesa mu nkola yasobola dda okulaba ekintu. Bino bye byavuddemu:Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

  • Okutikka omuko
  • Invoice zonna zisabibwa
  • Oluvannyuma lw’ekyo, emirimu gyonna egy’obusuulu ku mirimu egyakolebwa gisabibwa ku akawunti zonna. Nga data efunibwa, eweebwa mu browser.

Okusobola obutasengejja data mu bibaddewo buli mulundi, tusika ekintu kyaffe ku buli akawunti. Nga bino:

socket.emit (‘sdk: getOperationsCommissionResult_’ + accountId, {                 ebintu: data?.ebintu,                 muNkulaakulana: Boolean (ekiddakoCursor), });

Ebbago ly’okutongoza liri wano: https://github.com/pskucherov/tcsstat/tree/step3 https://github.com/pskucherov/tcsstat/geraageranya/omutendera2…omutendera3 Okugenda mu maaso. Kirungi nnyo nti osomye layini eno! 

Okubala n’okufulumya amawulire agakwata ku nsonga

Kisinziira ku ani yeetaaga amawulire ki. N’olwekyo, amangu ago nkubuulira nuances enkulu z’ogenda okusanga.

Okukola n’emiwendo 

Buli akola ne finance akimanyi nti okutunda ssente kulina kukolebwa na nnamba enzijuvu zokka. Olw’obutali butuufu bw’emiwendo oluvannyuma lw’ensonga ya decimal n’ensobi ey’okukuŋŋaanyizibwa n’omuwendo omunene ogw’emirimu. Eno y’ensonga lwaki emiwendo gyonna gyanjuddwa mu nkola ya MoneyValue eno wammangaTukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

ekisaawe okuwandiika Okunnyonnyola
sente akaguwa String Koodi y’ensimbi ya ISO
yuniti za yuniti int64 Ekitundu kya namba enzijuvu eky’omugatte, kiyinza okuba namba ya negatiivu
nano int32 Ekitundu eky’obutundutundu eky’omuwendo, kiyinza okuba namba ya negatiivu

Tuzirongoosa mu ngeri ey’enjawulo, olwo ne tuzituusa ku muwendo gw’ebbeeyi:

okujuliza.units + okujuliza.nano / 1e9

Ensimbi ezisaasaanyizibwa ku ndagaano z’ebiseera eby’omu maaso

Bbeeyi y’ebiseera eby’omu maaso elagibwa mu bubonero, bw’oba ​​olina ebiseera eby’omu maaso eby’ensimbi, olina okumanya omuwendo. Era ddala bbeeyi mu bubonero n’omutendera gw’ebbeeyi. Bw’oba ​​obala amagoba okuva mu nkolagana, kino kiyinza okukuba amasasi, kubanga. singa obala omuwendo gwonna ng’okubisaamu omuwendo n’omuwendo. Wano olina okwegendereza. Kati, tugenda kulaba bwe bigenda. Kino kikwata ku currency futures, mu bifo ebirala buli kimu kiri ok ne kino.Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions. Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

Akatale ka OTC

Akatale kano kalina bingi eby’enjawulo, kale ka tusome emirimu ku gwo okwawukana.Bw’otandika okukwataganya emirimu, kijja kuzuulibwa nti olina okuleeta figi / ticker ku ffoomu y’emu okusobola okukwatagana obulungi n’ekivuga. Bw’otandika okukwataganya kino ne lipoota ya brokerage, kijja kuzuulibwa nti tradeID y’enkolagana y’emu erina ennukuta ku ntandikwa mu nkolagana era teziri mu lipoota ya brokerage. N’olwekyo, teziyinza kugeraageranyizibwa … ahem-ahem … nga zigeraageranyizibwa! Nakwataganya obudde bw’okusuubula, ticker n’okukwatagana nti tradeId emu eri mu ndala. Kituufu, simanyi. Oyo yenna asanga kino era akifaako, jjangu ku nsonga oba tandika empya.Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

Emirimu gy’okubala ku bikozesebwa

Tekisoboka, nga totunuulidde, kukola mirimu gya kubala n’olukalala lwonna. Okusobola obutagattako bbugumu ku nnyogovu, bulijjo tukebera ssente ne tukola singa tuba tukakasa nti ssente zikwatagana, era obubonero ne bukyusibwa ne bufuuka ssente gye twagala. Nga tulina okumanya ku kukola ne nnamba za bbanka, tujja kubala akasiimo akasaasaanyiziddwa ku buli akawunti. Nga kino: https://github.com/pskucherov/tcsstat/omuti/omutendera4 https://github.com/pskucherov/tcsstat/geraageranya/omutendera3…omutendera4Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.    

Microservice yeetegese!

https://github.com/pskucherov/tcsstat Nga omulimu gw’awaka, osobola okukebera oba empeereza ekola n’omukutu ogugenda empola, ng’emikutu gimenyese, nga yintaneeti ekutuddwako, ng’ensobi oba ekkomo eriwedde ku ludda lwa broker. 

Ebimalirizibwa n’enteekateeka z’ebiseera eby’omu maaso

  • Yayiga ku mirimu emikulu n’okukola ne Invest API
  • Obudde obumala ~ essaawa 10
  • Omutendera gw’obuzibu ~ junior+ / wansi wakati 

Singa ogenda mu maaso n’okulongoosa microservice, oyinza okumaliriza ng’olina ekintu nga kino

https://opexbot.info ku mukutu gwa yintaneeti

  Eno y’enkulaakulana yange, eri abo abagayaavu ennyo okutegeera, okudduka n’okubala ku lwabwe. Nteekateeka okwongerako analytics eyo ku kusaba kw’abakozesa. Bw’oba ​​ekiwandiiko ekyo kyakunyumidde, olwo subscribe ku mukutu gwange ogwa telegram . Tukola microservice nga tukozesa Tinkoff Invest API okukola automate okukola ne lipoota za brokerage n’okubala commissions.

Pavel
Rate author
Add a comment

  1. Isakiiev

    Полезная статья. Не могу представить, сколько усилий автора потребовалось, чтобы все описать. Благодарю.

    Reply