Iwo anokurudzira kuseri kwekuvandudzwa kweiyo nhamba sevhisi yeTinkoff Investments aive:
- chinyorwa paHabré “Zvisiri kutaurwa naTinkoff Investments”
- kuongororwa kwezvido zvevashandisi vepuratifomu
- chinyorwa pamusoro pekuverengwa kwemakomisheni .
- Chii chichakurukurwa?
- Kugadzira statistics sevhisi nhanho nhanho:
- Kubatanidza kuTinkoff Invest API
- Kudhirowa data kubva kuTinkoff Invest API mubrowser
- Kugamuchira mishumo yebrokerage uye kutengeserana
- GetBrokerReport
- Nzira yekuwana zuva, uchifunga nezvekubvisa kubva pazuva razvino
- Chikumbiro chekugadzira
- Mhedzisiro:
- GetDividendsForeignIssuer
- GetOperationsByCursor
- Kuverengera uye kubuda kweruzivo rwekufarira
- Kushanda nemitengo
- Mutengo wezvibvumirano zveramangwana
- OTC musika
- Masvomhu mabasa pazvishandiso
- Microservice yakagadzirira!
- Mhedziso uye zvirongwa zvenguva yemberi
- https://opexbot.info
Chii chichakurukurwa?
- Chete chikamu chakashandiswa nezve budiriro.
- Zivo chaiyo uye ruzivo, izvo zvakakosha zvikuru mukushanda nezviridzwa zvemari.
- Muchidimbu nyaya dzekugadzirisa
Saka, ini ndoda kuverenga nhamba dzekutengesa uye kuzviita nenzira iri nyore.
Kugadzira statistics sevhisi nhanho nhanho:
- Kubatanidza kuTinkoff Invest API
- Kudhirowa data kubva kuTinkoff Invest API mubrowser
- Kugamuchira mishumo yebrokerage uye kutengeserana
- Kuverengera uye kubuda kweruzivo rwekufarira
- Mhedziso uye zvirongwa zvenguva yemberi
Kubatanidza kuTinkoff Invest API
Kuti ubatanidze kuAPI, unogona kutora chero sdk kubva pane zvinyorwa https://github.com/Tinkoff/investAPI#sdk . Kana kuti npm package ` tinkoff-sdk-grpc-js `. Izvo zvakakosha kuti iyo package inovandudzwa kune yazvino vhezheni nevagadziri. Install
npm i tinkoff-sdk-grpc-js
Kuongorora
const { createSdk } = inoda(‘tinkoff-sdk-grpc-js’); // Chiratidzo chinogona kuwanikwa senge ichi const TOKEN = ‘YOURAPI’; // Zita rekushandisa raunogona kuwanikwa naro muTCS matanda. const appName = ‘tcsstat’; const sdk = createSdk(TOKEN, appName); (async () => { console.log(await sdk.users.getAccounts()); })();
Mhedzisiro: runyorwa rweakaunti ako rucharatidzwa mukoni. Somuenzaniso, ngationgororei nuances:
- Muzvinyorwa zveakaunti pane “Investment bank”, iyo yausingakwanise kushanda nayo uchishandisa API
- Ndokumbira utarise kuti minda inouya ngameraCase, nepo mune zvinyorwa minda iyi inounzwa mu under_score.
- Zvichave seizvi kwese kwese, saka haugone kungotora nekukopa ndima kubva pane zvinyorwa.
Inobatsira:
- Iwe unogona kuwana iyi kodhi mubazi reprojekiti
https://github.com/pskucherov/tcsstat/tree/step1 https://github.com/pskucherov/tcsstat/compare/step1
Kudhirowa data kubva kuTinkoff Invest API mubrowser
Ndakatora inotevera.js uye socket.io. Iyi haisi kurudziro yakasimba, sarudza pakufunga kwako.
npx gadzira-inotevera-app@latest npm ini socket.io socket.io-client
Isu tinobva tangoenderera kune nhanho yehushamwari inotevera + socket + investtapi, uye ona Inobatsira chikamu cheichi nhanho kune ese ruzivo. Ndichatsanangura zvizere:
- Padivi renodejs (server), pane mapeji/api/investapi.js faira. Apa ndipo patinogadzira iyo socket.io server uye tobatanidza ku investapi.
- Padivi rebrowser (mutengi), tinobatanidza kune sevha kuburikidza nesoketi uye tinokumbira data reakaunti kubva kumutengesi.
- Isu tinogashira data kubva kune bhuroka pane server, tozotumira kune mutengi. Kana ivo vakagamuchirwa pane mutengi, ivo vanoratidzwa mubrowser.
Mhedzisiro: mubrowser console isu tinogona kuona ruzivo nezveakaundi. Ndokunge, mudanho rekupedzisira, takaona ruzivo nezveakaundi muserver console (nodejs), mudanho razvino, takaendesa ruzivo urwu kumutengi (browser).
Iye zvino ngatiitei kuitira kuti iwe usarudze account kubva kubrowser, uye kana pasina chiratidzo, ipapo kukanganisa kunotumirwa kune console. Iro basa riri nyore uye hapana chitsva, saka ini ndinopa chete zvinongedzo zvekuita
- https://github.com/pskucherov/tcsstat/commit/7e1ac57061e5e971588479015b06d8814d6609a9
- https://github.com/pskucherov/tcsstat/commit/b28ac973a57494f5232589b4cb6b9fb13b8af759
Inobatsira:
- Nzira yekuita shamwari inotevera uye socket inotsanangurwa zvakadzama pano .
- Kodhi yekushamwaridzana inotevera+socket+investapi:
https://github.com/pskucherov/tcsstat/commit/a443a4ac1bb4f0aa898f638128755fe7391ee381 Kune avo zviri pamusoro zvakaomera, saka isu tinoramba tiri panguva ino uye tinobata nekodhi. Kana uine mibvunzo – bvunza. https://github.com/pskucherov/tcsstat/tree/step2 https://github.com/pskucherov/tcsstat/compare/step1…step2
Kugamuchira mishumo yebrokerage uye kutengeserana
Pane nzira nhatu dzekugamuchira mishumo yebrokerage uye kutengeserana
Kubva pakutanga zvakakosha kuziva:
- Chirevo chebrokerage chinogadzirwa muT-3 mode, i.e. kutengeserana kunoratidzwa ipapo mushure mekuuraya kwavo chaiko.
- Saizvozvo, kana iwe ukakumbira chirevo ichi kwemazuva maviri apfuura, ichave yakagadzirira mumazuva matatu.
- Kuti tiwane kutengeserana kwemazuva ekupedzisira, tinoshandisa nzira yekugamuchira kutengeserana, asi yeuka kuti id yavo uye zvinyorwa zvinogona kuchinja mushure mokunge mushumo webrokerage wagadzirwa.
GetBrokerReport
Kuti uwane mushumo webrokerage, unofanirwa kutora id account, zuva rekutanga uye zuva rekupedzisira reshumo, asi kwete kupfuura mazuva 31. Isu tinotumira chikumbiro chekugadzira mushumo kuAPI mukugadzira _broker_report_request , tora taskId mukupindura. Mushure meizvozvo, tichishandisa iyi taskId, tinowana data kubva kuwana _broker_report_response.
- Iwe unofanirwa kuchengetedza iyo TaskID zvachose kune aya mazuva.
- Sezvo kana iwe ukairasa, saka pamazuva akakumbirwa iyo report inotanga kuuya ichipindura chikumbiro chechizvarwa,
- Uye zvadaro hazviuye zvachose.
Nzira yekuwana zuva, uchifunga nezvekubvisa kubva pazuva razvino
const getDateSubDay = (subDay = 5, start = true) => { const date = new Date(); date.setUTCDate(date.getUTCDate() – subDay); kana (kutanga) { date.setUTCHours(0, 0, 0, 0); } zvimwe { date.setUTCHours(23, 59, 59, 999); } zuva rekudzoka; };
Chikumbiro chekugadzira
const brokerReport = await (sdk.operations.getBrokerReport)({ generateBrokerReportRequest: { accountId, kubva, kuenda, }, });
Mhedzisiro:
- Nekuda kwekutanga kwekuita kwekuraira, tinowana iyo taskId.
- Chirevo chinotanga kugadzirwa kudivi rebroker. Kana yakagadzirira isingazivikanwe, isu tinomirira uye nguva nenguva tichidhonza iyo taskId tichitarisira mushumo.
- Sei? Nokuti kana mushumo usina kugadzirira, unokanda kukanganisa. Kana iyo report isati yagadzirira kudivi rebroker, saka ichi chikanganiso mukodhi yako. Tapota gadzirisa: 30058|INVALID_ARGUMENT|basa harisati rapera, tapota edza zvakare gare gare
Iyo kodhi yekumirira uye kugamuchira mushumo inotaridzika seizvi.
const timer = async nguva => { dzosa Promise itsva(gadzirisa => setTimeout(gadzirisa, nguva)); } const getBrokerResponseByTaskId = async (taskId, peji = 0) => { edza { kudzoka wakamirira (sdk.operations.getBrokerReport)({ getBrokerReportRequest: { taskId, peji, }, }); } kubata (e) { console.log(‘wait’, e); kumirira timer (10000); dzoka wakamirira getBrokerResponseByTaskId(taskId, peji); } };
Ipapo mashiripiti mamwe chetewo anoitika. Isu tinomisa script yedu, titange zvakare, isu hatina taskId. Isu tinoita iyo kodhi nechikumbiro cheId yebasa, asi isu hatisisiri kuwana iyo taskId, asi pakarepo mushumo. Mashiripiti! Uye zvese zvaizova zvakanaka kana zvaigara zvakadaro. Asi mumwedzi pachave pasina data zvachose. Inobatsira _
- Imwe dzidziso inotsanangurwa pano uye pano .
- Kuisa kodhi pamwe chete, iyo dhizaini ichaita senge ichi.
https://github.com/pskucherov/tcsstat/tree/step3.1 https://github.com/pskucherov/tcsstat/compare/step3.1
- Kana mumwe munhu akasangana neizvi, wobva wagamuchirwa kune iyo nyaya . Mushure mekugadzirisa mashiripiti aya, icharasikirwa nesimba rayo uye ichave neimwe nzira yakasiyana. Asi panguva yazvino (03/21/2023) inoshanda saizvozvo.
GetDividendsForeignIssuer
Mumwe munhu angafunga kuti nzira yacho yakafanana neyekare uye unogona kushandisa nzira imwe chete iyo iwe unongoshandura zita rekushanda. Asi havana kufungidzira! Kupihwa zita uko kwakasiyana kwazvo munzira uye muruzivo rwakadzoserwa. Uye kuverenga kwepeji kunotanga kubva ku0, zvino kubva ku1. Kuti urege kuvhiringidzika mune izvi zvose, zviri nyore kunyora nzira mbiri dzakasiyana. Izvo zvinoshamisa, nokuti pfungwa yebasa yakafanana. Ndakapfira mate kwenguva refu pandakaedza kugadzira imwe nzira uye pakanga paine kodhi shoma. Hapazovi nemienzaniso pano.
GetOperationsByCursor
Wandinofarira pavatatu. Kunyangwe isiri iyo yakanyanya kunaka, asi yakanyanya kukwana. Isu tinoita chikumbiro kubva pakutanga kugadzira account kusvika kune yakanyanya kukwanisika zuva (kuvhara account kana yazvino). Isu tinowana mhinduro, tora cursor uye tokumbira zvakare chero paine data. Uye iyo kodhi yakanyanya kupfupika kupfuura mumienzaniso iri pamusoro.
const timer = async nguva => { dzosa Promise itsva(gadzirisa => setTimeout(gadzirisa, nguva)); } const getOperationsByCursor = async (sdk, accountId, kubva, kuenda, cursor = ”) => { edza { const reqData = { accountId, kubva, kusvika, kugumira: 1000, nyika: sdk.OperationState.OPERATION_STATE_EXECUTED, withoutCommissions: false, withoutTrades: nhema, pasinaOvernights: nhema, chitubu, }; return wait sdk.operations.getOperationsByCursor(reqData); } kubata (e) { kumirira timer(60000); dzoka wakamirira getOperationsByCursor(sdk, accountId, kubva, kuenda, cursor = ”); } };
Iyo dhizaini yekumhanya iri pano: https://github.com/pskucherov/tcsstat/tree/step3.3 https://github.com/pskucherov/tcsstat/compare/step3.3 Iye zvino tagadzirira kuwedzera mabasa ekugamuchira ku chikumbiro chedu. Kana zvikaitwa nemazvo, saka iwe unofanirwa kuwana mishumo yebrokerage yekuvapo kwese kweaccount. Uye kune iyo data yakashaikwa, iwo maT-3 mamwe chete, rodha kubva kumabasa. Asi izvi zvinogona kuparadzaniswa kuva chinyorwa chakasiyana. Yemanuances makuru auchasangana nawo ndeye glue mashandiro uye mushumo webrokerage.
- Kana nhasi wakagamuchira mushumo webrokerage uye kutengeserana kwemazuva anodiwa, zviise zvose mu database, saka hapana matambudziko.
- Iwe uchave nezvinetso mangwana kana iwe uchigamuchira chikamu chinotevera che data kubva kumushumo uye mashandiro uye wofunga kuzvibatanidza nedatabase iripo.
- Mazhinji nuances nezve kusaenderana kana kuchinja id mushure mekugadzirisa
- Zvino kumusika weOTC, id haienderane zvachose.
- Pamwe chete nemanuances ezviridzwa zvekubatanidza, izvo zvakare zvisingaenderane, nekuda kwezvakasiyana zveAPI. Asi iyo imwe nyaya.
Ngatiwedzerei kuwana ruzivo nezve maoperation kune yedu application. Mubvunzo mukuru uchave uko iyo data ichagadziriswa uye kuchengetwa.
- Kana iwe ukazviitira iwe pachako, iwe unodya iyo yakafanana data kubva kune akasiyana michina. Ipapo iwe unofanirwa kugadzirisa uye kuchengeta data pane server.
- Kana uine data rakawanda rakasiyana rinopedzwa nevashandisi vakawanda vakasiyana, saka iwe unofanirwa kusarudza kuti chii chinonyanya kukosha: kumhanya kwevashandisi kana kuchengetedzwa kwesimbi parutivi rwako. Ani nani anogona kutenga huwandu husingaverengeki hwehardware anoverenga zvese zviri paserver yake uye anoita kuti imhanye zvakanyanya kune vashandisi, kuchengetedza zviwanikwa zvemushandisi, senge bhatiri uye traffic, iyo yakakosha pamafoni.
Nekudaro, kuverenga mubrowser haisi iyo yakanyanya kunaka mhinduro musimboti. Naizvozvo, izvo zvisingadhure, tinozviona pane yedu server. Isu tinosiya zvimwe kumutengi. Ini ndinoda chaizvo kutora uye kuverenga komisheni pane server. Asi pano panouya nuance inonzi “interactivity”. Ngatitii une zviuru zvekushanda uye zvinotora maminetsi mashanu kuti uzvigamuchire. Mushandisi achave nei panguva ino? Spinner? Kufambira mberi? Infa nezvekuti ingani yakaiswa? Zvakanakira kushandisa “kumirira kumirira” kana mushandisi ari mukuita achigona kuona chimwe chinhu. Heino Mhedzisiro:
- Page loading
- Mainvoice ese anokumbirwa
- Mushure meizvozvo, zvese zvekutengesa nemakomisheni ezvekuita kutengeserana zvinokumbirwa kune ese maakaundi. Sezvo data inogamuchirwa, inopihwa mubrowser.
Kuti tisasefa iyo data muzviitiko nguva yega yega, isu tinodhonza yedu chiitiko kune yega account. Sezvizvi:
socket.emit(‘sdk:getOperationsCommissionResult_’ + accountId, { zvinhu: data?.items, inProgress: Boolean(nextCursor), });
The draft to launch is here: https://github.com/pskucherov/tcsstat/tree/step3 https://github.com/pskucherov/tcsstat/compare/step2…step3 Moving on. Zvakanaka kuti waverenga mutsara uyu!
Kuverengera uye kubuda kweruzivo rwekufarira
Zvinoenderana nekuti ndiani anoda ruzivo. Naizvozvo, ini ndinokurumidza kukuudza iwo makuru nuances auchasangana nawo.
Kushanda nemitengo
Wese anoshanda nezvemari anoziva kuti kutengeserana kwemari kunofanirwa kuitwa chete nenhamba dzese. Nekuda kwekusarongeka kwehunhu mushure meiyo decimal point uye kukanganisa kwakawedzera nehuwandu hukuru hwekushanda. Ndokusaka mitengo yese ichiratidzwa mune inotevera MoneyValue fomati
munda | type | Tsanangudzo |
---|---|---|
mari | tambo | String ISO mari kodhi |
units | int64 | Integer chikamu chehuwandu, inogona kuva nhamba isina kunaka |
nano | int32 | Chikamu chechikamu chemari, inogona kuva nhamba isina kunaka |
Isu tinozvigadzirisa zvakasiyana, tozounza kune mutengo wemutengo:
quotation.units + quotation.nano / 1e9
Mutengo wezvibvumirano zveramangwana
Mutengo weramangwana unoratidzwa mumapoinzi, kana uine ramangwana remari, unofanirwa kuziva chiyero. Uye zvechokwadi mutengo mumapoinzi uye nhanho yemutengo. Kana iwe ukaverenga purofiti kubva mukutengeserana, izvi zvinogona kupfura, nekuti. kana iwe ukaverenga huwandu hwese nekuwedzera mutengo nehuwandu. Pano unofanira kungwarira. Parizvino, tichaona kuti zvinofamba sei. Izvi zvinoshanda kune ramangwana remari, mune dzimwe nzvimbo zvese zvakanaka neizvi.
OTC musika
Musika uyu une zvakawanda zvakajairwa, saka ngatidzidzei mashandisiro pairi zvakasiyana. Paunotanga kuwiriranisa mashandiro, zvinozoitika kuti iwe unofanirwa kuunza figi / ticker kune imwechete fomu kuti ienderane chiridzwa. Paunotanga kuwiriranisa izvi neshumo yebrokerage, zvichazoitika kuti tradeID yekutengeserana yakafanana ine mavara pakutanga mukutengeserana uye ivo havasi mushumo webrokerage. Naizvozvo, havagone kuenzaniswa … ahem-ahem … nekuenzanisa! Ndakafananidza nguva yekutengeserana, ticker uye kuenzanisa kuti imwe tradeId iri mune imwe. Zvakanaka, handizivi. Ani nani anosangana neizvi uye ane hanya nazvo, huya kunyaya kana kutanga imwe itsva.
Masvomhu mabasa pazvishandiso
Hazvigoneke, pasina kutarisa, kuita masvomhu mabasa nerunyorwa rwese. Kuti tisawedzera inodziya kune yakapfava, isu tinogara tichitarisa mari uye maitiro chete kana tine chokwadi chekuti mari yacho inoenderana, uye mapoinzi anoshandurwa kune yaunoda mari. Yakashongedzwa neruzivo nezve kushanda nenhamba dzebhangi, isu tichaverenga komisheni yakashandiswa pane imwe neimwe yeakaundi. Sezvizvi: https://github.com/pskucherov/tcsstat/tree/step4 https://github.com/pskucherov/tcsstat/compare/step3…step4
Microservice yakagadzirira!
https://github.com/pskucherov/tcsstat Sebasa remumba, unogona kutarisa kana sevhisi inoshanda nekubatanidza kunononoka, kana zvisungo zvakaputsika, kana Indaneti ichibviswa, kana kukanganisa kana kupera kwemiganhu kune chikamu chemutengesi.
Mhedziso uye zvirongwa zvenguva yemberi
- Akadzidza nezvekutanga mashandiro uye kushanda neiyo Invest API
- Nguva yakashandiswa ~ maawa gumi
- Chiyero chekuomerwa ~ junior + / pasi pakati
Kana iwe ukaramba uchinatsa iyo microservice, unogona kupedzisira uine chimwe chinhu chakadai
https://opexbot.info
Uku ndiko kukura kwangu, kune avo vane usimbe hwekunzwisisa, kumhanya uye kuverenga vega. Ini ndinoronga kuwedzera analytics ipapo pakukumbira kwevashandisi. Kana waifarira chinyorwa, saka nyoresa kune yangu telegraph chiteshi .
Полезная статья. Не могу представить, сколько усилий автора потребовалось, чтобы все описать. Благодарю.